[wp-trac] [WordPress Trac] #61268: PHP Deprecated: ltrim() in formatting esc_url.
WordPress Trac
noreply at wordpress.org
Wed May 22 17:43:57 UTC 2024
#61268: PHP Deprecated: ltrim() in formatting esc_url.
--------------------------+------------------------------
Reporter: neo2k23 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Changes (by sabernhardt):
* version: trunk =>
* component: General => Formatting
Old description:
> I am getting constant these warnings in my error log file.
>
> [22-May-2024 13:00:43 UTC] PHP Deprecated: ltrim(): Passing null to
> parameter #1 ($string) of type string is deprecated in /home//public_html
> /wp-includes/formatting.php on line 4482
>
> it is caused by this code
>
> {{{#!php
> <?php
> $original_url = $url;
>
> if ( '' === $url ) {
> return $url;
> }
>
> $url = str_replace( ' ', '%20', ltrim( $url ) );
>
> }}}
>
> The last line is line 4482
>
> If i change line 4478 to this it does not happen anymore.
>
> {{{#!php
> <?php
> $original_url = $url;
>
> if ( '' === $url || empty ($url)) {
> return $url;
> }
>
> $url = str_replace( ' ', '%20', ltrim( $url ) );
> }}}
>
> Since any information is missing on the location which is calling esc_url
> it is hard to debug which theme code or plugin code is responsible for
> this.
>
> Can someone please explain to mewhat is going on here?
>
> Thank you
New description:
I am getting constant these warnings in my error log file.
`[22-May-2024 13:00:43 UTC] PHP Deprecated: ltrim(): Passing null to
parameter #1 ($string) of type string is deprecated in /.../wp-
includes/formatting.php on line 4482`
it is caused by this code
{{{#!php
<?php
$original_url = $url;
if ( '' === $url ) {
return $url;
}
$url = str_replace( ' ', '%20', ltrim( $url ) );
}}}
The last line is line 4482
If i change line 4478 to this it does not happen anymore.
{{{#!php
<?php
$original_url = $url;
if ( '' === $url || empty ($url)) {
return $url;
}
$url = str_replace( ' ', '%20', ltrim( $url ) );
}}}
Since any information is missing on the location which is calling
`esc_url` it is hard to debug which theme code or plugin code is
responsible for this.
Can someone please explain to me what is going on here?
Thank you
--
Comment:
This specific issue needs to be reported on the
[https://wordpress.org/support/plugin/maintenance/ Maintenance plugin
support forum] (and others).
[https://plugins.trac.wordpress.org/browser/maintenance/tags/4.08/load/index.php#L68
The pingback URL] uses `esc_url()` around `bloginfo()`, the echo function,
instead of using `get_bloginfo()` like this (from Twenty Ten):
`<?php echo esc_url( get_bloginfo( 'pingback_url' ) ); ?>`
Additional [https://wpdirectory.net/search/01HYGM2Q08QN0ADQK40ZK9WQEF
plugins] and [https://wpdirectory.net/search/01HYGMEN2VKRG34TNGWD9JJY4X
themes] have `esc_url()` with `bloginfo()`, too.
At least two security plugins replace 'pingback_url' with an empty string,
which should avoid the deprecation warnings, but that can still result in
an empty link `href`.
The `if ( '' == $url )` condition goes back to [1132], when the function
was named `clean_url()`, and the comparison became strict in [47808].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61268#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list