[wp-trac] [WordPress Trac] #31301: Page ID of 0 passes is_page( 'ANYSLUG' ) check
WordPress Trac
noreply at wordpress.org
Wed Feb 11 18:37:27 UTC 2015
#31301: Page ID of 0 passes is_page( 'ANYSLUG' ) check
--------------------------+-----------------------------
Reporter: r-a-y | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version: 3.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/31301>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list