Make WordPress Core


Ignore:
Timestamp:
06/22/2023 02:34:56 PM (18 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Replace usage of strpos() with str_contains().

str_contains() was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).

WordPress core includes a polyfill for str_contains() on PHP < 8.0 as of WordPress 5.9.

This commit replaces false !== strpos( ... ) with str_contains() in core files, making the code more readable and consistent, as well as better aligned with modern development practices.

Follow-up to [52039], [52040], [52326], [55703], [55710], [55987].

Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes #58206.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r55720 r55988  
    13671367         * mysqlnd has supported utf8mb4 since 5.0.9.
    13681368         */
    1369         if ( false !== strpos( $mysql_client_version, 'mysqlnd' ) ) {
     1369        if ( str_contains( $mysql_client_version, 'mysqlnd' ) ) {
    13701370            $mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version );
    13711371            if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) {
     
    33363336
    33373337        $cache_hit_callback = static function ( $header_value ) {
    3338             return false !== strpos( strtolower( $header_value ), 'hit' );
     3338            return str_contains( strtolower( $header_value ), 'hit' );
    33393339        };
    33403340
Note: See TracChangeset for help on using the changeset viewer.