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() { |
180 | 180 | |
181 | 181 | // Default serving. |
182 | 182 | add_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' ); |
| 183 | add_filter( 'rest_pre_serve_request', 'rest_add_wp_die_handler_filter' ); |
183 | 184 | add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 ); |
184 | 185 | add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 ); |
185 | 186 | |
… |
… |
function rest_handle_options_request( $response, $handler, $request ) { |
650 | 651 | return $response; |
651 | 652 | } |
652 | 653 | |
| 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 | */ |
| 663 | function 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 | */ |
| 673 | function rest_wp_die_handler_callback() { |
| 674 | return '_json_wp_die_handler'; |
| 675 | } |
| 676 | |
653 | 677 | /** |
654 | 678 | * Sends the "Allow" header to state all methods that can be sent to the current route. |
655 | 679 | * |