#14494 closed enhancement (fixed)
Move the is_*() (aka conditional tags, conditional functions) functionality into the WP_Query class
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | 3.0.1 |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
Description
The is_*()
convenience functions only work for the global $wp_query
object.
In particular, they don't tell you anything about the current query while in hooks like pre_get_post
.
Attached moves their definitions to the WP_Query
class so that you can do things like ->is_author()
on the current global $wp_query
on the main global $wp_the_query
and on the currently running query in filters like pre_get_post
(all of which can be different in certain scenarios).
For example:
function my_query_mod( &$query ) { global $wp_the_query; // On the front page and doing an is_author sub or supplemental loop if ( $wp_the_query->is_front_page() && $query->is_author( 'bob' ) ) { // do something } }
I think this is a piece of the puzzle in making the WP
class hooks (request
, parse_request
) and the WP_Query
hooks (pre_get_posts
, etc.) all more useful and easier to use.
The attached also:
- Cleans up the inline docs.
- Deprecates
is_plugin_page()
which looks useless with the advent of the various hooks based off ofget_plugin_page_hookname()
.
Note:
I moved all the is_*()
functions to be methods of WP_Query
, but there's some we could probably keep as is. is_trackback()
, is_robots()
, and is_comments_popup()
probably don't need to be accessible on any query but the main one from the WP
class.
A great idea!