Code Modernization: Use str_starts_with() and str_ends_with() in a few more places.

`str_starts_with()` and `str_ends_with()` were introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins or ends with the given substring (needle).

WordPress core includes a polyfill for these functions on PHP < 8.0 as of WordPress 5.9.

Follow-up to [55990], [56014], [56019].

See #58220.

git-svn-id: https://develop.svn.wordpress.org/trunk@56020 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2023-06-24 17:15:06 +00:00
parent c226fa18f0
commit 89676d88a2
3 changed files with 4 additions and 4 deletions

View File

@@ -203,7 +203,7 @@ class WP_Http_Cookie {
// Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
$domain = ( str_starts_with( $domain, '.' ) ) ? substr( $domain, 1 ) : $domain;
if ( substr( $url['host'], -strlen( $domain ) ) !== $domain ) {
if ( ! str_ends_with( $url['host'], $domain ) ) {
return false;
}
@@ -213,7 +213,7 @@ class WP_Http_Cookie {
}
// Path - request path must start with path restriction.
if ( substr( $url['path'], 0, strlen( $path ) ) !== $path ) {
if ( ! str_starts_with( $url['path'], $path ) ) {
return false;
}