示例#1
0
 /**
  * Load data for a post
  *
  * @param  array        $data Post data
  *
  * @return WPPostLoader $this
  */
 public function loadData($data)
 {
     $this->resetData();
     if (!isset($data['post_id'])) {
         return null;
     }
     $this->setID($data['post_id']);
     $this->setTitle($data['post_title']);
     $this->setCreationDate(is_numeric($data['post_date']) ? $data['post_date'] : strtotime($data['post_date']));
     $this->setLastModifiedDate(is_numeric($data['post_modified']) ? $data['post_modified'] : strtotime($data['post_modified']));
     $this->setStatus($data['post_status']);
     $this->setType($data['post_type']);
     $this->setFormat($data['post_format']);
     $this->setName($data['post_name']);
     $this->setAuthor(new WPUser($this->getBlog(), $data['post_author']));
     $this->setPassword($data['post_password']);
     $this->setExcerpt($data['post_excerpt']);
     $this->setContent($data['post_content']);
     $this->setParent($data['post_parent']);
     $this->setMimeType($data['post_mime_type']);
     $this->setLink($data['link']);
     $this->setGUID($data['guid']);
     $this->setMenuOrder(intval($data['menu_order']));
     $this->setCommentStatus($data['comment_status']);
     $this->setPingStatus($data['ping_status']);
     $this->setSticky(filter_var($data['sticky'], FILTER_VALIDATE_BOOLEAN));
     if (isset($data['custom_fields'])) {
         foreach ($data['custom_fields'] as $value) {
             $this->setCustomField($value['key'], $value['value']);
         }
     }
     if (isset($data['enclosure'])) {
         $this->setEnclosureURL($data['enclosure']['url']);
         $this->setEnclosureLength($data['enclosure']['length']);
         $this->setEnclosureType($data['enclosure']['type']);
     }
     if (isset($data['post_thumbnail']['attachment_id'])) {
         $thumbnail = new WPMedia($this->getBlog());
         $thumbnail->loadData($data['post_thumbnail']);
         $this->setThumbnail($thumbnail);
     }
     foreach ($data['terms'] as $term) {
         $taxonomy = $this->getBlog()->getTaxonomy($term['taxonomy']);
         $termObj = new WPTerm($taxonomy);
         $termObj->loadData($term);
         $this->addTerm($termObj);
     }
     return $this;
 }
示例#2
0
 /**
  * Get terms from this taxonomy
  *
  * @param   string  $search     Restrict to terms with names that contain (case-insensitive) this value
  * @param   boolean $hide_empty Hide empty terms (count=0)
  * @param   int     $number     Number of terms retrieved
  * @param   int     $offset     Number of terms to skip
  * @param   string  $orderby    Field to use for ordering
  * @param   string  $order      Type of ordering (asd or desc)
  *
  * @return  array   $terms
  * 
  * @throws \Comodojo\Exception\WPException
  */
 public function getTerms($search = "", $hide_empty = false, $number = null, $offset = 0, $orderby = "name", $order = "ASC")
 {
     $terms = array();
     $filter = array("hide_empty" => $hide_empty, "offset" => $offset, "orderby" => $orderby, "order" => $order);
     if (!empty($search)) {
         $filter["search"] = $search;
     }
     if (!is_null($number)) {
         $filter["number"] = intval($number);
     }
     try {
         $list = $this->getWordpress()->sendMessage("wp.getTerms", array($this->getName(), $filter), $this->getBlog());
         foreach ($list as $term) {
             $t = new WPTerm($this);
             $t->loadData($term);
             array_push($terms, $t);
         }
     } catch (WPException $wpe) {
         throw new WPException("Unable to retrieve term informations (" . $wpe->getMessage() . ")");
     }
     return $terms;
 }
示例#3
0
 /**
  * Remove term
  *
  * @param  WPTerm     $term Term reference
  *
  * @return WPPostData $this
  */
 public function removeTerm($term)
 {
     foreach ($this->terms as $id => $t) {
         if ($t->getID() == $term->getID()) {
             unset($this->terms[$id]);
         }
     }
     return $this;
 }