WordPress.org

Make WordPress Core

Ticket #24674: 24674.ray.patch

File 24674.ray.patch, 1.4 KB (added by r-a-y, 5 years ago)
  • src/wp-includes/query.php

     
    43704370
    43714371                $page = (array) $page;
    43724372
    4373                 if ( in_array( $page_obj->ID, $page ) ) {
     4373                if ( 0 !== $page_obj->ID && in_array( $page_obj->ID, $page ) ) {
    43744374                        return true;
    43754375                } elseif ( in_array( $page_obj->post_title, $page ) ) {
    43764376                        return true;
  • tests/phpunit/tests/query/conditionals.php

     
    809809                $this->assertTrue( is_attachment( $post->post_title ) );
    810810                $this->assertTrue( is_attachment( $post->post_name ) );
    811811        }
     812
     813        function test_is_page_with_page_id_zero_and_random_page_slug() {
     814                $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     815                $this->go_to( "/?page_id=$post_id" );
     816
     817                // override post ID to 0 temporarily for testing
     818                $_id = $GLOBALS['wp_query']->post->ID;
     819                $GLOBALS['wp_query']->post->ID = 0;
     820
     821                $post = get_queried_object();
     822                $q = $GLOBALS['wp_query'];
     823
     824                $this->assertTrue( $q->is_page() );
     825                $this->assertFalse( $q->is_page( 'sample-page' ) );
     826                $this->assertFalse( $q->is_page( 'random-page-slug' ) );
     827
     828                // revert $wp_query global change
     829                $GLOBALS['wp_query']->post->ID = $_id;
     830        }
    812831}