Check if the $post_type
passed to get_post_type_object()
is a scalar
value. Non-scalars were producing PHP warnings.
Adds unit tests. Props Kloon. Fixes #30013. git-svn-id: https://develop.svn.wordpress.org/trunk@34100 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
13dd966554
commit
5d0bc76040
@ -835,10 +835,11 @@ function get_post_type( $post = null ) {
|
||||
function get_post_type_object( $post_type ) {
|
||||
global $wp_post_types;
|
||||
|
||||
if ( empty($wp_post_types[$post_type]) )
|
||||
if ( ! is_scalar( $post_type ) || empty( $wp_post_types[ $post_type ] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $wp_post_types[$post_type];
|
||||
return $wp_post_types[ $post_type ];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,4 +122,24 @@ class Tests_Post_Types extends WP_UnitTestCase {
|
||||
return $labels;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ticket 30013
|
||||
*/
|
||||
public function test_get_post_type_object_with_non_scalar_values() {
|
||||
$this->assertFalse( post_type_exists( 'foo' ) );
|
||||
|
||||
register_post_type( 'foo' );
|
||||
|
||||
$this->assertTrue( post_type_exists( 'foo' ) );
|
||||
|
||||
$this->assertNotNull( get_post_type_object( 'foo' ) );
|
||||
$this->assertNull( get_post_type_object( array() ) );
|
||||
$this->assertNull( get_post_type_object( array( 'foo' ) ) );
|
||||
$this->assertNull( get_post_type_object( new stdClass ) );
|
||||
|
||||
_unregister_post_type( 'foo' );
|
||||
|
||||
$this->assertFalse( post_type_exists( 'foo' ) );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user