REST API: Improve formatting of failed validation errors.
If a validation_callback returns a WP_Error it should give the same response format as if it returned `false`. This makes programmatically reading the validation errors better. Props bradyvercher for initial patch. Fixes #35028. Built from https://develop.svn.wordpress.org/trunk@35890 git-svn-id: http://core.svn.wordpress.org/trunk@35854 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c06143270e
commit
ee94a28953
|
@ -851,13 +851,13 @@ class WP_REST_Request implements ArrayAccess {
|
|||
}
|
||||
|
||||
if ( is_wp_error( $valid_check ) ) {
|
||||
$invalid_params[] = sprintf( '%s (%s)', $key, $valid_check->get_error_message() );
|
||||
$invalid_params[ $key ] = $valid_check->get_error_message();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $invalid_params ) {
|
||||
return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', $invalid_params ) ), array( 'status' => 400, 'params' => $invalid_params ) );
|
||||
return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.5-alpha-35889';
|
||||
$wp_version = '4.5-alpha-35890';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue