mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-27 14:53:08 +02:00
REST API: Simplify the check for an array of arrays in register_rest_route()
.
The previous implementation of checking whether the `args` parameter is an array of arrays used `array_filter()`, which would always loop the full array, even though we are only interested in finding one (the first) non-array to display a `_doing_it_wrong()` message. This commit aims to improve readability and performance of this check by using a `foreach` loop instead, leaving it as soon as the first non-array argument is found. Follow-up to [54339]. Props TobiasBg, audrasjb, costdev, SergeyBiryukov. Fixes #56804. Built from https://develop.svn.wordpress.org/trunk@54518 git-svn-id: http://core.svn.wordpress.org/trunk@54073 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1ea37c466d
commit
169204a8e0
@ -104,7 +104,8 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
|
||||
);
|
||||
}
|
||||
|
||||
if ( count( array_filter( $arg_group['args'], 'is_array' ) ) !== count( $arg_group['args'] ) ) {
|
||||
foreach ( $arg_group['args'] as $arg ) {
|
||||
if ( ! is_array( $arg ) ) {
|
||||
_doing_it_wrong(
|
||||
__FUNCTION__,
|
||||
sprintf(
|
||||
@ -115,6 +116,8 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
|
||||
),
|
||||
'6.1.0'
|
||||
);
|
||||
break; // Leave the foreach loop once a non-array argument was found.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1-RC1-54517';
|
||||
$wp_version = '6.1-RC1-54518';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user