Make WordPress Core


Ignore:
Timestamp:
03/16/2017 02:03:53 AM (7 years ago)
Author:
boonebgorges
Message:

Improve querying for terms with falsey names and slugs.

Prior to [38677], get_term_by() would always return false if
an empty string were passed as the queried 'name' or 'slug'. The
refactor to use get_terms() broke this behavior; inappropriately
imprecise empty() checks caused the 'name' or 'slug' clause to be
discarded altogether when fetching terms, resulting in an incorrect
term being returned from the function.

We fix the regression by special-casing truly empty values passed
to get_term_by(), and ensuring that WP_Term_Query is properly
able to handle 0 and '0' term queries.

Props sstoqnov.
Fixes #21760.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term-query.php

    r40147 r40293  
    475475        }
    476476
    477         if ( ! empty( $args['name'] ) ) {
     477        if (
     478            ( ! empty( $args['name'] ) ) ||
     479            ( is_string( $args['name'] ) && 0 !== strlen( $args['name'] ) )
     480        ) {
    478481            $names = (array) $args['name'];
    479482            foreach ( $names as &$_name ) {
     
    485488        }
    486489
    487         if ( ! empty( $args['slug'] ) ) {
     490        if (
     491            ( ! empty( $args['slug'] ) ) ||
     492            ( is_string( $args['slug'] ) && 0 !== strlen( $args['slug'] ) )
     493        ) {
    488494            if ( is_array( $args['slug'] ) ) {
    489495                $slug = array_map( 'sanitize_title', $args['slug'] );
Note: See TracChangeset for help on using the changeset viewer.