Make WordPress Core


Ignore:
Timestamp:
06/22/2023 02:34:56 PM (2 years 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-automatic-updater.php

    r55911 r55988  
    583583        // Send debugging email to admin for all development installations.
    584584        if ( ! empty( $this->update_results ) ) {
    585             $development_version = false !== strpos( get_bloginfo( 'version' ), '-' );
     585            $development_version = str_contains( get_bloginfo( 'version' ), '-' );
    586586
    587587            /**
     
    641641        // We should not try to perform a background update again until there is a successful one-click update performed by the user.
    642642        $critical = false;
    643         if ( 'disk_full' === $error_code || false !== strpos( $error_code, '__copy_dir' ) ) {
     643        if ( 'disk_full' === $error_code || str_contains( $error_code, '__copy_dir' ) ) {
    644644            $critical = true;
    645645        } elseif ( 'rollback_was_required' === $error_code && is_wp_error( $result->get_error_data()->rollback ) ) {
     
    647647            $critical        = true;
    648648            $rollback_result = $result->get_error_data()->rollback;
    649         } elseif ( false !== strpos( $error_code, 'do_rollback' ) ) {
     649        } elseif ( str_contains( $error_code, 'do_rollback' ) ) {
    650650            $critical = true;
    651651        }
Note: See TracChangeset for help on using the changeset viewer.