[wp-trac] [WordPress Trac] #11871: $pagenow is wrong in frontend processing (always set to "index.php")

WordPress Trac wp-trac at lists.automattic.com
Tue Jan 12 10:39:56 UTC 2010


#11871: $pagenow is wrong in frontend processing (always set to "index.php")
--------------------------+-------------------------------------------------
 Reporter:  codestyling   |       Owner:                         
     Type:  defect (bug)  |      Status:  new                    
 Priority:  high          |   Milestone:  2.9.2                  
Component:  Template      |     Version:  2.9.1                  
 Severity:  critical      |    Keywords:  template pagenow defect
--------------------------+-------------------------------------------------

Comment(by codestyling):

 The main confusion is this code inside '''vars.php''' :


 {{{
 // On which page are we ?
 if ( is_admin() ) {
         // wp-admin pages are checked more carefully
         preg_match('#/wp-admin/?(.*?)$#i', $PHP_SELF, $self_matches);
         $pagenow = $self_matches[1];
         $pagenow = trim($pagenow, '/');
         $pagenow = preg_replace('#\?.*?$#', '', $pagenow);
         if ( '' === $pagenow || 'index' === $pagenow || 'index.php' ===
 $pagenow ) {
                 $pagenow = 'index.php';
         } else {
                 preg_match('#(.*?)(/|$)#', $pagenow, $self_matches);
                 $pagenow = strtolower($self_matches[1]);
                 if ( '.php' !== substr($pagenow, -4, 4) )
                         $pagenow .= '.php'; // for Options +Multiviews:
 /wp-admin/themes/index.php (themes.php is queried)
         }
 } else {
         if ( preg_match('#([^/]+\.php)([?/].*?)?$#i', $PHP_SELF,
 $self_matches) )
                 $pagenow = strtolower($self_matches[1]);
         else
                 $pagenow = 'index.php';
 }
 }}}

 The code makes a difference between admin area and non admin area (equal
 to frontend visitor view only). At admin areas the ''$pagenow'' will be
 set properly but the else (frontend part) make no sence. At this point of
 time you will always get "index.php" at ''$pagenow'' so this could also be
 hard coded there!

 If this is not intended to be so, than this place is not the correct one.

 Sometimes is may be necessary to know the actual running "base" template,
 if you have as example includes inside your templates file fetching
 snippet files, that need to know exactly, what is going to be produced to
 change there behavior explicitly.
 Furthermore why we can obtain the correct running "base" file as admin
 area but not at frontend ?

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


More information about the wp-trac mailing list