mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-09 23:24:34 +00:00
REST API: Unify object access handling for simplicity.
Rather than repeating ourselves, unifying the access into a single method keeps everything tidy. While we're at it, add in additional schema handling for common parameters. See #38792. git-svn-id: https://develop.svn.wordpress.org/trunk@39954 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -46,6 +46,13 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset( $args['args'] ) ) {
|
||||
$common_args = $args['args'];
|
||||
unset( $args['args'] );
|
||||
} else {
|
||||
$common_args = array();
|
||||
}
|
||||
|
||||
if ( isset( $args['callback'] ) ) {
|
||||
// Upgrade a single set to multiple.
|
||||
$args = array( $args );
|
||||
@@ -57,12 +64,13 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
|
||||
'args' => array(),
|
||||
);
|
||||
foreach ( $args as $key => &$arg_group ) {
|
||||
if ( ! is_numeric( $arg_group ) ) {
|
||||
if ( ! is_numeric( $key ) ) {
|
||||
// Route option, skip here.
|
||||
continue;
|
||||
}
|
||||
|
||||
$arg_group = array_merge( $defaults, $arg_group );
|
||||
$arg_group['args'] = array_merge( $common_args, $arg_group['args'] );
|
||||
}
|
||||
|
||||
$full_route = '/' . trim( $namespace, '/' ) . '/' . trim( $route, '/' );
|
||||
|
||||
Reference in New Issue
Block a user