diff options
Diffstat (limited to 'plugins/jetpack/_inc/class.jetpack-provision.php')
-rw-r--r-- | plugins/jetpack/_inc/class.jetpack-provision.php | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/plugins/jetpack/_inc/class.jetpack-provision.php b/plugins/jetpack/_inc/class.jetpack-provision.php index 600e79ad..e3d95b27 100644 --- a/plugins/jetpack/_inc/class.jetpack-provision.php +++ b/plugins/jetpack/_inc/class.jetpack-provision.php @@ -1,5 +1,10 @@ <?php //phpcs:ignore +use Automattic\Jetpack\Connection\Client; +use Automattic\Jetpack\Connection\Utils as Connection_Utils; +use Automattic\Jetpack\Roles; +use Automattic\Jetpack\Sync\Actions; + class Jetpack_Provision { //phpcs:ignore /** @@ -17,27 +22,22 @@ class Jetpack_Provision { //phpcs:ignore ); foreach ( $url_args as $url_arg => $constant_name ) { - // Anonymous functions were introduced in 5.3.0. So, if we're running on - // >= 5.3.0, use an anonymous function to set the home/siteurl value%s. - // - // Otherwise, fallback to setting the home/siteurl value via the WP_HOME and - // WP_SITEURL constants if the constant hasn't already been defined. if ( isset( $named_args[ $url_arg ] ) ) { - if ( version_compare( phpversion(), '5.3.0', '>=' ) ) { - add_filter( $url_arg, function() use ( $url_arg, $named_args ) { // phpcs:ignore PHPCompatibility.PHP.NewClosure.Found + add_filter( + $url_arg, + function() use ( $url_arg, $named_args ) { return $named_args[ $url_arg ]; - }, 11 ); - } elseif ( ! defined( $constant_name ) ) { - define( $constant_name, $named_args[ $url_arg ] ); - } + }, + 11 + ); } } // If Jetpack is currently connected, and is not in Safe Mode already, kick off a sync of the current // functions/callables so that we can test if this site is in IDC. - if ( Jetpack::is_active() && ! Jetpack::validate_sync_error_idc_option() && Jetpack_Sync_Actions::sync_allowed() ) { - Jetpack_Sync_Actions::do_full_sync( array( 'functions' => true ) ); - Jetpack_Sync_Actions::$sender->do_full_sync(); + if ( Jetpack::is_active() && ! Jetpack::validate_sync_error_idc_option() && Actions::sync_allowed() ) { + Actions::do_full_sync( array( 'functions' => true ) ); + Actions::$sender->do_full_sync(); } if ( Jetpack::validate_sync_error_idc_option() ) { @@ -47,10 +47,8 @@ class Jetpack_Provision { //phpcs:ignore ); } - $blog_id = Jetpack_Options::get_option( 'id' ); - $blog_token = Jetpack_Options::get_option( 'blog_token' ); - if ( ! $blog_id || ! $blog_token || ( isset( $named_args['force_register'] ) && intval( $named_args['force_register'] ) ) ) { + if ( ! Jetpack::connection()->is_registered() || ( isset( $named_args['force_register'] ) && intval( $named_args['force_register'] ) ) ) { // This code mostly copied from Jetpack::admin_page_load. Jetpack::maybe_set_version_option(); $registered = Jetpack::try_registration(); @@ -59,9 +57,6 @@ class Jetpack_Provision { //phpcs:ignore } elseif ( ! $registered ) { return new WP_Error( 'registration_error', __( 'There was an unspecified error registering the site', 'jetpack' ) ); } - - $blog_id = Jetpack_Options::get_option( 'id' ); - $blog_token = Jetpack_Options::get_option( 'blog_token' ); } // If the user isn't specified, but we have a current master user, then set that to current user. @@ -100,8 +95,9 @@ class Jetpack_Provision { //phpcs:ignore $user = wp_get_current_user(); // Role. - $role = Jetpack::translate_current_user_to_role(); - $signed_role = Jetpack::sign_role( $role ); + $roles = new Roles(); + $role = $roles->translate_current_user_to_role(); + $signed_role = Jetpack::connection()->sign_role( $role ); $secrets = Jetpack::init()->generate_secrets( 'authorize' ); @@ -186,11 +182,12 @@ class Jetpack_Provision { //phpcs:ignore } // Add calypso env if set. - if ( getenv( 'CALYPSO_ENV' ) ) { - $url = add_query_arg( array( 'calypso_env' => getenv( 'CALYPSO_ENV' ) ), $url ); + $calypso_env = Jetpack::get_calypso_env(); + if ( ! empty( $calypso_env ) ) { + $url = add_query_arg( array( 'calypso_env' => $calypso_env ), $url ); } - $result = Jetpack_Client::_wp_remote_request( $url, $request ); + $result = Client::_wp_remote_request( $url, $request ); if ( is_wp_error( $result ) ) { return $result; @@ -224,7 +221,7 @@ class Jetpack_Provision { //phpcs:ignore private static function authorize_user( $user_id, $access_token ) { // authorize user and enable SSO - Jetpack::update_user_token( $user_id, sprintf( '%s.%d', $access_token, $user_id ), true ); + Connection_Utils::update_user_token( $user_id, sprintf( '%s.%d', $access_token, $user_id ), true ); /** * Auto-enable SSO module for new Jetpack Start connections @@ -257,7 +254,7 @@ class Jetpack_Provision { //phpcs:ignore ); $url = sprintf( 'https://%s/rest/v1.3/jpphp/partner-keys/verify', self::get_api_host() ); - $result = Jetpack_Client::_wp_remote_request( $url, $request ); + $result = Client::_wp_remote_request( $url, $request ); if ( is_wp_error( $result ) ) { return $result; @@ -278,7 +275,7 @@ class Jetpack_Provision { //phpcs:ignore } private static function get_api_host() { - $env_api_host = getenv( 'JETPACK_START_API_HOST', true ); + $env_api_host = getenv( 'JETPACK_START_API_HOST', true ); // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctionParameters.getenv_local_onlyFound return $env_api_host ? $env_api_host : JETPACK__WPCOM_JSON_API_HOST; } } |