From 075890a98df21e020c5dcdeb2557d2c0de9b4520 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Thu, 6 Apr 2023 10:14:33 +0200 Subject: [PATCH] Admin Titles: avoid PHP warnings in PHP 8.1 This avoids the following warning on pages where a title is not defined: ``` PHP Deprecated: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /wp-admin/admin-header.php on line 36 ``` This should not normally happen, but some folks may pass null to `add_submenu_page()` when creating new pages, to hide that page from the admin menu. This may not be the best approach, but it is one that is documented in the codex and used in the wild: https://developer.wordpress.org/reference/functions/add_submenu_page/#comment-445 - Related Core trac ticket: https://core.trac.wordpress.org/ticket/57579 - Related PR: #4084 --- src/wp-admin/admin-header.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/admin-header.php b/src/wp-admin/admin-header.php index 3306c9125b129..72e31f6cc2a33 100644 --- a/src/wp-admin/admin-header.php +++ b/src/wp-admin/admin-header.php @@ -33,7 +33,10 @@ } get_admin_page_title(); -$title = strip_tags( $title ); + +if ( ! is_null( $title ) ) { + $title = wp_strip_all_tags( $title ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited +} if ( is_network_admin() ) { /* translators: Network admin screen title. %s: Network title. */