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.

git-svn-id: https://develop.svn.wordpress.org/trunk@54414 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
David Baumwald 2022-10-07 14:23:58 +00:00
parent 9bbdd27b13
commit 494d20c469

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'];
}