Automattic\WooCommerce\Internal\Admin\Settings

Utils::get_wpcom_connection_authorizationpublic staticWC 1.0

Get the details to authorize a connection to WordPress.com.

The most important part of the result is the URL to redirect to for authorization.

Method of the class: Utils{}

No Hooks.

Returns

Array. 'success' => bool Whether the request was successful. 'errors' => array An array of error messages, if any. 'color_scheme' => string The color scheme to use for the authorization page. 'url' => string The URL to redirect to for authorization.

Usage

$result = Utils::get_wpcom_connection_authorization( $return_url ): array;
$return_url(string) (required)
The URL to redirect to after the connection is authorized.

Utils::get_wpcom_connection_authorization() code WC 10.3.3

public static function get_wpcom_connection_authorization( string $return_url ): array {
	$plugin_onboarding = new OnboardingPlugins();

	$request = new WP_REST_Request();
	$request->set_param( 'redirect_url', $return_url );
	$result = $plugin_onboarding->get_jetpack_authorization_url( $request );

	if ( ! empty( $result['url'] ) ) {
		$result['url'] = add_query_arg(
			array(
				// We use the new WooDNA value.
				'from'         => 'woocommerce-onboarding',
				// We inform Calypso that this is a WooPayments onboarding flow.
				'plugin_name'  => 'woocommerce-payments',
				// Use the current user's WP admin color scheme.
				'color_scheme' => $result['color_scheme'],
			),
			$result['url']
		);
	}

	return $result;
}