mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Posts, Post Types: Ensure is_page_template() can only return true when viewing a singular post query.
Props natereist, dlh Fixes #39211 git-svn-id: https://develop.svn.wordpress.org/trunk@39599 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1073,6 +1073,32 @@ class Tests_Query_Conditionals extends WP_UnitTestCase {
|
||||
$this->assertTrue( is_page_template( array( 'test.php', 'example.php' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 39211
|
||||
*/
|
||||
function test_is_page_template_not_singular() {
|
||||
global $wpdb;
|
||||
|
||||
// We need a non-post that shares an ID with a post assigned a template.
|
||||
$user_id = self::factory()->user->create();
|
||||
if ( ! get_post( $user_id ) ) {
|
||||
$post_id = self::factory()->post->create( array( 'post_type' => 'post' ) );
|
||||
$wpdb->update( $wpdb->posts, array( 'ID' => $user_id ), array( 'ID' => $post_id ), array( '%d' ) );
|
||||
}
|
||||
|
||||
update_post_meta( $user_id, '_wp_page_template', 'example.php' );
|
||||
|
||||
// Verify that the post correctly reports having a template.
|
||||
$this->go_to( get_post_permalink( $user_id ) );
|
||||
$this->assertInstanceOf( 'WP_Post', get_queried_object() );
|
||||
$this->assertTrue( is_page_template( 'example.php' ) );
|
||||
|
||||
// Verify that the non-post with a matching ID does not report having a template.
|
||||
$this->go_to( get_author_posts_url( $user_id ) );
|
||||
$this->assertInstanceOf( 'WP_User', get_queried_object() );
|
||||
$this->assertFalse( is_page_template( 'example.php' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35902
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user