Skip to content

Commit

Permalink
Admin Titles: avoid PHP warnings in PHP 8.1
Browse files Browse the repository at this point in the history
This avoids the following warning on pages where a title is not defined:

```
PHP Deprecated:  strip_tags(): Passing null to parameter WordPress#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: WordPress#4084
  • Loading branch information
jeherve committed Apr 6, 2023
1 parent b6b6ded commit 075890a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/wp-admin/admin-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 075890a

Please sign in to comment.