WC_Auth::make_validation()protectedWC 2.4.0

Make validation.

Method of the class: WC_Auth{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->make_validation();

Changelog

Since 2.4.0 Introduced.

WC_Auth::make_validation() code WC 9.4.2

protected function make_validation() {
	$data   = array();
	$params = array(
		'app_name',
		'user_id',
		'return_url',
		'callback_url',
		'scope',
	);

	foreach ( $params as $param ) {
		if ( empty( $_REQUEST[ $param ] ) ) { // WPCS: input var ok, CSRF ok.
			/* translators: %s: parameter */
			throw new Exception( sprintf( __( 'Missing parameter %s', 'woocommerce' ), $param ) );
		}

		$data[ $param ] = wp_unslash( $_REQUEST[ $param ] ); // WPCS: input var ok, CSRF ok, sanitization ok.
	}

	if ( ! in_array( $data['scope'], array( 'read', 'write', 'read_write' ), true ) ) {
		/* translators: %s: scope */
		throw new Exception( sprintf( __( 'Invalid scope %s', 'woocommerce' ), wc_clean( $data['scope'] ) ) );
	}

	foreach ( array( 'return_url', 'callback_url' ) as $param ) {
		$param = $this->get_formatted_url( $data[ $param ] );

		if ( false === filter_var( $param, FILTER_VALIDATE_URL ) ) {
			/* translators: %s: url */
			throw new Exception( sprintf( __( 'The %s is not a valid URL', 'woocommerce' ), $param ) );
		}
	}

	$callback_url = $this->get_formatted_url( $data['callback_url'] );

	if ( 0 !== stripos( $callback_url, 'https://' ) ) {
		throw new Exception( __( 'The callback_url needs to be over SSL', 'woocommerce' ) );
	}
}