Make WordPress Core


Ignore:
Timestamp:
06/26/2023 10:15:04 AM (22 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], [56021].

See #58206.

File:
1 edited

Legend:

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

    r55988 r56031  
    908908
    909909    $url = true;
    910     if ( strpos( $show, 'url' ) === false &&
    911         strpos( $show, 'directory' ) === false &&
    912         strpos( $show, 'home' ) === false ) {
     910
     911    if ( ! str_contains( $show, 'url' )
     912        && ! str_contains( $show, 'directory' )
     913        && ! str_contains( $show, 'home' )
     914    ) {
    913915        $url = false;
    914916    }
     
    37393741                $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && (int) $match[1] >= 534 );
    37403742            } elseif ( $is_IE ) {
    3741                 $wp_rich_edit = ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' ) !== false );
     3743                $wp_rich_edit = str_contains( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' );
    37423744            } elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) {
    37433745                $wp_rich_edit = true;
Note: See TracChangeset for help on using the changeset viewer.