Un motore di ricerca WordPress per sviluppatori e autori di temi



wp_send_json ›

Da3.5.0
Deprecaton/a
wp_send_json ( $response, $status_code = null )
Parametri: (2)
  • (mixed) $response Variable (usually an array or object) to encode as JSON, then print and die.
    Richiesto:
  • (int) $status_code The HTTP status code to output.
    Richiesto: No
    Default: null
Definito a:
Codex:
ChangeLog:
  • 4.7.0

Send a JSON response back to an Ajax request.



Sorgenti

function wp_send_json( $response, $status_code = null ) {
	if ( ! headers_sent() ) {
		header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
		if ( null !== $status_code ) {
			status_header( $status_code );
		}
	}

	echo wp_json_encode( $response );

	if ( wp_doing_ajax() ) {
		wp_die(
			'',
			'',
			array(
				'response' => null,
			)
		);
	} else {
		die;
	}
}