Changeset 28415
- Timestamp:
- 05/15/2014 03:50:46 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r28241 r28415 3713 3713 * @return array 3714 3714 */ 3715 function get_the_taxonomies( $post = 0, $args = array() ) {3715 function get_the_taxonomies( $post = 0, $args = array() ) { 3716 3716 $post = get_post( $post ); 3717 3717 … … 3719 3719 'template' => '%s: %l.', 3720 3720 ) ); 3721 extract( $args, EXTR_SKIP );3722 3721 3723 3722 $taxonomies = array(); 3724 3723 3725 if ( ! $post )3724 if ( ! $post ) { 3726 3725 return $taxonomies; 3727 3728 foreach ( get_object_taxonomies($post) as $taxonomy ) { 3729 $t = (array) get_taxonomy($taxonomy); 3730 if ( empty($t['label']) ) 3726 } 3727 3728 foreach ( get_object_taxonomies( $post ) as $taxonomy ) { 3729 $t = (array) get_taxonomy( $taxonomy ); 3730 if ( empty( $t['label'] ) ) { 3731 3731 $t['label'] = $taxonomy; 3732 if ( empty($t['args']) ) 3732 } 3733 if ( empty( $t['args'] ) ) { 3733 3734 $t['args'] = array(); 3734 if ( empty($t['template']) ) 3735 $t['template'] = $template; 3736 3737 $terms = get_object_term_cache($post->ID, $taxonomy); 3738 if ( false === $terms ) 3739 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); 3740 3735 } 3736 if ( empty( $t['template'] ) ) { 3737 $t['template'] = $args['template']; 3738 } 3739 3740 $terms = get_object_term_cache( $post->ID, $taxonomy ); 3741 if ( false === $terms ) { 3742 $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); 3743 } 3741 3744 $links = array(); 3742 3745 3743 foreach ( $terms as $term ) 3744 $links[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>"; 3745 3746 if ( $links ) 3747 $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms); 3746 foreach ( $terms as $term ) { 3747 $links[] = "<a href='" . esc_attr( get_term_link( $term ) ) . "'>$term->name</a>"; 3748 } 3749 if ( $links ) { 3750 $taxonomies[$taxonomy] = wp_sprintf( $t['template'], $t['label'], $links, $terms ); 3751 } 3748 3752 } 3749 3753 return $taxonomies; -
trunk/tests/phpunit/tests/taxonomy.php
r28374 r28415 34 34 } 35 35 36 function test_get_the_taxonomies() { 37 $post_id = $this->factory->post->create(); 38 39 $taxes = get_the_taxonomies( $post_id ); 40 $this->assertNotEmpty( $taxes ); 41 $this->assertEquals( array( 'category' ), array_keys( $taxes ) ); 42 43 $id = $this->factory->tag->create(); 44 wp_set_post_tags( $post_id, array( $id ) ); 45 46 $taxes = get_the_taxonomies( $post_id ); 47 $this->assertNotEmpty( $taxes ); 48 $this->assertCount( 2, $taxes ); 49 $this->assertEquals( array( 'category', 'post_tag' ), array_keys( $taxes ) ); 50 } 51 36 52 function test_get_link_taxonomy() { 37 53 foreach ( get_object_taxonomies('link') as $taxonomy ) {
Note: See TracChangeset
for help on using the changeset viewer.