From 494d20c469925a2da030a06dbdf8a7bad5f68938 Mon Sep 17 00:00:00 2001 From: David Baumwald Date: Fri, 7 Oct 2022 14:23:58 +0000 Subject: [PATCH] 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 --- src/wp-admin/includes/class-wp-screen.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-screen.php b/src/wp-admin/includes/class-wp-screen.php index 7b7290011c..61217462eb 100644 --- a/src/wp-admin/includes/class-wp-screen.php +++ b/src/wp-admin/includes/class-wp-screen.php @@ -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']; }