mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Query: Prevent PHP notice when get_post_type_object() returns null in is_post_type_archive().
This changeset avoids potential PHP notices caused by `get_post_type_object()` returning `null` when called inside `is_post_type_archive()`. Props sean212, costdev. Fixes #56287. git-svn-id: https://develop.svn.wordpress.org/trunk@54464 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -769,4 +769,23 @@ class Tests_Query extends WP_UnitTestCase {
|
||||
$this->assertArrayHasKey( 'join', $posts_clauses_request );
|
||||
$this->assertSame( '/* posts_join_request */', $posts_clauses_request['join'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that is_post_type_archive() returns false for an undefined post type.
|
||||
*
|
||||
* @ticket 56287
|
||||
*
|
||||
* @covers ::is_post_type_archive
|
||||
*/
|
||||
public function test_is_post_type_archive_should_return_false_for_an_undefined_post_type() {
|
||||
global $wp_query;
|
||||
|
||||
$post_type = '56287-post-type';
|
||||
|
||||
// Force the request to be a post type archive.
|
||||
$wp_query->is_post_type_archive = true;
|
||||
$wp_query->set( 'post_type', $post_type );
|
||||
|
||||
$this->assertFalse( is_post_type_archive( $post_type ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user