Repository navigation
Conversation
This replaces `foreach` loops that return `true` on the first matching element, or `false` on the first failing one, with `array_any()` and `array_all()`. All of them were added after the first round of conversions in [62550] and [62553]. The negated conditions in the `array_all()` callbacks are written out positively, for example `! is_string( $value ) || '' === $value` becomes `is_string( $value ) && '' !== $value`, so the operands are still evaluated in the same order and short-circuit in the same places. WordPress core includes polyfills for `array_any()` and `array_all()` 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], [62550], [62553], [62564], [63453]. See #65818.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
🟢 Approval recommended
The conversions preserve existing behavior and PHP compatibility, with no unresolved findings.
No open issues 🎉
What changed in this PR
Modernizes seven boolean checks across WordPress core without changing behavior.
Changes:
- Replaces early-return loops with
array_any()orarray_all(). - Preserves short-circuit evaluation and empty-array results, using existing compatibility polyfills.
| File | Description |
|---|---|
| src/wp-includes/secrets/class-wp-secrets-config-key-provider.php | Uses array_all() to validate salt values. |
| src/wp-includes/media.php | Uses array_any() to detect isolation headers. |
| src/wp-includes/class-wp-rewrite.php | Uses array_any() to detect random-base conflicts. |
| src/wp-includes/abilities/class-wp-abilities-content.php | Converts status permission and cache-priming checks. |
| src/wp-includes/abilities-api/class-wp-ability.php | Uses array_all() to validate capability strings. |
| src/wp-admin/includes/plugin.php | Uses array_any() to check restricted submenu entries. |
Review effort: Balanced
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Replaces
foreachloops that returntrueon the first matching element, orfalseon the first failing one, witharray_any()andarray_all(). All of these loops were added after the first round of conversions in r62550 and r62553.Why this is safe
array_any()andarray_all()short-circuit exactly like the loops they replace, and returnfalseandtruerespectively for an empty array, which matches the loops' fall-through values.arrayparameter type of the functions cannot throw aTypeError: a cast(array), alist<string>return type, a class constant,headers_list(), or an array literal.array_all()callbacks are written out positively, for example! is_string( $value ) || '' === $valuebecomesis_string( $value ) && '' !== $value. The operands are evaluated in the same order and short-circuit in the same places, sotrim()is still only called on strings.Follow-up to r59783, r62550, r62553, r62564, r63453.
Trac ticket: https://core.trac.wordpress.org/ticket/65818
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.