Make WordPress Core

Changeset 62564


Ignore:
Timestamp:
06/25/2026 07:43:05 PM (10 hours ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Use array_any() in WP_REST_Comments_Controller.

This commit replaces a foreach loop in ::check_post_type_supports_notes() that iterates the editor supports, returns true as soon as an element has non-empty notes, and otherwise falls 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], [62550], [62553].

Props Soean.
See #65519.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r61888 r62564  
    20502050    private function check_post_type_supports_notes( $post_type ) {
    20512051        $supports = get_all_post_type_supports( $post_type );
     2052
    20522053        if ( ! isset( $supports['editor'] ) ) {
    20532054            return false;
    20542055        }
     2056
    20552057        if ( ! is_array( $supports['editor'] ) ) {
    20562058            return false;
    20572059        }
    2058         foreach ( $supports['editor'] as $item ) {
    2059             if ( ! empty( $item['notes'] ) ) {
    2060                 return true;
    2061             }
    2062         }
    2063         return false;
     2060
     2061        return array_any( $supports['editor'], fn( $item ) => ! empty( $item['notes'] ) );
    20642062    }
    20652063}
Note: See TracChangeset for help on using the changeset viewer.