Don't bail out of term_exists() when term sanitizes to an empty string.

This change brings return values for failures of this sort in line with other
failed lookups in term_exists(): a null value is now returned in all cases
where the queried term is not found.

Adds unit test for the sanitization issue. Modifies existing unit test to
reflect the change in return value for empty term strings.

Props boonebgorges, georgestephanis.
Fixes #29589.
Built from https://develop.svn.wordpress.org/trunk@29865


git-svn-id: http://core.svn.wordpress.org/trunk@29625 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2014-10-09 03:16:18 +00:00
parent 659a6b3838
commit 587599c54f

View File

@ -1656,9 +1656,10 @@ function get_terms( $taxonomies, $args = '' ) {
* @param int|string $term The term to check
* @param string $taxonomy The taxonomy name to use
* @param int $parent Optional. ID of parent term under which to confine the exists search.
* @return mixed Returns 0 if the term does not exist. Returns the term ID if no taxonomy is specified
* and the term ID exists. Returns an array of the term ID and the term taxonomy ID
* if the taxonomy is specified and the pairing exists.
* @return mixed Returns null if the term does not exist. Returns the term ID
* if no taxonomy is specified and the term ID exists. Returns
* an array of the term ID and the term taxonomy ID the taxonomy
* is specified and the pairing exists.
*/
function term_exists( $term, $taxonomy = '', $parent = null ) {
global $wpdb;
@ -1677,9 +1678,7 @@ function term_exists( $term, $taxonomy = '', $parent = null ) {
}
$term = trim( wp_unslash( $term ) );
if ( '' === $slug = sanitize_title($term) )
return 0;
$slug = sanitize_title( $term );
$where = 't.slug = %s';
$else_where = 't.name = %s';