From 37f91b71c627a18c2cfff20fd50556d32b34a287 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 27 Apr 2022 13:45:57 +0000 Subject: [PATCH] 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 --- src/wp-includes/vars.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/vars.php b/src/wp-includes/vars.php index 5f9257e85a..e285ed8321 100644 --- a/src/wp-includes/vars.php +++ b/src/wp-includes/vars.php @@ -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 {