[wp-trac] [WordPress Trac] #14494: Move the is_*() (aka conditional tags, conditional functions) functionality into the WP_Query class

WordPress Trac wp-trac at lists.automattic.com
Sat Jul 31 22:23:55 UTC 2010


#14494: Move the is_*() (aka conditional tags, conditional functions) functionality
into the WP_Query class
-------------------------+--------------------------------------------------
 Reporter:  mdawaffe     |       Owner:           
     Type:  enhancement  |      Status:  new      
 Priority:  normal       |   Milestone:  3.1      
Component:  Query        |     Version:  3.0.1    
 Severity:  normal       |    Keywords:  has-patch
-------------------------+--------------------------------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14494>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list