Make WordPress Core


Ignore:
Timestamp:
07/07/2020 04:59:51 AM (4 years ago)
Author:
whyisjake
Message:

REST API: Trigger _doing_it_wrong() if wp_send_json() is used on a REST API request

In addition to triggering the _doing_it_wrong() logging, also adds a X-WP-DoingItWrong header.

Fixes #36271.

Props rmccue, TimothyBlynJacobs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r48359 r48361  
    40394039 */
    40404040function wp_send_json( $response, $status_code = null ) {
     4041    if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
     4042        _doing_it_wrong( __FUNCTION__, __( 'Return a WP_REST_Response or WP_Error object from your callback when using the REST API.' ), '5.5.0' );
     4043    }
     4044
    40414045    if ( ! headers_sent() ) {
    40424046        header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
Note: See TracChangeset for help on using the changeset viewer.