Ticket #27238: 27238.5.patch
File 27238.5.patch, 5.6 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()4111 * @see get_the_taxonomies() for detail about the $template and $term_template arguments. 4119 4112 * 4120 * @param array $args Override the defaults. 4113 * @param array $args { 4114 * Arguments about which post to use and how to format the output. 4115 * 4116 * @type int|WP_Post $post Post ID or object to get taxonomies of. Default current post. 4117 * @type string $before Displays before the taxonomies. Default empty string. 4118 * @type string $sep Separates each taxonomy. Default is a space. 4119 * @type string $after Displays after the taxonomies. Default empty string. 4120 * @type string $template Template for a taxonomy label and its terms. 4121 * @type string $term_template Template for a term. 4122 * } 4121 4123 */ 4122 4124 function the_taxonomies( $args = array() ) { 4123 4125 $defaults = array( … … 4125 4127 'before' => '', 4126 4128 'sep' => ' ', 4127 4129 'after' => '', 4128 /* translators: %s: taxonomy label, %l: list of term links */ 4129 'template' => __( '%s: %l.' ) 4130 /* translators: %s: taxonomy label, %l: list of terms formatted as $term_template */ 4131 'template' => __( '%s: %l.' ), 4132 'term_template' => '<a href="%1$s">%2$s</a>', 4130 4133 ); 4131 4134 4132 4135 $r = wp_parse_args( $args, $defaults ); … … 4143 4146 * @since 2.5.0 4144 4147 * 4145 4148 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 4146 * @param array $args Override the defaults. 4149 * @param array $args { 4150 * Arguments about how to format the taxonomy name and its terms. 4151 * 4152 * @type string $template Template for displaying a taxonomy label and list of 4153 * terms. Default is "Label: Terms." 4154 * @type string $term_template Template for displaying a single term in the list. 4155 * Default is the term name linked to its archive. 4156 * } 4147 4157 * @return array List of taxonomies. 4148 4158 */ 4149 4159 function get_the_taxonomies( $post = 0, $args = array() ) { 4150 4160 $post = get_post( $post ); 4151 4161 4152 4162 $args = wp_parse_args( $args, array( 4153 /* translators: %s: taxonomy label, %l: list of term links*/4163 /* translators: %s: taxonomy label, %l: list of terms formatted as $term_template */ 4154 4164 'template' => __( '%s: %l.' ), 4165 'term_template' => '<a href="%1$s">%2$s</a>', 4155 4166 ) ); 4156 4167 4157 4168 $taxonomies = array(); … … 4171 4182 if ( empty( $t['template'] ) ) { 4172 4183 $t['template'] = $args['template']; 4173 4184 } 4185 if ( empty( $t['term_template'] ) ) { 4186 $t['term_template'] = $args['term_template']; 4187 } 4174 4188 4175 4189 $terms = get_object_term_cache( $post->ID, $taxonomy ); 4176 4190 if ( false === $terms ) { … … 4179 4193 $links = array(); 4180 4194 4181 4195 foreach ( $terms as $term ) { 4182 $links[] = "<a href='" . esc_attr( get_term_link( $term ) ) . "'>$term->name</a>";4196 $links[] = wp_sprintf( $t['term_template'], esc_attr( get_term_link($term) ), $term->name ); 4183 4197 } 4184 4198 if ( $links ) { 4185 4199 $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);