WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/03/2016 04:57:00 AM (4 years ago)
Author:
rmccue
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-request.php

    r39109 r39111  
    684684            $error_data = array(
    685685                'status' => WP_Http::BAD_REQUEST,
    686                 'json_error_code' => json_last_error(),
    687                 'json_error_message' => json_last_error_msg(),
    688686            );
     687            if ( function_exists( 'json_last_error' ) ) {
     688                $error_data['json_error_code'] = json_last_error();
     689                $error_data['json_error_message'] = json_last_error_msg();
     690            }
     691
    689692            return new WP_Error( 'rest_invalid_json', __( 'Invalid JSON body passed.' ), $error_data );
    690693        }
Note: See TracChangeset for help on using the changeset viewer.