Make WordPress Core

Opened 15 years ago

Closed 14 years ago

Last modified 14 years ago

#14494 closed enhancement (fixed)

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

Reported by: mdawaffe's profile mdawaffe 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:

  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 (1)

14494.diff (27.5 KB) - added by mdawaffe 15 years ago.

Download all attachments as: .zip

Change History (5)

@mdawaffe
15 years ago

#1 @scribu
15 years ago

A great idea!

#2 @mikeschinkel
15 years ago

  • Cc mikeschinkel@… added

#3 @ryan
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

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

#4 @scribu
14 years ago

Interesting side effect: #14729 #14705

Note: See TracTickets for help on using tickets.