Make WordPress Core


Ignore:
Timestamp:
06/23/2026 01:53:35 PM (32 hours ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Use array_any() where appropriate.

This commit replaces several foreach loops that iterate an array, return true as soon as an element matches a condition, and otherwise fall through to false. That is exactly what PHP 8.4's array_any() expresses in a single, more readable call.

WordPress core includes a polyfill for array_any() on PHP < 8.4 as of WordPress 6.8, so the change works on every supported PHP version without raising the minimum requirement.

Follow-up to [59783].

Props Soean, mukesh27, SergeyBiryukov.
See #65519.

File:
1 edited

Legend:

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

    r62368 r62550  
    851851        }
    852852
    853         foreach ( (array) $this->default_dirs as $test ) {
    854             if ( str_starts_with( $src, $test ) ) {
    855                 return true;
    856             }
    857         }
    858         return false;
     853        return array_any( (array) $this->default_dirs, fn( $test ) => str_starts_with( $src, $test ) );
    859854    }
    860855
Note: See TracChangeset for help on using the changeset viewer.