wp_send_json_error
函数
wp_send_json_error ( $data = null, $status_code = null, $options = 0 )
- 参数
-
-
(mixed)
$data
Optional. Data to encode as JSON, then print and die. Default null.- Required: 否
- Default: null
-
(int)
$status_code
Optional. The HTTP status code to output. Default null.- Required: 否
- Default: null
-
(int)
$options
Optional. Options to be passed to json_encode(). Default 0.- Required: 否
-
(mixed)
- 定义位置
-
-
wp-includes/functions.php
, line 4469
-
wp-includes/functions.php
- 引入
- 3.5.0
- 弃用
- –
Sends a JSON response back to an Ajax request, indicating failure.
If the `$data` parameter is a WP_Error object, the errors
within the object are processed and output as an array of error
codes and corresponding messages. All other types are output
without further processing.
function wp_send_json_error( $data = null, $status_code = null, $options = 0 ) { $response = array( 'success' => false ); if ( isset( $data ) ) { if ( is_wp_error( $data ) ) { $result = array(); foreach ( $data->errors as $code => $messages ) { foreach ( $messages as $message ) { $result[] = array( 'code' => $code, 'message' => $message, ); } } $response['data'] = $result; } else { $response['data'] = $data; } } wp_send_json( $response, $status_code, $options ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。