public function get_term($term) { if (!isset($term->taxonomy) || !isset($term->term_id)) { return; } $taxonomy = $term->taxonomy; if (in_array($taxonomy, $this->objects)) { return new $taxonomy($term->term_id, $taxonomy); } else { return Clarkson_Term::get_by_id($term->term_id, $taxonomy); } }
/** * Retrieve the terms for a post. * * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'. * @param array $args Optional. {@link wp_get_object_terms()} arguments. Default empty array. * @return array List of post tags. */ public function get_terms($taxonomy, $args = array()) { return array_map(function ($term) use($taxonomy) { try { if (is_object($term)) { // Check if there is a Custom Taxonomy class if (class_exists($taxonomy)) { return call_user_func(array($taxonomy, 'get_by_id'), $term->term_id, $taxonomy); } // Else return a default Clarkson Term return Clarkson_Term::get_by_id($term->term_id, $taxonomy); } return $term; } catch (Exception $e) { return null; } }, wp_get_post_terms($this->get_id(), $taxonomy, $args)); }