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. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
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. |
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 #14618. Follow-up to r59783, r62550, r62553, r62564, r63453, r64337, r64351, r64388, r64402, r64500, r64588. Props soean. See #65818. git-svn-id: https://develop.svn.wordpress.org/trunk@64690 602fd350-edb4-49c9-b593-d223f7449a82
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 WordPress/wordpress-develop#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
✅ Committed in r64690 (fb78023).
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.