#31301 closed defect (bug) (duplicate)
Page ID of 0 passes is_page( 'ANYSLUG' ) check
| Reported by: |
|
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.
Duplicate of #24674.