Make WordPress Core

Ticket #47188: 47188.diff

File 47188.diff, 1.2 KB (added by spacedmonkey, 6 years ago)
  • src/wp-includes/rest-api.php

     
    179179
    180180        // Default serving.
    181181        add_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
     182        add_filter( 'rest_pre_serve_request', 'rest_add_wp_die_handler_filter', 10 );
    182183        add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 );
    183184        add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
    184185
     
    646647}
    647648
    648649/**
     650 * Add the filter for the custom wp_die handler.
     651 *
     652 * This is hooked on rest_pre_dispatch, so any uses of wp_die in endpoints
     653 * will be wrapped by our custom wp_die handler to output JSON rather than the
     654 * usual HTML error page.
     655 *
     656 * @since 5.3.0
     657 */
     658function rest_add_wp_die_handler_filter() {
     659        add_filter( 'wp_die_handler', 'rest_wp_die_handler_callback' );
     660}
     661
     662/**
     663 * Callback to set the wp_die handler to rest_wp_die_handler.
     664 *
     665 * @return string
     666 * @since 5.3.0
     667 */
     668function rest_wp_die_handler_callback() {
     669        return '_json_wp_die_handler';
     670}
     671
     672/**
    649673 * Sends the "Allow" header to state all methods that can be sent to the current route.
    650674 *
    651675 * @since 4.4.0