[wp-trac] [WordPress Trac] #59757: Function wp_normalize_path() is causing a deprecated error when $path is null.
WordPress Trac
noreply at wordpress.org
Thu Jan 11 22:18:14 UTC 2024
#59757: Function wp_normalize_path() is causing a deprecated error when $path is
null.
----------------------------+------------------------
Reporter: garymarkfuller | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: General | Version: 6.3.2
Severity: normal | Resolution: duplicate
Keywords: php81 | Focuses:
----------------------------+------------------------
Changes (by sabernhardt):
* status: new => closed
* resolution: => duplicate
* milestone: Awaiting Review =>
Old description:
> 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 /home/gary/bailey-head/wordpress
> /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;
> }
> }}}
New description:
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;
}
}}}
--
Comment:
#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
[https://wpdirectory.net/search/01HHD6Z8T4Y1ACTKK68HJ5CNJJ 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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59757#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list