/**
  * Retrieve the entry terms by taxonomy.
  *
  * @access public
  * @since  8.2
  * @static
  *
  * @param int    $id
  * @param string $taxonomy
  * @param array  $atts     Optional. An array of arguments. @see cnTerm::getRelationships() for accepted arguments.
  *
  * @return mixed array|WP_Error An array of terms by taxonomy associated to an entry.
  */
 public static function entryTerms($id, $taxonomy, $atts = array())
 {
     /** @todo Check that entry exists */
     //if ( ! $id = get_entry( $id ) ) {
     //	return false;
     //}
     $terms = cnTerm::getRelationshipsCache($id, $taxonomy);
     if (FALSE === $terms) {
         $terms = cnTerm::getRelationships($id, $taxonomy, $atts);
         wp_cache_add($id, $terms, "cn_{$taxonomy}_relationships");
     } else {
         /**
          * Filter the list of terms attached to the given entry.
          *
          * @since 8.2
          *
          * @param array|WP_Error $terms    List of attached terms, or WP_Error on failure.
          * @param int            $id       Post ID.
          * @param string         $taxonomy Name of the taxonomy.
          * @param array          $atts     An array of arguments for retrieving terms for the given object.
          */
         $terms = apply_filters('cn_get_object_terms', $terms, $id, $taxonomy, $atts);
     }
     return $terms;
 }
 /**
  * The category metabox.
  *
  * @access public
  * @since  0.8
  * @param  cnEntry $entry   An instance of the cnEntry object.
  * @param  array   $metabox The metabox options array from self::register().
  * @return string           The category metabox.
  */
 public static function category($entry, $metabox)
 {
     echo '<div class="categorydiv" id="taxonomy-category">';
     echo '<div id="category-all" class="tabs-panel">';
     cnTemplatePart::walker('term-checklist', array('selected' => cnTerm::getRelationships($entry->getID(), 'category', array('fields' => 'ids'))));
     echo '</div>';
     echo '</div>';
 }
 /**
  * Deletes all entry's relationships.
  *
  * @deprecated 8.1.6 Use {@see cnTerm::deleteRelationships()} instead.
  * @see cnTerm::deleteRelationships()
  *
  * @param integer $entryID
  *
  * @return bool
  */
 public function deleteTermRelationships($entryID)
 {
     $terms = cnTerm::getRelationships($entryID, 'category', array('fields' => 'ids'));
     $result = cnTerm::deleteRelationships($entryID, $terms, 'category');
     cnCache::clear(TRUE, 'transient', "cn_category");
     return $result;
 }
 /**
  * Update the term taxonomy counts of the supplied entry IDs for the supplied taxonmies.
  *
  * @access private
  * @since  8.2.5
  * @static
  *
  * @param mixed $ids      array|string An array or comma separated list of entry IDs.
  * @param mixed $taxonomy array|string An array of taxonomies or taxonomy to update the term taxonomy count.
  *
  * @return array|WP_Error An indexed array of term taxonomy IDs which have had their term count updated. WP_Error on failure.
  */
 public static function updateTermCount($ids, $taxonomy = 'category')
 {
     // Check for and convert to an array.
     $ids = wp_parse_id_list($ids);
     $result = cnTerm::getRelationships($ids, $taxonomy, array('fields' => 'tt_ids'));
     if (!empty($result) && !is_wp_error($result)) {
         cnTerm::updateCount($result, $taxonomy);
     }
     cnCache::clear(TRUE, 'transient', "cn_{$taxonomy}");
     return $result;
 }
 /**
  * Retrieve the entry terms by taxonomy.
  *
  * NOTE: This is the Connections equivalent of @see get_the_terms() in WordPress core ../wp-includes/category-template.php
  *
  * @access public
  * @since  8.2
  * @static
  *
  * @param int    $id
  * @param string $taxonomy
  * @param array  $atts     Optional. An array of arguments. @see cnTerm::getRelationships() for accepted arguments.
  *
  * @return array|false|WP_Error An array of terms by taxonomy associated to an entry.
  */
 public static function entryTerms($id, $taxonomy, $atts = array())
 {
     /** @todo Check that entry exists */
     //if ( ! $id = get_entry( $id ) ) {
     //	return false;
     //}
     $terms = cnTerm::getRelationshipsCache($id, $taxonomy);
     if (FALSE === $terms) {
         $terms = cnTerm::getRelationships($id, $taxonomy, $atts);
         if (!is_wp_error($terms)) {
             $to_cache = array();
             foreach ($terms as $key => $term) {
                 $to_cache[$key] = $term->data;
             }
             wp_cache_add($id, $to_cache, "cn_{$taxonomy}_relationships");
         }
     } else {
         // This differs from the core WP function because $terms only needs run thru cnTerm::get() on a cache hit
         // otherwise it is unnecessarily run twice. once in cnTerm::getRelationships() on cache miss, once here.
         // Moving this logic to the else statement make sure it is only fun once on the cache hit.
         $terms = array_map(array('cnTerm', 'get'), $terms);
     }
     /**
      * Filter the list of terms attached to the given entry.
      *
      * @since 8.2
      *
      * @param array|WP_Error $terms    List of attached terms, or WP_Error on failure.
      * @param int            $id       Post ID.
      * @param string         $taxonomy Name of the taxonomy.
      * @param array          $atts     An array of arguments for retrieving terms for the given object.
      */
     $terms = apply_filters('cn_get_object_terms', $terms, $id, $taxonomy, $atts);
     if (empty($terms)) {
         return FALSE;
     }
     return $terms;
 }