Ticket #27238: 27238.6.patch
File 27238.6.patch, 5.0 KB (added by , 10 years ago) |
---|
-
src/wp-includes/taxonomy.php
4107 4107 * post without specifying the Post ID. You can also use it outside the Loop to 4108 4108 * display the taxonomies for a specific post. 4109 4109 * 4110 * The available defaults are:4111 * 'post' : default is 0. The post ID to get taxonomies of.4112 * 'before' : default is empty string. Display before taxonomies list.4113 * 'sep' : default is empty string. Separate every taxonomy with value in this.4114 * 'after' : default is empty string. Display this after the taxonomies list.4115 * 'template' : The template to use for displaying the taxonomy terms.4116 *4117 4110 * @since 2.5.0 4118 * @uses get_the_taxonomies()4119 4111 * 4120 * @param array $args Override the defaults. 4112 * @param array $args { 4113 * Arguments about which post to use and how to format the output. 4114 * 4115 * @type int|WP_Post $post Post ID or object to get taxonomies of. Default current post. 4116 * @type string $before Displays before the taxonomies. Default empty string. 4117 * @type string $sep Separates each taxonomy. Default is a space. 4118 * @type string $after Displays after the taxonomies. Default empty string. 4119 * @type string $template Template for displaying a taxonomy label and list of 4120 * terms. Default is "Label: Terms." 4121 * @type string $term_template Template for displaying a single term in the list. 4122 * Default is the term name linked to its archive. 4123 * } 4121 4124 */ 4122 4125 function the_taxonomies( $args = array() ) { 4123 4126 $defaults = array( … … 4125 4128 'before' => '', 4126 4129 'sep' => ' ', 4127 4130 'after' => '', 4128 /* translators: %s: taxonomy label, %l: list of term links */ 4129 'template' => __( '%s: %l.' ) 4131 /* translators: %s: taxonomy label, %l: list of terms formatted as $term_template */ 4132 'template' => __( '%s: %l.' ), 4133 'term_template' => '<a href="%1$s">%2$s</a>', 4130 4134 ); 4131 4135 4132 4136 $r = wp_parse_args( $args, $defaults ); … … 4150 4154 $post = get_post( $post ); 4151 4155 4152 4156 $args = wp_parse_args( $args, array( 4153 /* translators: %s: taxonomy label, %l: list of term links*/4157 /* translators: %s: taxonomy label, %l: list of terms formatted as $term_template */ 4154 4158 'template' => __( '%s: %l.' ), 4159 'term_template' => '<a href="%1$s">%2$s</a>', 4155 4160 ) ); 4156 4161 4157 4162 $taxonomies = array(); … … 4171 4176 if ( empty( $t['template'] ) ) { 4172 4177 $t['template'] = $args['template']; 4173 4178 } 4179 if ( empty( $t['term_template'] ) ) { 4180 $t['term_template'] = $args['term_template']; 4181 } 4174 4182 4175 4183 $terms = get_object_term_cache( $post->ID, $taxonomy ); 4176 4184 if ( false === $terms ) { … … 4179 4187 $links = array(); 4180 4188 4181 4189 foreach ( $terms as $term ) { 4182 $links[] = "<a href='" . esc_attr( get_term_link( $term ) ) . "'>$term->name</a>";4190 $links[] = wp_sprintf( $t['term_template'], esc_attr( get_term_link($term) ), $term->name ); 4183 4191 } 4184 4192 if ( $links ) { 4185 4193 $taxonomies[$taxonomy] = wp_sprintf( $t['template'], $t['label'], $links, $terms ); -
tests/phpunit/tests/taxonomy.php
49 49 $this->assertEquals( array( 'category', 'post_tag' ), array_keys( $taxes ) ); 50 50 } 51 51 52 function test_get_the_taxonomies_term_template() { 53 $post_id = $this->factory->post->create(); 54 55 $taxes = get_the_taxonomies( $post_id, array( 'term_template' => '%2$s' ) ); 56 $this->assertEquals( 'Categories: Uncategorized.', $taxes['category'] ); 57 58 $taxes = get_the_taxonomies( $post_id, array( 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>' ) ); 59 $link = get_category_link( 1 ); 60 $this->assertEquals( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $taxes['category'] ); 61 } 62 52 63 function test_the_taxonomies() { 53 64 $post_id = $this->factory->post->create(); 54 65 … … 57 68 $output = ob_get_clean(); 58 69 59 70 $link = get_category_link( 1 ); 60 $expected = "Categories: <a href='$link'>Uncategorized</a>.";71 $expected = 'Categories: <a href="' . $link . '">Uncategorized</a>.'; 61 72 $this->assertEquals( $expected, $output ); 62 73 } 63 74 75 function test_the_taxonomies_term_template() { 76 $post_id = $this->factory->post->create(); 77 78 $output = get_echo( 'the_taxonomies', array( array( 'post' => $post_id, 'term_template' => '%2$s' ) ) ); 79 $this->assertEquals( 'Categories: Uncategorized.', $output ); 80 81 $output = get_echo( 'the_taxonomies', array( array( 'post' => $post_id, 'term_template' => '<span class="foo"><a href="%1$s">%2$s</a></span>' ) ) ); 82 $link = get_category_link( 1 ); 83 $this->assertEquals( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $output ); 84 } 85 64 86 function test_get_link_taxonomy() { 65 87 foreach ( get_object_taxonomies('link') as $taxonomy ) { 66 88 $tax = get_taxonomy($taxonomy);