Make WordPress Core


Ignore:
Timestamp:
06/22/2023 02:34:56 PM (21 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-login.php

    r55953 r55988  
    12301230            $redirect_to = $_REQUEST['redirect_to'];
    12311231            // Redirect to HTTPS if user wants SSL.
    1232             if ( $secure_cookie && false !== strpos( $redirect_to, 'wp-admin' ) ) {
     1232            if ( $secure_cookie && str_contains( $redirect_to, 'wp-admin' ) ) {
    12331233                $redirect_to = preg_replace( '|^http://|', 'https://', $redirect_to );
    12341234            }
     
    13671367            } elseif ( WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED === $action ) {
    13681368                $errors->add( 'enter_recovery_mode', __( 'Recovery Mode Initialized. Please log in to continue.' ), 'message' );
    1369             } elseif ( isset( $_GET['redirect_to'] ) && false !== strpos( $_GET['redirect_to'], 'wp-admin/authorize-application.php' ) ) {
     1369            } elseif ( isset( $_GET['redirect_to'] ) && str_contains( $_GET['redirect_to'], 'wp-admin/authorize-application.php' ) ) {
    13701370                $query_component = wp_parse_url( $_GET['redirect_to'], PHP_URL_QUERY );
    13711371                $query           = array();
Note: See TracChangeset for help on using the changeset viewer.