Bootstrap/Load: Avoid a PHP warning when setting the $pagenow global in wp-includes/vars.php.

In some scenarios where `is_admin()` returns true but `$_SERVER['PHP_SELF']` does not match a `wp-admin/*` location, setting the `$pagenow` global could trigger a PHP warning: `Undefined array key 1`.

This commit avoids the warning by checking whether the matches array is not empty.

Props janh2, konradyoast, peterwilsoncc.
Fixes #54700.

git-svn-id: https://develop.svn.wordpress.org/trunk@53294 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-04-27 13:45:57 +00:00
parent d47a44ab68
commit 37f91b71c6

View File

@ -29,9 +29,11 @@ if ( is_admin() ) {
} else {
preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
}
$pagenow = $self_matches[1];
$pagenow = ! empty( $self_matches[1] ) ? $self_matches[1] : '';
$pagenow = trim( $pagenow, '/' );
$pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
$pagenow = 'index.php';
} else {