WP_REST_Request::get_json_params(): array

Retrieves the parameters from a JSON-formatted body.

Return

array Parameter map of key to value.

Source

public function get_json_params() {
	// Ensure the parameters have been parsed out.
	$this->parse_json_params();

	return $this->params['JSON'];
}

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    For example

    add_action( 'rest_api_init', 'wpdocs_create_custom_endpoint' );
    
    function wpdocs_create_custom_endpoint() {
    	register_rest_route(
    		'wpdocs/v1',
    		'/send-message',
    		array(
    			'methods' => 'POST',
    			'callback' =>'wpdocs_get_response_send_message',
    			'permission_callback' => '__return_true',
    		)
    	);
    
    }
    
    function wpdocs_get_response_send_message( $request ) {
    	$json_params = $request->get_json_params();
    	error_log( print_r( $json_params, true ) );
    }

You must log in before being able to contribute a note or feedback.