+ if ( is_wp_error( $term ) )
+ return $term;
+
+ // use legacy functions for core taxonomies until they are fully plugged in
+ if ( $taxonomy == 'category' )
+ return get_category_link((int) $term->term_id);
+ if ( $taxonomy == 'post_tag' )
+ return get_tag_link((int) $term->term_id);
+
+ $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
+
+ $slug = $term->slug;
+
+ if ( empty($termlink) ) {
+ $file = get_option('home') . '/';
+ $t = get_taxonomy($taxonomy);
+ if ( $t->query_var )
+ $termlink = "$file?$t->query_var=$slug";
+ else
+ $termlink = "$file?taxonomy=$taxonomy&term=$slug";
+ } else {
+ $termlink = str_replace("%$taxonomy%", $slug, $termlink);
+ $termlink = get_option('home') . user_trailingslashit($termlink, 'category');
+ }
+ return apply_filters('term_link', $termlink, $term, $taxonomy);
+}
+
+/**
+ * Display the taxonomies of a post with available options.
+ *
+ * This function can be used within the loop to display the taxonomies for a
+ * post without specifying the Post ID. You can also use it outside the Loop to
+ * display the taxonomies for a specific post.
+ *
+ * The available defaults are:
+ * 'post' : default is 0. The post ID to get taxonomies of.
+ * 'before' : default is empty string. Display before taxonomies list.
+ * 'sep' : default is empty string. Separate every taxonomy with value in this.
+ * 'after' : default is empty string. Display this after the taxonomies list.
+ *
+ * @since 2.5.0
+ * @uses get_the_taxonomies()
+ *
+ * @param array $args Override the defaults.
+ */
+function the_taxonomies($args = array()) {
+ $defaults = array(
+ 'post' => 0,
+ 'before' => '',
+ 'sep' => ' ',
+ 'after' => '',
+ );
+
+ $r = wp_parse_args( $args, $defaults );
+ extract( $r, EXTR_SKIP );
+
+ echo $before . join($sep, get_the_taxonomies($post)) . $after;
+}
+
+/**
+ * Retrieve all taxonomies associated with a post.
+ *
+ * This function can be used within the loop. It will also return an array of
+ * the taxonomies with links to the taxonomy and name.
+ *
+ * @since 2.5.0
+ *
+ * @param int $post Optional. Post ID or will use Global Post ID (in loop).
+ * @return array
+ */
+function get_the_taxonomies($post = 0) {
+ if ( is_int($post) )
+ $post =& get_post($post);
+ elseif ( !is_object($post) )
+ $post =& $GLOBALS['post'];
+
+ $taxonomies = array();
+
+ if ( !$post )
+ return $taxonomies;
+
+ $template = apply_filters('taxonomy_template', '%s: %l.');
+
+ foreach ( get_object_taxonomies($post) as $taxonomy ) {
+ $t = (array) get_taxonomy($taxonomy);
+ if ( empty($t['label']) )
+ $t['label'] = $taxonomy;
+ if ( empty($t['args']) )
+ $t['args'] = array();
+ if ( empty($t['template']) )
+ $t['template'] = $template;
+
+ $terms = get_object_term_cache($post->ID, $taxonomy);
+ if ( empty($terms) )
+ $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
+
+ $links = array();
+
+ foreach ( $terms as $term )
+ $links[] = "<a href='" . esc_attr(get_term_link($term, $taxonomy)) . "'>$term->name</a>";
+
+ if ( $links )
+ $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms);
+ }
+ return $taxonomies;
+}
+
+/**
+ * Retrieve all taxonomies of a post with just the names.
+ *
+ * @since 2.5.0
+ * @uses get_object_taxonomies()
+ *
+ * @param int $post Optional. Post ID
+ * @return array
+ */
+function get_post_taxonomies($post = 0) {
+ $post =& get_post($post);
+
+ return get_object_taxonomies($post);
+}
+
+/**
+ * Determine if the given object is associated with any of the given terms.
+ *
+ * The given terms are checked against the object's terms' term_ids, names and slugs.
+ * Terms given as integers will only be checked against the object's terms' term_ids.
+ * If no terms are given, determines if object is associated with any terms in the given taxonomy.
+ *
+ * @since 2.7.0
+ * @uses get_object_term_cache()
+ * @uses wp_get_object_terms()
+ *
+ * @param int $object_id. ID of the object (post ID, link ID, ...)
+ * @param string $taxonomy. Single taxonomy name
+ * @param int|string|array $terms Optional. Term term_id, name, slug or array of said
+ * @return bool|WP_Error. WP_Error on input error.
+ */
+function is_object_in_term( $object_id, $taxonomy, $terms = null ) {
+ if ( !$object_id = (int) $object_id )
+ return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) );
+
+ $object_terms = get_object_term_cache( $object_id, $taxonomy );
+ if ( empty( $object_terms ) )
+ $object_terms = wp_get_object_terms( $object_id, $taxonomy );
+
+ if ( is_wp_error( $object_terms ) )
+ return $object_terms;
+ if ( empty( $object_terms ) )
+ return false;
+ if ( empty( $terms ) )
+ return ( !empty( $object_terms ) );
+
+ $terms = (array) $terms;
+
+ if ( $ints = array_filter( $terms, 'is_int' ) )
+ $strs = array_diff( $terms, $ints );
+ else
+ $strs =& $terms;
+
+ foreach ( $object_terms as $object_term ) {
+ if ( $ints && in_array( $object_term->term_id, $ints ) ) return true; // If int, check against term_id
+ if ( $strs ) {
+ if ( in_array( $object_term->term_id, $strs ) ) return true;
+ if ( in_array( $object_term->name, $strs ) ) return true;
+ if ( in_array( $object_term->slug, $strs ) ) return true;
+ }
+ }
+
+ return false;