[wp-trac] [WordPress Trac] #63403: Handle null/falsy paths in wp_normalize_path without warnings
WordPress Trac
noreply at wordpress.org
Tue May 6 22:33:07 UTC 2025
#63403: Handle null/falsy paths in wp_normalize_path without warnings
--------------------------+-----------------------------
Reporter: zyphlar | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords: has-patch
Focuses: |
--------------------------+-----------------------------
Without this modification, some plugins like username-updater (Easy
Username Updater) may try to do something like call add_submenu_page(null,
...) which can result in an error like this filling up logs:
str_replace(): Passing null to parameter #3 ($subject) of type
array|string is deprecated
It stands to reason that a normalized null/false/empty path is still
null/false/empty (or maybe an empty string) and we should just guard whiny
functions like str_replace against unexpected input.
Github PR: https://github.com/WordPress/WordPress/pull/749
Patch:
From 7ed4124a7fc69fe1edcda31b764f2e776f6fdd4c Mon Sep 17 00:00:00 2001
From: zyphlar <zyphlar at users.noreply.github.com>
Date: Tue, 6 May 2025 15:25:49 -0700
Subject: [PATCH] Handle null/falsy paths in wp_normalize_path without
warnings
Without this modification, some plugins like username-updater (Easy
Username Updater) may try to do something like call
`add_submenu_page(null, ...)` which can result in an error like this
filling up logs:
`str_replace(): Passing null to parameter #3 ($subject) of type
array|string is deprecated`
It stands to reason that a normalized null/false/empty path is still
null/false/empty (or maybe an empty string) and we should just guard whiny
functions like str_replace against unexpected input.
---
wp-includes/functions.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 33b775e7182..5ffcaf432e5 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -2177,11 +2177,15 @@ function path_join( $base, $path ) {
* @since 4.4.0 Ensures upper-case drive letters on Windows systems.
* @since 4.5.0 Allows for Windows network shares.
* @since 4.9.7 Allows for PHP file wrappers.
+ * @since latest TODO Allows for null/falsy paths (returns whatever was
passed)
*
* @param string $path Path to normalize.
* @return string Normalized path.
*/
function wp_normalize_path( $path ) {
+ if (!$path) {
+ return $path;
+ }
$wrapper = '';
if ( wp_is_stream( $path ) ) {
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63403>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list