WordPress.org

Make WordPress Core

Ticket #47188: 47188.2.diff

File 47188.2.diff, 1.3 KB (added by spacedmonkey, 5 months ago)
  • src/wp-includes/rest-api.php

    diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
    index 9f63b87f93..494bc0b0ad 100644
    a b function rest_api_default_filters() { 
    180180
    181181        // Default serving.
    182182        add_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
     183        add_filter( 'rest_pre_serve_request', 'rest_add_wp_die_handler_filter' );
    183184        add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 );
    184185        add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );
    185186
    function rest_handle_options_request( $response, $handler, $request ) { 
    650651        return $response;
    651652}
    652653
     654/**
     655 * Add the filter for the custom wp_die handler.
     656 *
     657 * This is hooked on rest_pre_dispatch, so any uses of wp_die in endpoints
     658 * will be wrapped by our custom wp_die handler to output JSON rather than the
     659 * usual HTML error page.
     660 *
     661 * @since 5.5.0
     662 */
     663function rest_add_wp_die_handler_filter() {
     664        add_filter( 'wp_die_handler', 'rest_wp_die_handler_callback' );
     665}
     666
     667/**
     668 * Callback to set the wp_die handler to rest_wp_die_handler.
     669 *
     670 * @since 5.5.0
     671 * @return string
     672 */
     673function rest_wp_die_handler_callback() {
     674        return '_json_wp_die_handler';
     675}
     676
    653677/**
    654678 * Sends the "Allow" header to state all methods that can be sent to the current route.
    655679 *