Skip to content

Commit

Permalink
Fix possible PHP warnings about admin title being null.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Jan 16, 2025
1 parent 0d8ac58 commit eb0cd31
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions felixarntz-mu-plugins/clean-plugin-menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,22 @@ static function () {
add_action(
'admin_init',
function () use ( $moved, $admin_menu ) {
global $pagenow, $plugin_page;
global $pagenow, $plugin_page, $title;

if ( ! isset( $plugin_page ) || ! isset( $moved[ $plugin_page ] ) ) {
if ( ! isset( $plugin_page ) ) {
return;
}

// Prevent PHP warnings about `$title` being null.
if ( ! is_string( $title ) ) {
$page_item = $admin_menu->get_menu_page( $plugin_page );
if ( ! $page_item ) {
$page_item = $admin_menu->get_submenu_page( '', $plugin_page );
}
$title = $page_item ? $page_item[0] : ''; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
}

if ( ! isset( $moved[ $plugin_page ] ) ) {
return;
}

Expand All @@ -271,7 +284,7 @@ function () use ( $moved, $admin_menu ) {
add_action(
'load-' . $current_moved_page['new_hookname'],
function () use ( $current_moved_page ) {
global $hook_suffix, $title;
global $hook_suffix;

// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$hook_suffix = $current_moved_page['old_hookname'];
Expand Down

0 comments on commit eb0cd31

Please sign in to comment.