[wp-trac] [WordPress Trac] #24674: WP_Query::is_page() should use stricter comparison

WordPress Trac noreply at wordpress.org
Tue Jul 2 15:43:14 UTC 2013


#24674: WP_Query::is_page() should use stricter comparison
--------------------------+------------------------------
 Reporter:  clifgriffin   |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  3.5.2
 Severity:  minor         |  Resolution:
 Keywords:  has-patch     |
--------------------------+------------------------------

Comment (by clifgriffin):

 Good point.  That could certainly cause a lot of issues in existing code.

 This may be crazy, but could we simply check if $page is_numeric, and then
 use absint()?

 {{{
 function is_page( $page = '' ) {
         if ( !$this->is_page )
                 return false;

         if ( empty( $page ) )
                 return true;

         $page_obj = $this->get_queried_object();

         if( is_numeric($page) )
                 $page = absint($page);

         $page = (array) $page;

         if ( in_array( $page_obj->ID, $page, true ) )
                 return true;
         elseif ( in_array( $page_obj->post_title, $page ) )
                 return true;
         else if ( in_array( $page_obj->post_name, $page ) )
                 return true;

         return false;
 }
 }}}

--
Ticket URL: <http://core.trac.wordpress.org/ticket/24674#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list