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

WP_REST_Request::has_valid_params() WP 4.4.0

Checks whether this request is valid according to its attributes.

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

Хуков нет.

Возвращает

true/false/WP_Error. True if there are no parameters to validate or if all pass validation, WP_Error if required parameters are missing.

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

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

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

С версии 4.4.0 Введена.

Код WP REST Request::has valid params: wp-includes/rest-api/class-wp-rest-request.php WP 5.2.4

<?php
public function has_valid_params() {
	// If JSON data was passed, check for errors.
	$json_error = $this->parse_json_params();
	if ( is_wp_error( $json_error ) ) {
		return $json_error;
	}

	$attributes = $this->get_attributes();
	$required   = array();

	// No arguments set, skip validation.
	if ( empty( $attributes['args'] ) ) {
		return true;
	}

	foreach ( $attributes['args'] as $key => $arg ) {

		$param = $this->get_param( $key );
		if ( isset( $arg['required'] ) && true === $arg['required'] && null === $param ) {
			$required[] = $key;
		}
	}

	if ( ! empty( $required ) ) {
		return new WP_Error(
			'rest_missing_callback_param',
			sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ),
			array(
				'status' => 400,
				'params' => $required,
			)
		);
	}

	/*
	 * Check the validation callbacks for each registered arg.
	 *
	 * This is done after required checking as required checking is cheaper.
	 */
	$invalid_params = array();

	foreach ( $attributes['args'] as $key => $arg ) {

		$param = $this->get_param( $key );

		if ( null !== $param && ! empty( $arg['validate_callback'] ) ) {
			$valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key );

			if ( false === $valid_check ) {
				$invalid_params[ $key ] = __( 'Invalid parameter.' );
			}

			if ( is_wp_error( $valid_check ) ) {
				$invalid_params[ $key ] = $valid_check->get_error_message();
			}
		}
	}

	if ( $invalid_params ) {
		return new WP_Error(
			'rest_invalid_param',
			sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ),
			array(
				'status' => 400,
				'params' => $invalid_params,
			)
		);
	}

	return true;

}