Make WordPress Core

Opened 11 years ago

Closed 6 months ago

#29161 closed defect (bug) (invalid)

$pagenow variable not set in admin pages on Windows systems

Reported by: craxic's profile Craxic Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Administration Keywords: reporter-feedback
Focuses: administration Cc:

Description

In the most recent version of WordPress:

vars.php, starting line 25:

if ( is_network_admin() )
    preg_match('#/wp-admin/network/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
elseif ( is_user_admin() )
    preg_match('#/wp-admin/user/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
else
    preg_match('#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);

The "/" character does not match the "\" character found as the directory separator on Windows systems. This causes various issues throughout the entirety of the administration pages, notably that "add_meta_box" ceases to function correctly.

Would recommend it be changed to something like this:

$ds = preg_quote(DIRECTORY_SEPARATOR);
if ( is_network_admin() )
    preg_match('#'.$ds.'wp-admin'.$ds.'network'.$ds.'?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
elseif ( is_user_admin() )
    preg_match('#'.$ds.'wp-admin'.$ds.'user'.$ds.'?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);
else
    preg_match('#'.$ds.'wp-admin'.$ds.'?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches);

Thanks for the wonderful software!

Change History (5)

#1 @dd32
11 years ago

  • Keywords reporter-feedback added

$_SERVER['PHP_SELF'] should be in a URL format, regardless of if the host is Unix or Windows based. it's supposed to specifically contain only the path component, ie. /path/to/wp-admin/ in http://example.com/path/to/wp-admin/.

I initially thought this might be a failure in wp_fix_server_vars() but doesn't look like that could be the case.

@Craxic - Sorry it's taken so long for you to get a response here, are you still seeing this failure? Do you still have the server environment available? Could you supply us an example of the contents of the $_SERVER variable at the start of wp_fix_server_vars()?
could you also provide as much information about the server configuration as you can? It really sounds like a misconfiguration of a cgi based system to me.

#2 @aoloe
10 years ago

i have the same problem on os x.

in my case i don't miss any value, but i get a warning and the js call fails.

i solved the issue by checking that the matches variable is an array and has enough values:

	$pagenow = '';
	if (is_array($self_matches) && (count($self_matches) > 2)) {
		$pagenow = $self_matches[1];
	}

with this patch, the plugin i'm using is working correctly.

can this patch be applied to vars.php?

#3 @soulseekah
7 years ago

This sounds like a server configuration issue.

PHP_SELF may indeed contain backslashes on Windows machines on certain servers (think very old Apache+mod_php or some old PHP-FPM version).

Would be good to find out what server was being run. If this is a common configuration occurrence (probably not) wp_fix_server_vars() should be fixing the path in PHP_SELF.

#5 @karmatosed
6 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

It looks like we haven't had any response since this was suggested it was a server issue. In order to progress this ticket more details are needed and whilst thank you everyone for your collaboration so far, my approach is going to be to close this ticket for now until we get that information. We can always reopen if more details become available. We can also reopen should other suggestions require that. For now, it makes sense to close with an invalid status. Again, this could change once we have more insight.

Note: See TracTickets for help on using tickets.