Make WordPress Core

Changeset 56019


Ignore:
Timestamp:
06/24/2023 04:48:25 PM (11 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].

See #58220.

Location:
trunk/src/wp-includes
Files:
5 edited

Legend:

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

    r55988 r56019  
    14621462        foreach ( $q['search_terms'] as $term ) {
    14631463            // If there is an $exclusion_prefix, terms prefixed with it should be excluded.
    1464             $exclude = $exclusion_prefix && ( substr( $term, 0, 1 ) === $exclusion_prefix );
     1464            $exclude = $exclusion_prefix && str_starts_with( $term, $exclusion_prefix );
    14651465            if ( $exclude ) {
    14661466                $like_op  = 'NOT LIKE';
  • trunk/src/wp-includes/deprecated.php

    r55990 r56019  
    948948
    949949    $order = 'ASC';
    950     if ( substr($orderby, 0, 1) === '_' ) {
     950    if ( str_starts_with($orderby, '_') ) {
    951951        $order = 'DESC';
    952952        $orderby = substr($orderby, 1);
  • trunk/src/wp-includes/link-template.php

    r55988 r56019  
    38923892
    38933893    $url = trim( $url );
    3894     if ( substr( $url, 0, 2 ) === '//' ) {
     3894    if ( str_starts_with( $url, '//' ) ) {
    38953895        $url = 'http:' . $url;
    38963896    }
  • trunk/src/wp-includes/ms-functions.php

    r55988 r56019  
    402402            }
    403403
    404             if ( $email_domain == $banned_domain ) {
     404            if ( $email_domain === $banned_domain ) {
    405405                $is_email_address_unsafe = true;
    406406                break;
    407407            }
    408408
    409             $dotted_domain = ".$banned_domain";
    410             if ( substr( $normalized_email, -strlen( $dotted_domain ) ) === $dotted_domain ) {
     409            if ( str_ends_with( $normalized_email, ".$banned_domain" ) ) {
    411410                $is_email_address_unsafe = true;
    412411                break;
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r54891 r56019  
    11381138
    11391139            // Unquote quoted filename, but after trimming.
    1140             if ( substr( $filename, 0, 1 ) === '"' && substr( $filename, -1, 1 ) === '"' ) {
     1140            if ( str_starts_with( $filename, '"' ) && str_ends_with( $filename, '"' ) ) {
    11411141                $filename = substr( $filename, 1, -1 );
    11421142            }
Note: See TracChangeset for help on using the changeset viewer.