WooCommerce\Admin

Experimental_Abtest::request_assignment()publicWC 1.0

Perform the request for a experiment assignment of a provided A/B test from WP.com.

{} Это метод класса: Experimental_Abtest{}

Хуков нет.

Возвращает

Массив|\WP_Error. A/B test variation error on failure.

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

$Experimental_Abtest = new Experimental_Abtest();
$Experimental_Abtest->request_assignment( $args );
$args(массив) (обязательный)
Arguments to pass to the request for A/B test.

Код Experimental_Abtest::request_assignment() WC 6.7.0

public function request_assignment( $args ) {
	// Request as authenticated wp user.
	if ( $this->as_auth_wpcom_user && class_exists( Jetpack_Connection_Manager::class ) ) {
		$jetpack_connection_manager = new Jetpack_Connection_Manager();
		if ( $jetpack_connection_manager->is_user_connected() ) {
			$response = Jetpack_Connection_client::wpcom_json_api_request_as_user(
				'/experiments/0.1.0/assignments/' . $this->platform,
				'2',
				$args
			);
		}
	}

	// Request as anonymous user.
	if ( ! isset( $response ) ) {
		if ( ! isset( $args['anon_id'] ) || empty( $args['anon_id'] ) ) {
			return new \WP_Error( 'invalid_anon_id', 'anon_id must be an none empty string.' );
		}

		$url      = add_query_arg(
			$args,
			sprintf(
				'https://public-api.wordpress.com/wpcom/v2/experiments/0.1.0/assignments/%s',
				$this->platform
			)
		);
		$response = wp_remote_get( $url );
	}

	return $response;
}