Skip to content

Commit 260fcbe

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@62564 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5908f03 commit 260fcbe

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,17 +2049,15 @@ protected function check_is_comment_content_allowed( $prepared_comment ) {
20492049
*/
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
}

0 commit comments

Comments
 (0)