mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Taxonomy: Prevent non string taxonomy names generating warnings or errors.
This changeset adds an `is_string( $taxonomy )` check to the condition in `taxonomy_exists()`, to ensure `false` is returned when the `$taxonomy` is not a string. Follow-up to [35718]. Props costdev, peterwilsoncc, mukesh27. Fixes #56338. See #56336. git-svn-id: https://develop.svn.wordpress.org/trunk@53869 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -337,7 +337,7 @@ function get_taxonomy( $taxonomy ) {
|
||||
function taxonomy_exists( $taxonomy ) {
|
||||
global $wp_taxonomies;
|
||||
|
||||
return isset( $wp_taxonomies[ $taxonomy ] );
|
||||
return is_string( $taxonomy ) && isset( $wp_taxonomies[ $taxonomy ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -128,6 +128,41 @@ class Tests_Taxonomy extends WP_UnitTestCase {
|
||||
$this->assertFalse( taxonomy_exists( null ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that `taxonomy_exists()` returns `false` when the `$taxonomy`
|
||||
* argument is not a string.
|
||||
*
|
||||
* @ticket 56338
|
||||
*
|
||||
* @covers :taxonomy_exists
|
||||
*
|
||||
* @dataProvider data_taxonomy_exists_should_return_false_with_non_string_taxonomy
|
||||
*
|
||||
* @param mixed $taxonomy The non-string taxonomy.
|
||||
*/
|
||||
public function test_taxonomy_exists_should_return_false_with_non_string_taxonomy( $taxonomy ) {
|
||||
$this->assertFalse( taxonomy_exists( $taxonomy ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider with non-string values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function data_taxonomy_exists_should_return_false_with_non_string_taxonomy() {
|
||||
return array(
|
||||
'array' => array( array() ),
|
||||
'object' => array( new stdClass() ),
|
||||
'bool (true)' => array( true ),
|
||||
'bool (false)' => array( false ),
|
||||
'null' => array( null ),
|
||||
'integer (0)' => array( 0 ),
|
||||
'integer (1)' => array( 1 ),
|
||||
'float (0.0)' => array( 0.0 ),
|
||||
'float (1.1)' => array( 1.1 ),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_is_taxonomy_hierarchical() {
|
||||
$this->assertTrue( is_taxonomy_hierarchical( 'category' ) );
|
||||
$this->assertFalse( is_taxonomy_hierarchical( 'post_tag' ) );
|
||||
|
||||
Reference in New Issue
Block a user