Make WordPress Core

Changeset 54414


Ignore:
Timestamp:
10/07/2022 02:23:58 PM (20 months ago)
Author:
davidbaumwald
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-screen.php

    r54133 r54414  
    213213        }
    214214
     215        $id              = '';
    215216        $post_type       = null;
    216217        $taxonomy        = null;
     
    221222        if ( $hook_name ) {
    222223            $id = $hook_name;
    223         } else {
     224        } elseif ( ! empty( $GLOBALS['hook_suffix'] ) ) {
    224225            $id = $GLOBALS['hook_suffix'];
    225226        }
Note: See TracChangeset for help on using the changeset viewer.