Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#31301 closed defect (bug) (duplicate)

Page ID of 0 passes is_page( 'ANYSLUG' ) check

Reported by: r-a-y's profile r-a-y Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Query Keywords: has-patch
Focuses: Cc:

Description

For plugins using virtual pages like BuddyPress and bbPress, to avoid notices we override $wp_query to set the page ID to 0.

If we land on a page with our resetted page ID of 0, if a theme dev is using is_page( 'ANYSLUG' ) on this page, the check will always return true.

The problem is due to $wp_query->is_page() using in_array( $page_obj->ID, $page ):
source:/tags/4.1/src/wp-includes/query.php@:4349#L4338

in_array( 0, array( 'ANYSLUG' ) always returns true.

My suggested fix would have been to use in_array()'s strict check - in_array( $page_obj->ID, $page, true ) - but that fails this test:
source:/tags/4.1/tests/phpunit/tests/canonical/pageOnFront.php@:51#L40

So, I've opted to check the page ID before doing the in_array() check.

Attached is a unit test demonstrating the problem with the fix suggested above.

Attachments (1)

31301.01.patch (1.4 KB) - added by r-a-y 10 years ago.

Download all attachments as: .zip

Change History (4)

@r-a-y
10 years ago

#1 @r-a-y
10 years ago

  • Keywords has-patch added

#2 @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #24674.

#3 @r-a-y
10 years ago

Ugh! Apologies for the duplicate and thanks for pointing me to that ticket, SergeyBiryukov!

Note: See TracTickets for help on using tickets.