Make WordPress Core

Opened 10 years ago

Last modified 2 years ago

#29161 new defect (bug)

$pagenow variable not set in admin pages on Windows systems

Reported by: craxic's profile Craxic Owned by:
Milestone: Awaiting Review 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 (4)

#1 @dd32
9 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
9 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
6 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.

Note: See TracTickets for help on using tickets.