Automattic\WooCommerce\Admin\API

OnboardingPlugins::get_jetpack_authorization_url()publicWC 1.0

Return Jetpack authorization URL.

Method of the class: OnboardingPlugins{}

No Hooks.

Return

Array.

Usage

$OnboardingPlugins = new OnboardingPlugins();
$OnboardingPlugins->get_jetpack_authorization_url( $request );
$request(WP_REST_Request) (required)
WP_REST_Request object.

OnboardingPlugins::get_jetpack_authorization_url() code WC 9.1.2

public function get_jetpack_authorization_url( WP_REST_Request $request ) {
	$manager = new Manager( 'woocommerce' );
	$errors  = new WP_Error();

	// Register the site to wp.com.
	if ( ! $manager->is_connected() ) {
		$result = $manager->try_registration();
		if ( is_wp_error( $result ) ) {
			$errors->add( $result->get_error_code(), $result->get_error_message() );
		}
	}

	$redirect_url = $request->get_param( 'redirect_url' );
	$calypso_env  = defined( 'WOOCOMMERCE_CALYPSO_ENVIRONMENT' ) && in_array( WOOCOMMERCE_CALYPSO_ENVIRONMENT, [ 'development', 'wpcalypso', 'horizon', 'stage' ], true ) ? WOOCOMMERCE_CALYPSO_ENVIRONMENT : 'production';

	return [
		'success' => ! $errors->has_errors(),
		'errors'  => $errors->get_error_messages(),
		'url'     => add_query_arg(
			[
				'from'        => $request->get_param( 'from' ),
				'calypso_env' => $calypso_env,
			],
			$manager->get_authorization_url( null, $redirect_url )
		),
	];
}