Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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

This comment has been minimized.

Copy link
Owner Author

@mcguffin mcguffin commented Dec 19, 2018

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