REST API: Only provide JSON error code on PHP 5.3+.

json_last_error() was only added to PHP 5.3.0, so we can't provide the information for older versions.

See #38547.


git-svn-id: https://develop.svn.wordpress.org/trunk@39111 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan McCue 2016-11-03 04:57:00 +00:00
parent 3146b1e971
commit a94ba30624
1 changed files with 5 additions and 2 deletions

View File

@ -683,9 +683,12 @@ class WP_REST_Request implements ArrayAccess {
$error_data = array(
'status' => WP_Http::BAD_REQUEST,
'json_error_code' => json_last_error(),
'json_error_message' => json_last_error_msg(),
);
if ( function_exists( 'json_last_error' ) ) {
$error_data['json_error_code'] = json_last_error();
$error_data['json_error_message'] = json_last_error_msg();
}
return new WP_Error( 'rest_invalid_json', __( 'Invalid JSON body passed.' ), $error_data );
}