Administration: Guard against undefined `$GLOBALS['hook_suffix']` in `WP_Screen::get()`.

When initially defaulting the screen `$id` in `WP_Screen::get()`, if the `$hook_name` parameter is not supplied, an `else` fallback uses `$GLOBALS['hook_suffix']`.  However, in some cases, `hook_suffix` doesn't exist in the global scope.  This produces an "Undefined index" notice on < PHP 8, and a warning in >= PHP 8.

This change ensures `$GLOBALS['hook_suffix']` has a value before using it as a fallback for the screen ID.

Props splendorstudio, SergeyBiryukov, htdat, mukesh27, dd32, costdev.
Fixes #49089.
Built from https://develop.svn.wordpress.org/trunk@54414


git-svn-id: http://core.svn.wordpress.org/trunk@53973 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
davidbaumwald 2022-10-07 14:25:14 +00:00
parent 6441d199f2
commit 8a8bd9192b
2 changed files with 3 additions and 2 deletions

View File

@ -212,6 +212,7 @@ final class WP_Screen {
return $hook_name;
}
$id = '';
$post_type = null;
$taxonomy = null;
$in_admin = false;
@ -220,7 +221,7 @@ final class WP_Screen {
if ( $hook_name ) {
$id = $hook_name;
} else {
} elseif ( ! empty( $GLOBALS['hook_suffix'] ) ) {
$id = $GLOBALS['hook_suffix'];
}

View File

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