Make WordPress Core


Ignore:
Timestamp:
06/25/2023 10:48:28 AM (3 years 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/blocks.php

    r56005 r56021  
    804804    $result = '';
    805805
    806     if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
     806    if ( str_contains( $text, '<!--' ) && str_contains( $text, '--->' ) ) {
    807807        $text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
    808808    }
Note: See TracChangeset for help on using the changeset viewer.