Ticket #14494 (closed enhancement: fixed)

Opened 22 months ago

Last modified 21 months ago

Move the is_*() (aka conditional tags, conditional functions) functionality into the WP_Query class

Reported by: mdawaffe Owned by:
Priority: normal Milestone: 3.1
Component: Query Version: 3.0.1
Severity: normal Keywords: has-patch
Cc: mikeschinkel@…

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:

  1. Cleans up the inline docs.
  2. Deprecates is_plugin_page() which looks useless with the advent of the various hooks based off of get_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.

Attachments

14494.diff Download (27.5 KB) - added by mdawaffe 22 months ago.

Change History

A great idea!

  • Cc mikeschinkel@… added
  • Status changed from new to closed
  • Resolution set to fixed

(In [15531]) is_* WP_Query methods. Props mdawaffe. fixes #14494

Interesting side effect: #14729 #14705

Note: See TracTickets for help on using tickets.