Make WordPress Core


Ignore:
Timestamp:
06/25/2023 10:48:28 AM (8 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Use str_contains() in a few more places.

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 [55988].

Props spacedmonkey.
See #58220.

File:
1 edited

Legend:

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

    r55990 r56021  
    44644464     * starting with /, # or ?, or a PHP file).
    44654465     */
    4466     if ( strpos( $url, ':' ) === false && ! in_array( $url[0], array( '/', '#', '?' ), true ) &&
    4467         ! preg_match( '/^[a-z0-9-]+?\.php/i', $url ) ) {
     4466    if ( ! str_contains( $url, ':' ) && ! in_array( $url[0], array( '/', '#', '?' ), true ) &&
     4467        ! preg_match( '/^[a-z0-9-]+?\.php/i', $url )
     4468    ) {
    44684469        $url = 'http://' . $url;
    44694470    }
Note: See TracChangeset for help on using the changeset viewer.