Make WordPress Core


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

File:
1 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';
Note: See TracChangeset for help on using the changeset viewer.