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.
Built from https://develop.svn.wordpress.org/trunk@53294


git-svn-id: http://core.svn.wordpress.org/trunk@52883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-04-27 13:47:11 +00:00
parent 87c8ca71b5
commit 6e9c29da06
2 changed files with 4 additions and 2 deletions

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 {

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-beta3-53293';
$wp_version = '6.0-beta3-53294';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.