Changes between Initial Version and Version 1 of Ticket #31723, comment 12
- Timestamp:
- 03/23/2015 12:35:33 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #31723, comment 12
initial v1 4 4 5 5 * If `parse_query()` has already determined that this is not a page query at all (https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/query.php?marks=1598,1599#L1587), return false early https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/query.php?marks=4339,4340#L4324. 6 * If `empty( $page )`, we assume that no argumen has been passed to `is_page()`, and we're simply checking to see whether we're on any sort of page at all. We already know that we are, after the previous step. So we return true. https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/query.php?marks=4342,4343#L43246 * If `empty( $page )`, we assume that no argument has been passed to `is_page()`, and we're simply checking to see whether we're on any sort of page at all. We already know that we are, after the previous step. So we return true. https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/query.php?marks=4342,4343#L4324 This assumption is the source of the bug - `empty( $page )` is too broad a check. 7 7 * From this point on, we compare the passed value of `$page` against the current page. 8 8 … … 20 20 }}} 21 21 22 [ 31723.1.diff] fixes the behavior for `is_page( 0 )` and `is_page( false )` and `is_page( '' )`, but not for `is_page( null )`. I suppose there's an argument for privileging `''` and `false`: `get_metadata()` will generally return an empty string when the requested value is not found, and `get_option()` generally returns `false`, which means that the bug'll be fixed for cases where a falsey value is stored in one of these two places. My `func_num_args()` trick is a broader fix, though I know that in the past, function argument overloading has been frowned upon (harder to read and document).22 [attachment:31723.1.diff] fixes the behavior for `is_page( 0 )` and `is_page( false )` and `is_page( '' )`, but not for `is_page( null )`. I suppose there's an argument for privileging `''` and `false`: `get_metadata()` will generally return an empty string when the requested value is not found, and `get_option()` generally returns `false`, which means that the bug'll be fixed for cases where a falsey value is stored in one of these two places. My `func_num_args()` trick is a broader fix, though I know that in the past, function argument overloading has been frowned upon (harder to read and document). 23 23 24 24 In any of these cases, backward compatibility is a concern. It's very likely that plugins are counting on `is_page( 0 )` to return the same as `is_page()`. It's a hard thing to verify, though - I'm not sure how to search for it.