Opened 13 months ago
Closed 10 months ago
#59757 closed defect (bug) (duplicate)
Function wp_normalize_path() is causing a deprecated error when $path is null.
Reported by: | garymarkfuller | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 6.3.2 |
Component: | General | Keywords: | php81 |
Focuses: | Cc: |
Description (last modified by )
The function wp_normalize_path()
is causing the error below on my test environment:
PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /.../wp-includes/functions.php on line 2182
Locally I altered the function to resolve the error as per the code below:
function wp_normalize_path( $path ) { $wrapper = ''; if(!empty($path)) { if ( wp_is_stream( $path ) ) { list( $wrapper, $path ) = explode( '://', $path, 2 ); $wrapper .= '://'; } // Standardize all paths to use '/'. $path = str_replace( '\\', '/', $path ); // Replace multiple slashes down to a singular, allowing for network shares having two slashes. $path = preg_replace( '|(?<=.)/+|', '/', $path ); // Windows paths should uppercase the drive letter. if ( ':' === substr( $path, 1, 1 ) ) { $path = ucfirst( $path ); } } return $wrapper . $path; }
Change History (2)
#2
@
10 months ago
- Description modified (diff)
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
#57580 (and #57581) had earlier reports about the deprecated warnings for wp_normalize_path()
and wp_is_stream()
.
The four causes identified on #57580 were all plugins that had added null
in the add_submenu_page()
function. Those four plugins have been updated for newer PHP, but a directory search still finds many plugins doing it wrong. The problem could also be somewhere else.
If you identify the issue in a plugin, please report it to the plugin's author.
@garymarkfuller Thanks for reporting this. This issue will need a backtrace to figure out where the error is coming from.
The wp_normalize_path() function is documented as only accepting a
string
and the error you are reporting means something somewhere is passingnull
towp_normalize_path()
. This needs to be fixed at the source of the problem, not in thewp_normalize_path()
function.