diff options
Diffstat (limited to 'plugins/jetpack/class.jetpack-cli.php')
-rw-r--r-- | plugins/jetpack/class.jetpack-cli.php | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/plugins/jetpack/class.jetpack-cli.php b/plugins/jetpack/class.jetpack-cli.php index df84021a..73da5d05 100644 --- a/plugins/jetpack/class.jetpack-cli.php +++ b/plugins/jetpack/class.jetpack-cli.php @@ -241,7 +241,7 @@ class Jetpack_CLI extends WP_CLI_Command { switch ( $action ) { case 'options': - $options_to_reset = Jetpack::get_jetpack_options_for_reset(); + $options_to_reset = Jetpack_Options::get_options_for_reset(); // Reset the Jetpack options _e( "Resetting Jetpack Options...\n", "jetpack" ); @@ -415,7 +415,7 @@ class Jetpack_CLI extends WP_CLI_Command { case 'whitelist': $whitelist = array(); $new_ip = $args[1]; - $current_whitelist = get_site_option( 'jetpack_protect_whitelist' ); + $current_whitelist = get_site_option( 'jetpack_protect_whitelist', array() ); // Build array of IPs that are already whitelisted. // Re-build manually instead of using jetpack_protect_format_whitelist() so we can easily get @@ -522,7 +522,7 @@ class Jetpack_CLI extends WP_CLI_Command { */ public function options( $args, $assoc_args ) { $action = isset( $args[0] ) ? $args[0] : 'list'; - $safe_to_modify = Jetpack::get_jetpack_options_for_reset(); + $safe_to_modify = Jetpack_Options::get_options_for_reset(); // Jumpstart is special array_push( $safe_to_modify, 'jumpstart' ); @@ -831,10 +831,10 @@ class Jetpack_CLI extends WP_CLI_Command { $this->partner_provision_error( new WP_Error( 'missing_access_token', __( 'Missing or invalid access token', 'jetpack' ) ) ); } - $blog_id = Jetpack_Options::get_option( 'id' ); + $site_identifier = Jetpack_Options::get_option( 'id' ); - if ( ! $blog_id ) { - $this->partner_provision_error( new WP_Error( 'site_not_registered', __( 'This site is not connected to Jetpack', 'jetpack' ) ) ); + if ( ! $site_identifier ) { + $site_identifier = Jetpack::build_raw_urls( get_home_url() ); } $request = array( @@ -844,18 +844,19 @@ class Jetpack_CLI extends WP_CLI_Command { ), 'timeout' => 60, 'method' => 'POST', - 'body' => json_encode( array( 'site_id' => $blog_id ) ) ); - $url = sprintf( 'https://%s/rest/v1.3/jpphp/%d/partner-cancel', $this->get_api_host(), $blog_id ); + $url = sprintf( 'https://%s/rest/v1.3/jpphp/%s/partner-cancel', $this->get_api_host(), $site_identifier ); $result = Jetpack_Client::_wp_remote_request( $url, $request ); + Jetpack_Options::delete_option( 'onboarding' ); + if ( is_wp_error( $result ) ) { $this->partner_provision_error( $result ); } - WP_CLI::log( json_encode( $result ) ); + WP_CLI::log( wp_remote_retrieve_body( $result ) ); } /** @@ -931,8 +932,10 @@ class Jetpack_CLI extends WP_CLI_Command { ? get_site_icon_url() : false; + $auto_enable_sso = ( ! Jetpack::is_active() || Jetpack::is_module_active( 'sso' ) ); + /** This filter is documented in class.jetpack-cli.php */ - if ( apply_filters( 'jetpack_start_enable_sso', true ) ) { + if ( apply_filters( 'jetpack_start_enable_sso', $auto_enable_sso ) ) { $redirect_uri = add_query_arg( array( 'action' => 'jetpack-sso', 'redirect_to' => urlencode( admin_url() ) ), wp_login_url() // TODO: come back to Jetpack dashboard? @@ -941,7 +944,7 @@ class Jetpack_CLI extends WP_CLI_Command { $redirect_uri = admin_url(); } - $request_body = array( + $request_body = array( 'jp_version' => JETPACK__VERSION, 'redirect_uri' => $redirect_uri ); @@ -986,6 +989,10 @@ class Jetpack_CLI extends WP_CLI_Command { $request_body['force_connect'] = intval( $named_args['force_connect'] ); } + if ( isset( $request_body['onboarding'] ) && (bool) $request_body['onboarding'] ) { + Jetpack::create_onboarding_token(); + } + $request = array( 'headers' => array( 'Authorization' => "Bearer " . $token->access_token, @@ -1007,8 +1014,8 @@ class Jetpack_CLI extends WP_CLI_Command { if ( is_wp_error( $result ) ) { $this->partner_provision_error( $result ); - } - + } + $response_code = wp_remote_retrieve_response_code( $result ); $body_json = json_decode( wp_remote_retrieve_body( $result ) ); @@ -1016,7 +1023,7 @@ class Jetpack_CLI extends WP_CLI_Command { if ( isset( $body_json->error ) ) { $this->partner_provision_error( new WP_Error( $body_json->error, $body_json->message ) ); } else { - $this->partner_provision_error( new WP_Error( 'server_error', sprintf( __( "Request failed with code %s" ), $response_code ) ) ); + $this->partner_provision_error( new WP_Error( 'server_error', sprintf( __( "Request failed with code %s", 'jetpack' ), $response_code ) ) ); } } @@ -1024,13 +1031,6 @@ class Jetpack_CLI extends WP_CLI_Command { // authorize user and enable SSO Jetpack::update_user_token( $user->ID, sprintf( '%s.%d', $body_json->access_token, $user->ID ), true ); - if ( $active_modules = Jetpack_Options::get_option( 'active_modules' ) ) { - Jetpack::delete_active_modules(); - Jetpack::activate_default_modules( 999, 1, $active_modules, false ); - } else { - Jetpack::activate_default_modules( false, false, array(), false ); - } - /** * Auto-enable SSO module for new Jetpack Start connections * @@ -1038,8 +1038,15 @@ class Jetpack_CLI extends WP_CLI_Command { * * @param bool $enable_sso Whether to enable the SSO module. Default to true. */ - if ( apply_filters( 'jetpack_start_enable_sso', true ) ) { - Jetpack::activate_module( 'sso', false, false ); + $other_modules = apply_filters( 'jetpack_start_enable_sso', true ) + ? array( 'sso' ) + : array(); + + if ( $active_modules = Jetpack_Options::get_option( 'active_modules' ) ) { + Jetpack::delete_active_modules(); + Jetpack::activate_default_modules( 999, 1, array_merge( $active_modules, $other_modules ), false ); + } else { + Jetpack::activate_default_modules( false, false, $other_modules, false ); } } |