WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_REST_Request::parse_json_params() WP 4.4.0

Parses the JSON parameters.

Avoids parsing the JSON data until we need to access it.

Это метод класса: WP_REST_Request

Хуков нет.

Возвращает

true/WP_Error. True if the JSON data was passed or no JSON data was provided, WP_Error if invalid JSON was passed.

Использование

$WP_REST_Request = new WP_REST_Request();
$var = $WP_REST_Request->parse_json_params();

Список изменений

С версии 4.4.0 Введена.
С версии 4.7.0 Returns error instance if value cannot be decoded.

Код WP REST Request::parse json params: wp-includes/rest-api/class-wp-rest-request.php WP 5.2.2

<?php
protected function parse_json_params() {
	if ( $this->parsed_json ) {
		return true;
	}

	$this->parsed_json = true;

	// Check that we actually got JSON.
	$content_type = $this->get_content_type();

	if ( empty( $content_type ) || 'application/json' !== $content_type['value'] ) {
		return true;
	}

	$body = $this->get_body();
	if ( empty( $body ) ) {
		return true;
	}

	$params = json_decode( $body, true );

	/*
	 * Check for a parsing error.
	 *
	 * Note that due to WP's JSON compatibility functions, json_last_error
	 * might not be defined: https://core.trac.wordpress.org/ticket/27799
	 */
	if ( null === $params && ( ! function_exists( 'json_last_error' ) || JSON_ERROR_NONE !== json_last_error() ) ) {
		// Ensure subsequent calls receive error instance.
		$this->parsed_json = false;

		$error_data = array(
			'status' => WP_Http::BAD_REQUEST,
		);
		if ( function_exists( 'json_last_error' ) ) {
			$error_data['json_error_code']    = json_last_error();
			$error_data['json_error_message'] = json_last_error_msg();
		}

		return new WP_Error( 'rest_invalid_json', __( 'Invalid JSON body passed.' ), $error_data );
	}

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