Changeset 40293
- Timestamp:
- 03/16/2017 02:03:53 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-term-query.php
r40147 r40293 475 475 } 476 476 477 if ( ! empty( $args['name'] ) ) { 477 if ( 478 ( ! empty( $args['name'] ) ) || 479 ( is_string( $args['name'] ) && 0 !== strlen( $args['name'] ) ) 480 ) { 478 481 $names = (array) $args['name']; 479 482 foreach ( $names as &$_name ) { … … 485 488 } 486 489 487 if ( ! empty( $args['slug'] ) ) { 490 if ( 491 ( ! empty( $args['slug'] ) ) || 492 ( is_string( $args['slug'] ) && 0 !== strlen( $args['slug'] ) ) 493 ) { 488 494 if ( is_array( $args['slug'] ) ) { 489 495 $slug = array_map( 'sanitize_title', $args['slug'] ); -
trunk/src/wp-includes/taxonomy.php
r40292 r40293 836 836 } 837 837 838 // No need to perform a query for empty 'slug' or 'name'. 839 if ( 'slug' === $field || 'name' === $field ) { 840 $value = (string) $value; 841 842 if ( 0 === strlen( $value ) ) { 843 return false; 844 } 845 } 846 838 847 if ( 'id' === $field || 'term_id' === $field ) { 839 848 $term = get_term( (int) $value, $taxonomy, $output, $filter ); -
trunk/tests/phpunit/tests/term/getTermBy.php
r40275 r40293 206 206 $this->assertEquals( 0, $action->get_call_count() ); 207 207 } 208 209 /** 210 * @ticket 21760 211 */ 212 public function test_get_term_by_name_with_string_0() { 213 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 214 215 $term_id = $this->factory->term->create( array( 216 'name' => '0', 217 'taxonomy' => 'wptests_tax', 218 ) ); 219 220 $found = get_term_by( 'name', '0', 'wptests_tax' ); 221 $this->assertSame( $term_id, $found->term_id ); 222 } 223 224 /** 225 * @ticket 21760 226 */ 227 public function test_get_term_by_slug_with_string_0() { 228 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 229 230 $term_id = $this->factory->term->create( array( 231 'taxonomy' => 'wptests_tax', 232 'name' => '0', 233 'slug' => '0', 234 ) ); 235 236 $found = get_term_by( 'slug', '0', 'wptests_tax' ); 237 $this->assertSame( $term_id, $found->term_id ); 238 } 239 240 /** 241 * @ticket 21760 242 */ 243 public function test_get_term_by_with_empty_string() { 244 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 245 246 $found_by_slug = get_term_by( 'slug', '', 'wptests_tax' ); 247 $found_by_name = get_term_by( 'name', '', 'wptests_tax' ); 248 249 $this->assertFalse( $found_by_slug ); 250 $this->assertFalse( $found_by_name ); 251 } 208 252 } -
trunk/tests/phpunit/tests/term/getTerms.php
r38382 r40293 2224 2224 } 2225 2225 2226 /** 2227 * @ticket 21760 2228 */ 2229 public function test_with_term_slug_equal_to_string_0() { 2230 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2231 2232 $term_id = self::factory()->term->create( array( 2233 'name' => '0', 2234 'slug' => '0', 2235 'taxonomy' => 'wptests_tax', 2236 ) ); 2237 2238 $found = get_terms( array( 2239 'taxonomy' => 'wptests_tax', 2240 'hide_empty' => 0, 2241 'slug' => '0', 2242 ) ); 2243 2244 $this->assertEqualSets( array( $term_id ), wp_list_pluck( $found, 'term_id' ) ); 2245 } 2246 2247 /** 2248 * @ticket 21760 2249 */ 2250 public function test_with_multiple_term_slugs_one_equal_to_string_0() { 2251 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2252 2253 $term_id1 = self::factory()->term->create( array( 2254 'name' => '0', 2255 'slug' => '0', 2256 'taxonomy' => 'wptests_tax', 2257 ) ); 2258 2259 $term_id2 = self::factory()->term->create( array( 2260 'name' => 'Test', 2261 'slug' => 'test', 2262 'taxonomy' => 'wptests_tax', 2263 ) ); 2264 2265 $found = get_terms( array( 2266 'taxonomy' => 'wptests_tax', 2267 'hide_empty' => 0, 2268 'slug' => array( 2269 '0', 2270 'test', 2271 ), 2272 ) ); 2273 2274 $this->assertEqualSets( array( $term_id1, $term_id2 ), wp_list_pluck( $found, 'term_id' ) ); 2275 } 2276 2226 2277 protected function create_hierarchical_terms_and_posts() { 2227 2278 $terms = array();
Note: See TracChangeset
for help on using the changeset viewer.