Make WordPress Core


Ignore:
Timestamp:
06/22/2023 02:34:56 PM (10 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-content/themes/twentytwenty/template-parts/pagination.php

    r51322 r55988  
    3838
    3939// If we're not outputting the previous page link, prepend a placeholder with `visibility: hidden` to take its place.
    40 if ( strpos( $posts_pagination, 'prev page-numbers' ) === false ) {
     40if ( ! str_contains( $posts_pagination, 'prev page-numbers' ) ) {
    4141    $posts_pagination = str_replace( '<div class="nav-links">', '<div class="nav-links"><span class="prev page-numbers placeholder" aria-hidden="true">' . $prev_text . '</span>', $posts_pagination );
    4242}
    4343
    4444// If we're not outputting the next page link, append a placeholder with `visibility: hidden` to take its place.
    45 if ( strpos( $posts_pagination, 'next page-numbers' ) === false ) {
     45if ( ! str_contains( $posts_pagination, 'next page-numbers' ) ) {
    4646    $posts_pagination = str_replace( '</div>', '<span class="next page-numbers placeholder" aria-hidden="true">' . $next_text . '</span></div>', $posts_pagination );
    4747}
Note: See TracChangeset for help on using the changeset viewer.