Make WordPress Core


Ignore:
Timestamp:
06/24/2023 05:15:06 PM (21 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-http-cookie.php

    r55990 r56020  
    204204        // Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
    205205        $domain = ( str_starts_with( $domain, '.' ) ) ? substr( $domain, 1 ) : $domain;
    206         if ( substr( $url['host'], -strlen( $domain ) ) !== $domain ) {
     206        if ( ! str_ends_with( $url['host'], $domain ) ) {
    207207            return false;
    208208        }
     
    214214
    215215        // Path - request path must start with path restriction.
    216         if ( substr( $url['path'], 0, strlen( $path ) ) !== $path ) {
     216        if ( ! str_starts_with( $url['path'], $path ) ) {
    217217            return false;
    218218        }
Note: See TracChangeset for help on using the changeset viewer.