Skip to content

Instantly share code, notes, and snippets.

@mcguffin
Created December 16, 2018 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcguffin/641dfa2cdff36357e714a21fb045267f to your computer and use it in GitHub Desktop.
Save mcguffin/641dfa2cdff36357e714a21fb045267f to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Fix core issue 42656
Description: Fix PHP Warning undefined index pagenow on login popup. Place this into wp-content/mu-plugins/
Author: McGuffin
Author URI: http://github.org/mcguffin
Version: 0.0.1
*/
// borrowed from wp-includes/vars.php
global $pagenow;
// On which page are we ?
if ( is_admin() ) {
// wp-admin pages are checked more carefully
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);
$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', $_SERVER['PHP_SELF'], $self_matches) )
$pagenow = strtolower($self_matches[1]);
else
$pagenow = 'index.php';
}
unset($self_matches);
@mcguffin
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment