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. Built from https://develop.svn.wordpress.org/trunk@48361 git-svn-id: http://core.svn.wordpress.org/trunk@48130 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -4038,6 +4038,10 @@ function _wp_json_prepare_data( $data ) {
|
||||
* @param int $status_code The HTTP status code to output.
|
||||
*/
|
||||
function wp_send_json( $response, $status_code = null ) {
|
||||
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
|
||||
_doing_it_wrong( __FUNCTION__, __( 'Return a WP_REST_Response or WP_Error object from your callback when using the REST API.' ), '5.5.0' );
|
||||
}
|
||||
|
||||
if ( ! headers_sent() ) {
|
||||
header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
|
||||
if ( null !== $status_code ) {
|
||||
|
||||
Reference in New Issue
Block a user