Make WordPress Core

Ticket #16802: 16802.3.patch

File 16802.3.patch, 2.6 KB (added by johnbillion, 11 years ago)
  • src/wp-includes/query.php

     
    42274227         *
    42284228         * @since 3.1.0
    42294229         *
    4230          * @param mixed $page Page ID, title, slug, or array of such.
     4230         * @param mixed $page Page ID, title, slug, path, or array of such.
    42314231         * @return bool
    42324232         */
    42334233        public function is_page( $page = '' ) {
     
    42414241
    42424242                $page = (array) $page;
    42434243
    4244                 if ( in_array( $page_obj->ID, $page ) )
     4244                if ( in_array( $page_obj->ID, $page ) ) {
    42454245                        return true;
    4246                 elseif ( in_array( $page_obj->post_title, $page ) )
     4246                } elseif ( in_array( $page_obj->post_title, $page ) ) {
    42474247                        return true;
    4248                 else if ( in_array( $page_obj->post_name, $page ) )
     4248                } else if ( in_array( $page_obj->post_name, $page ) ) {
    42494249                        return true;
     4250                } else {
     4251                        foreach ( $page as $index => $pagepath ) {
     4252                                $pagepath_page_obj = get_page_by_path( $pagepath );
     4253
     4254                                if ( $pagepath_page_obj && ( $pagepath_page_obj->ID == $page_obj->ID ) ) {
     4255                                        return true;
     4256                                }
     4257                        }
     4258                }
    42504259
    42514260                return false;
    42524261        }
  • tests/phpunit/tests/query/conditionals.php

     
    709709                $this->assertTrue( is_page( $post->post_name ) );
    710710        }
    711711
     712        /**
     713         * @ticket 16802
     714         */
     715        function test_is_page_with_parent() {
     716                $parent_id = $this->factory->post->create( array(
     717                        'post_type' => 'page',
     718                        'post_name' => 'foo',
     719                ) );
     720                $post_id = $this->factory->post->create( array(
     721                        'post_type'   => 'page',
     722                        'post_name'   => 'bar',
     723                        'post_parent' => $parent_id,
     724                ) );
     725                $this->go_to( "/?page_id=$post_id" );
     726
     727                $post = get_queried_object();
     728                $q = $GLOBALS['wp_query'];
     729
     730                $this->assertTrue( is_page() );
     731                $this->assertFalse( $q->is_single );
     732                $this->assertTrue( $q->is_page );
     733                $this->assertFalse( $q->is_attachment );
     734                $this->assertTrue( is_page( $post ) );
     735                $this->assertTrue( is_page( $post->ID ) );
     736                $this->assertTrue( is_page( $post->post_title ) );
     737                $this->assertTrue( is_page( $post->post_name ) );
     738                $this->assertTrue( is_page( 'foo/bar' ) );
     739                $this->assertFalse( is_page( $parent_id ) );
     740                $this->assertFalse( is_page( 'foo/bar/baz' ) );
     741                $this->assertFalse( is_page( 'bar/bar' ) );
     742                $this->assertFalse( is_page( 'foo' ) );
     743        }
     744
    712745        function test_is_attachment() {
    713746                $post_id = $this->factory->post->create( array( 'post_type' => 'attachment' ) );
    714747                $this->go_to( "/?attachment_id=$post_id" );