diff --git a/src/wp-includes/post-functions.php b/src/wp-includes/post-functions.php index 05663968de..1c410d7674 100644 --- a/src/wp-includes/post-functions.php +++ b/src/wp-includes/post-functions.php @@ -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 ]; } /** diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php index e1ead02003..5a1be694d8 100644 --- a/tests/phpunit/tests/post/types.php +++ b/tests/phpunit/tests/post/types.php @@ -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' ) ); + } }