rest_get_combining_operation_error
函数
rest_get_combining_operation_error ( $value, $param, $errors )
- 参数
-
-
(array)
$value
The value to validate.- Required: 是
-
(string)
$param
The parameter name, used in error messages.- Required: 是
-
(array)
$errors
The errors array, to search for possible error.- Required: 是
-
(array)
- 返回值
-
- (WP_Error) The combining operation error.
- 定义位置
-
-
wp-includes/rest-api.php
, line 1789
-
wp-includes/rest-api.php
- 引入
- 5.6.0
- 弃用
- –
Gets the error of combining operation.
function rest_get_combining_operation_error( $value, $param, $errors ) {
// If there is only one error, simply return it.
if ( 1 === count( $errors ) ) {
return rest_format_combining_operation_error( $param, $errors[0] );
}
// Filter out all errors related to type validation.
$filtered_errors = array();
foreach ( $errors as $error ) {
$error_code = $error['error_object']->get_error_code();
$error_data = $error['error_object']->get_error_data();
if ( 'rest_invalid_type' !== $error_code || ( isset( $error_data['param'] ) && $param !== $error_data['param'] ) ) {
$filtered_errors[] = $error;
}
}
// If there is only one error left, simply return it.
if ( 1 === count( $filtered_errors ) ) {
return rest_format_combining_operation_error( $param, $filtered_errors[0] );
}
// If there are only errors related to object validation, try choosing the most appropriate one.
if ( count( $filtered_errors ) > 1 && 'object' === $filtered_errors[0]['schema']['type'] ) {
$result = null;
$number = 0;
foreach ( $filtered_errors as $error ) {
if ( isset( $error['schema']['properties'] ) ) {
$n = count( array_intersect_key( $error['schema']['properties'], $value ) );
if ( $n > $number ) {
$result = $error;
$number = $n;
}
}
}
if ( null !== $result ) {
return rest_format_combining_operation_error( $param, $result );
}
}
// If each schema has a title, include those titles in the error message.
$schema_titles = array();
foreach ( $errors as $error ) {
if ( isset( $error['schema']['title'] ) ) {
$schema_titles[] = $error['schema']['title'];
}
}
if ( count( $schema_titles ) === count( $errors ) ) {
/* translators: 1: Parameter, 2: Schema titles. */
return new WP_Error( 'rest_no_matching_schema', wp_sprintf( __( '%1$s is not a valid %2$l.' ), $param, $schema_titles ) );
}
/* translators: %s: Parameter. */
return new WP_Error( 'rest_no_matching_schema', sprintf( __( '%s does not match any of the expected formats.' ), $param ) );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。