Commit dde5c0e2f9 for wordpress.org
commit dde5c0e2f96ddf3cd519349ce9cef1f1e603ba2a
Author: westonruter <westonruter@git.wordpress.org>
Date: Fri Oct 23 17:59:49 2026 +0000
Code Modernization: Use `array_any()` and `array_all()` more widely.
This replaces `foreach` loops that return early on the first matching or failing element with `array_any()` and `array_all()`, with no change in behavior. These loops were all added in later features, so they were missed by the conversions in r62550 and r62553.
Developed in https://github.com/WordPress/wordpress-develop/pull/14618.
Follow-up to r59783, r62550, r62553, r62564, r63453, r64337, r64351, r64388, r64402, r64500, r64588.
Props soean.
See #65818.
Built from https://develop.svn.wordpress.org/trunk@64690
git-svn-id: http://core.svn.wordpress.org/trunk@63840 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php
index c9830eb1a9..9fc438026c 100644
--- a/wp-admin/includes/plugin.php
+++ b/wp-admin/includes/plugin.php
@@ -2205,13 +2205,10 @@ function wp_admin_page_exists(): bool {
return true;
}
- foreach ( (array) $_wp_submenu_nopriv as $nopriv_submenus ) {
- if ( isset( $nopriv_submenus[ $plugin_page ] ) ) {
- return true;
- }
- }
-
- return false;
+ return array_any(
+ (array) $_wp_submenu_nopriv,
+ fn( $nopriv_submenus ) => isset( $nopriv_submenus[ $plugin_page ] )
+ );
}
/**
diff --git a/wp-includes/abilities-api/class-wp-ability.php b/wp-includes/abilities-api/class-wp-ability.php
index d800e8c1b2..8b007de170 100644
--- a/wp-includes/abilities-api/class-wp-ability.php
+++ b/wp-includes/abilities-api/class-wp-ability.php
@@ -641,12 +641,10 @@ class WP_Ability {
return false;
}
- foreach ( $capabilities as $capability ) {
- if ( ! is_string( $capability ) || '' === trim( $capability ) ) {
- return false;
- }
- }
- return true;
+ return array_all(
+ $capabilities,
+ fn( $capability ) => is_string( $capability ) && '' !== trim( $capability )
+ );
}
/**
diff --git a/wp-includes/abilities/class-wp-abilities-content.php b/wp-includes/abilities/class-wp-abilities-content.php
index 8d75cb3f14..af3fe8f62d 100644
--- a/wp-includes/abilities/class-wp-abilities-content.php
+++ b/wp-includes/abilities/class-wp-abilities-content.php
@@ -282,13 +282,10 @@ final class WP_Abilities_Content {
* @return bool True if the requested statuses may be queried.
*/
private function can_query_statuses( array $where, WP_Post_Type $post_type_object ): bool {
- foreach ( $this->get_requested_statuses( $where ) as $status ) {
- if ( ! $this->can_query_status( $status, $post_type_object ) ) {
- return false;
- }
- }
-
- return true;
+ return array_all(
+ $this->get_requested_statuses( $where ),
+ fn( $status ) => $this->can_query_status( $status, $post_type_object )
+ );
}
/**
@@ -790,13 +787,10 @@ final class WP_Abilities_Content {
* @return bool True when post meta and term caches should be primed.
*/
private function should_prime_post_caches( array $fields ): bool {
- foreach ( self::CACHE_PRIMING_FIELDS as $field ) {
- if ( $this->is_field_requested( $field, $fields ) ) {
- return true;
- }
- }
-
- return false;
+ return array_any(
+ self::CACHE_PRIMING_FIELDS,
+ fn( $field ) => $this->is_field_requested( $field, $fields )
+ );
}
/**
diff --git a/wp-includes/class-wp-rewrite.php b/wp-includes/class-wp-rewrite.php
index 0c571e4d76..20967bafa0 100644
--- a/wp-includes/class-wp-rewrite.php
+++ b/wp-includes/class-wp-rewrite.php
@@ -1559,13 +1559,10 @@ class WP_Rewrite {
$random_base_posts[] = get_page_by_path( $random_slug, OBJECT, 'post' );
}
- $random_base_is_taken = false;
- foreach ( $random_base_posts as $random_base_post ) {
- if ( $random_base_post instanceof WP_Post && is_post_publicly_viewable( $random_base_post ) ) {
- $random_base_is_taken = true;
- break;
- }
- }
+ $random_base_is_taken = array_any(
+ $random_base_posts,
+ fn( $random_base_post ) => $random_base_post instanceof WP_Post && is_post_publicly_viewable( $random_base_post )
+ );
if ( ! $random_base_is_taken ) {
$rules[ $random_base . '/?$' ] = $this->index . '?random=1';
diff --git a/wp-includes/media.php b/wp-includes/media.php
index 351d4c3f71..3c675dd05d 100644
--- a/wp-includes/media.php
+++ b/wp-includes/media.php
@@ -7018,12 +7018,9 @@ function wp_is_cross_origin_isolated_request(): bool {
return true;
}
- foreach ( headers_list() as $header ) {
- if ( 0 === stripos( $header, 'Document-Isolation-Policy:' ) ) {
- return true;
- }
- }
-
- return false;
+ return array_any(
+ headers_list(),
+ fn( $header ) => 0 === stripos( $header, 'Document-Isolation-Policy:' )
+ );
}
diff --git a/wp-includes/secrets/class-wp-secrets-config-key-provider.php b/wp-includes/secrets/class-wp-secrets-config-key-provider.php
index 7fbd208818..c99adc925e 100644
--- a/wp-includes/secrets/class-wp-secrets-config-key-provider.php
+++ b/wp-includes/secrets/class-wp-secrets-config-key-provider.php
@@ -261,13 +261,10 @@ final class WP_Secrets_Config_Key_Provider implements WP_Secrets_Keyring {
* @phpstan-assert-if-true non-empty-string $logged_in_salt
*/
private function are_usable_salt_values( $logged_in_key, $logged_in_salt ): bool {
- foreach ( array( $logged_in_key, $logged_in_salt ) as $value ) {
- if ( ! is_string( $value ) || '' === $value || self::KNOWN_PLACEHOLDER === $value ) {
- return false;
- }
- }
-
- return true;
+ return array_all(
+ array( $logged_in_key, $logged_in_salt ),
+ fn( $value ) => is_string( $value ) && '' !== $value && self::KNOWN_PLACEHOLDER !== $value
+ );
}
/**
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 7ab4fc5b61..0e667fd610 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-beta1-64689';
+$wp_version = '7.2-beta1-64690';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.