Automattic\WooCommerce\Internal\Admin\Settings

PaymentsRestController::check_providers_order_map_arg()privateWC 1.0

Validate the providers order map argument.

Метод класса: PaymentsRestController{}

Хуков нет.

Возвращает

WP_Error|true. True if the providers order map argument is valid, otherwise a WP_Error object.

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

// private - только в коде основоного (родительского) класса
$result = $this->check_providers_order_map_arg( $value );
$value(разное) (обязательный)
Value of the argument.

Код PaymentsRestController::check_providers_order_map_arg() WC 9.6.1

private function check_providers_order_map_arg( $value ) {
	if ( ! is_array( $value ) ) {
		return new WP_Error( 'rest_invalid_param', esc_html__( 'The ordering argument must be an object.', 'woocommerce' ), array( 'status' => 400 ) );
	}

	foreach ( $value as $provider_id => $order ) {
		if ( ! is_string( $provider_id ) || ! is_numeric( $order ) ) {
			return new WP_Error( 'rest_invalid_param', esc_html__( 'The ordering argument must be an object with provider IDs as keys and numeric values as values.', 'woocommerce' ), array( 'status' => 400 ) );
		}

		if ( sanitize_key( $provider_id ) !== $provider_id ) {
			return new WP_Error( 'rest_invalid_param', esc_html__( 'The provider ID must be a valid string.', 'woocommerce' ), array( 'status' => 400 ) );
		}

		if ( false === filter_var( $order, FILTER_VALIDATE_INT ) ) {
			return new WP_Error( 'rest_invalid_param', esc_html__( 'The order value must be an integer.', 'woocommerce' ), array( 'status' => 400 ) );
		}
	}

	return true;
}