diff options
Diffstat (limited to 'plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php')
-rw-r--r-- | plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php | 524 |
1 files changed, 302 insertions, 222 deletions
diff --git a/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php b/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php index a0f0bf44..30a53865 100644 --- a/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php +++ b/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php @@ -1,4 +1,11 @@ <?php + +use Automattic\Jetpack\Connection\Client; +use Automattic\Jetpack\Connection\Manager as Connection_Manager; +use Automattic\Jetpack\JITM; +use Automattic\Jetpack\Tracking; +use Automattic\Jetpack\Status; + /** * Register WP REST API endpoints for Jetpack. * @@ -61,7 +68,6 @@ class Jetpack_Core_Json_Api_Endpoints { self::$stats_roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ); - Jetpack::load_xml_rpc_client(); $ixr_client = new Jetpack_IXR_Client( array( 'user_id' => get_current_user_id() ) ); $core_api_endpoint = new Jetpack_Core_API_Data( $ixr_client ); $module_list_endpoint = new Jetpack_Core_API_Module_List_Endpoint(); @@ -74,7 +80,18 @@ class Jetpack_Core_Json_Api_Endpoints { 'methods' => WP_REST_Server::READABLE, 'callback' => __CLASS__ . '::get_plans', 'permission_callback' => __CLASS__ . '::connect_url_permission_callback', + ) ); + register_rest_route( 'jetpack/v4', 'products', array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => __CLASS__ . '::get_products', + 'permission_callback' => __CLASS__ . '::connect_url_permission_callback', + ) ); + + register_rest_route( 'jetpack/v4', 'marketing/survey', array( + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => __CLASS__ . '::submit_survey', + 'permission_callback' => __CLASS__ . '::disconnect_site_permission_callback', ) ); register_rest_route( 'jetpack/v4', '/jitm', array( @@ -87,12 +104,6 @@ class Jetpack_Core_Json_Api_Endpoints { 'callback' => __CLASS__ . '::delete_jitm_message' ) ); - // Register a site - register_rest_route( 'jetpack/v4', '/verify_registration', array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => __CLASS__ . '::verify_registration', - ) ); - // Authorize a remote user register_rest_route( 'jetpack/v4', '/remote_authorize', array( 'methods' => WP_REST_Server::EDITABLE, @@ -139,6 +150,16 @@ class Jetpack_Core_Json_Api_Endpoints { 'permission_callback' => __CLASS__ . '::get_user_connection_data_permission_callback', ) ); + // Start the connection process by registering the site on WordPress.com servers. + register_rest_route( 'jetpack/v4', '/connection/register', array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => __CLASS__ . '::register_site', + 'permission_callback' => __CLASS__ . '::connect_url_permission_callback', + 'args' => array( + 'registration_nonce' => array( 'type' => 'string' ), + ), + ) ); + // Set the connection owner register_rest_route( 'jetpack/v4', '/connection/owner', array( 'methods' => WP_REST_Server::EDITABLE, @@ -191,6 +212,31 @@ class Jetpack_Core_Json_Api_Endpoints { 'permission_callback' => array( $site_endpoint , 'can_request' ), ) ); + // Get current site purchases. + register_rest_route( + 'jetpack/v4', + '/site/purchases', + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $site_endpoint, 'get_purchases' ), + 'permission_callback' => array( $site_endpoint, 'can_request' ), + ) + ); + + // Get current site benefits + register_rest_route( 'jetpack/v4', '/site/benefits', array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $site_endpoint, 'get_benefits' ), + 'permission_callback' => array( $site_endpoint, 'can_request' ), + ) ); + + // Get Activity Log data for this site. + register_rest_route( 'jetpack/v4', '/site/activity', array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => __CLASS__ . '::get_site_activity', + 'permission_callback' => __CLASS__ . '::manage_modules_permission_check', + ) ); + // Confirm that a site in identity crisis should be in staging mode register_rest_route( 'jetpack/v4', '/identity-crisis/confirm-safe-mode', array( 'methods' => WP_REST_Server::EDITABLE, @@ -341,26 +387,6 @@ class Jetpack_Core_Json_Api_Endpoints { 'permission_callback' => __CLASS__ . '::manage_modules_permission_check', ) ); - // Return current Jumpstart status - register_rest_route( 'jetpack/v4', '/jumpstart', array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => __CLASS__ . '::jumpstart_status', - 'permission_callback' => __CLASS__ . '::update_settings_permission_check', - ) ); - - // Update Jumpstart - register_rest_route( 'jetpack/v4', '/jumpstart', array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => __CLASS__ . '::jumpstart_toggle', - 'permission_callback' => __CLASS__ . '::manage_modules_permission_check', - 'args' => array( - 'active' => array( - 'required' => true, - 'validate_callback' => __CLASS__ . '::validate_boolean', - ), - ), - ) ); - // Updates: get number of plugin updates available register_rest_route( 'jetpack/v4', '/updates/plugins', array( 'methods' => WP_REST_Server::READABLE, @@ -382,6 +408,12 @@ class Jetpack_Core_Json_Api_Endpoints { 'permission_callback' => __CLASS__ . '::activate_plugins_permission_check', ) ); + register_rest_route( 'jetpack/v4', '/plugins/akismet/activate', array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => __CLASS__ . '::activate_akismet', + 'permission_callback' => __CLASS__ . '::activate_plugins_permission_check', + ) ); + // Plugins: check if the plugin is active. register_rest_route( 'jetpack/v4', '/plugin/(?P<plugin>[a-z\/\.\-_]+)', array( 'methods' => WP_REST_Server::READABLE, @@ -452,10 +484,20 @@ class Jetpack_Core_Json_Api_Endpoints { ), ) ); + + register_rest_route( + 'jetpack/v4', + '/mobile/send-login-email', + array( + 'methods' => WP_REST_Server::EDITABLE, + 'callback' => __CLASS__ . '::send_mobile_magic_link', + 'permission_callback' => __CLASS__ . '::view_admin_page_permission_check', + ) + ); } public static function get_plans( $request ) { - $request = Jetpack_Client::wpcom_json_api_request_as_user( + $request = Client::wpcom_json_api_request_as_user( '/plans?_locale=' . get_user_locale(), '2', array( @@ -466,7 +508,7 @@ class Jetpack_Core_Json_Api_Endpoints { ) ); - $body = wp_remote_retrieve_body( $request ); + $body = json_decode( wp_remote_retrieve_body( $request ) ); if ( 200 === wp_remote_retrieve_response_code( $request ) ) { $data = $body; } else { @@ -478,6 +520,65 @@ class Jetpack_Core_Json_Api_Endpoints { } /** + * Gets the WP.com products that are in use on wpcom. + * Similar to the WP.com plans that we currently in user on WPCOM. + * + * @param WP_REST_Request $request The request. + * + * @return string|WP_Error A JSON object of wpcom products if the request was successful, or a WP_Error otherwise. + */ + public static function get_products( $request ) { + $wpcom_request = Client::wpcom_json_api_request_as_user( + '/products?_locale=' . get_user_locale() . '&type=jetpack', + '2', + array( + 'method' => 'GET', + 'headers' => array( + 'X-Forwarded-For' => Jetpack::current_user_ip( true ), + ), + ) + ); + + $response_code = wp_remote_retrieve_response_code( $wpcom_request ); + if ( 200 === $response_code ) { + return json_decode( wp_remote_retrieve_body( $wpcom_request ) ); + } else { + // Something went wrong so we'll just return the response without caching. + return new WP_Error( + 'failed_to_fetch_data', + esc_html__( 'Unable to fetch the requested data.', 'jetpack' ), + array( 'status' => $response_code ) + ); + } + } + + public static function submit_survey( $request ) { + + $wpcom_request = Client::wpcom_json_api_request_as_user( + '/marketing/survey', + 'v2', + array( + 'method' => 'POST', + 'headers' => array( + 'Content-Type' => 'application/json', + 'X-Forwarded-For' => Jetpack::current_user_ip( true ), + ), + ), + $request->get_json_params() + ); + + $wpcom_request_body = json_decode( wp_remote_retrieve_body( $wpcom_request ) ); + if ( 200 === wp_remote_retrieve_response_code( $wpcom_request ) ) { + $data = $wpcom_request_body; + } else { + // something went wrong so we'll just return the response without caching + return $wpcom_request_body; + } + + return $data; + } + + /** * Asks for a jitm, unless they've been disabled, in which case it returns an empty array * * @param $request WP_REST_Request @@ -485,11 +586,9 @@ class Jetpack_Core_Json_Api_Endpoints { * @return array An array of jitms */ public static function get_jitm_message( $request ) { - require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-jitm.php' ); - - $jitm = Jetpack_JITM::init(); + $jitm = new JITM(); - if ( ! $jitm ) { + if ( ! $jitm->register() ) { return array(); } @@ -503,11 +602,9 @@ class Jetpack_Core_Json_Api_Endpoints { * @return bool Always True */ public static function delete_jitm_message( $request ) { - require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-jitm.php' ); + $jitm = new JITM(); - $jitm = Jetpack_JITM::init(); - - if ( ! $jitm ) { + if ( ! $jitm->register() ) { return true; } @@ -515,28 +612,6 @@ class Jetpack_Core_Json_Api_Endpoints { } /** - * Handles verification that a site is registered - * - * @since 5.4.0 - * - * @param WP_REST_Request $request The request sent to the WP REST API. - * - * @return array|wp-error - */ - public static function verify_registration( $request ) { - require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; - $xmlrpc_server = new Jetpack_XMLRPC_Server(); - $result = $xmlrpc_server->verify_registration( array( $request['secret_1'], $request['state'] ) ); - - if ( is_a( $result, 'IXR_Error' ) ) { - $result = new WP_Error( $result->code, $result->message ); - } - - return $result; - } - - - /** * Checks if this site has been verified using a service - only 'google' supported at present - and a specfic * keyring to use to get the token if it is not * @@ -586,7 +661,6 @@ class Jetpack_Core_Json_Api_Endpoints { return new WP_Error( 'forbidden', __( 'Site is under construction and cannot be verified', 'jetpack' ) ); } - Jetpack::load_xml_rpc_client(); $xml = new Jetpack_IXR_Client( array( 'user_id' => get_current_user_id(), ) ); @@ -612,7 +686,6 @@ class Jetpack_Core_Json_Api_Endpoints { public static function verify_site( $request ) { - Jetpack::load_xml_rpc_client(); $xml = new Jetpack_IXR_Client( array( 'user_id' => get_current_user_id(), ) ); @@ -651,7 +724,6 @@ class Jetpack_Core_Json_Api_Endpoints { * @return array|wp-error */ public static function remote_authorize( $request ) { - require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php'; $xmlrpc_server = new Jetpack_XMLRPC_Server(); $result = $xmlrpc_server->remote_authorize( $request ); @@ -723,7 +795,7 @@ class Jetpack_Core_Json_Api_Endpoints { return true; } - return new WP_Error( 'invalid_user_permission_jetpack_disconnect', self::$user_permissions_error_msg, array( 'status' => self::rest_authorization_required_code() ) ); + return new WP_Error( 'invalid_user_permission_jetpack_connect', self::$user_permissions_error_msg, array( 'status' => self::rest_authorization_required_code() ) ); } @@ -749,11 +821,12 @@ class Jetpack_Core_Json_Api_Endpoints { * Check that user has permission to change the master user. * * @since 6.2.0 + * @since 7.7.0 Update so that any user with jetpack_disconnect privs can set owner. * * @return bool|WP_Error True if user is able to change master user. */ public static function set_connection_owner_permission_callback() { - if ( get_current_user_id() === Jetpack_Options::get_option( 'master_user' ) ) { + if ( current_user_can( 'jetpack_disconnect' ) ) { return true; } @@ -903,10 +976,11 @@ class Jetpack_Core_Json_Api_Endpoints { */ public static function jetpack_connection_status() { return rest_ensure_response( array( - 'isActive' => Jetpack::is_active(), - 'isStaging' => Jetpack::is_staging_site(), - 'devMode' => array( - 'isActive' => Jetpack::is_development_mode(), + 'isActive' => Jetpack::is_active(), + 'isStaging' => Jetpack::is_staging_site(), + 'isRegistered' => Jetpack::connection()->is_registered(), + 'devMode' => array( + 'isActive' => ( new Status() )->is_development_mode(), 'constant' => defined( 'JETPACK_DEV_DEBUG' ) && JETPACK_DEV_DEBUG, 'url' => site_url() && false === strpos( site_url(), '.' ), 'filter' => apply_filters( 'jetpack_development_mode', false ), @@ -1050,7 +1124,7 @@ class Jetpack_Core_Json_Api_Endpoints { return new WP_Error( 'site_id_missing' ); } - $response = Jetpack_Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d/rewind', $site_id ) .'?force=wpcom', '2', array(), null, 'wpcom' ); + $response = Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d/rewind', $site_id ) .'?force=wpcom', '2', array(), null, 'wpcom' ); if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { return new WP_Error( 'rewind_data_fetch_failed' ); @@ -1120,6 +1194,33 @@ class Jetpack_Core_Json_Api_Endpoints { } /** + * Registers the Jetpack site + * + * @uses Jetpack::try_registration(); + * @since 7.7.0 + * + * @param WP_REST_Request $request The request sent to the WP REST API. + * + * @return bool|WP_Error True if Jetpack successfully registered + */ + public static function register_site( $request ) { + if ( ! wp_verify_nonce( $request->get_param( 'registration_nonce' ), 'jetpack-registration-nonce' ) ) { + return new WP_Error( 'invalid_nonce', __( 'Unable to verify your request.', 'jetpack' ), array( 'status' => 403 ) ); + } + + $response = Jetpack::try_registration(); + + if ( is_wp_error( $response ) ) { + return $response; + } + + return rest_ensure_response( + array( + 'authorizeUrl' => Jetpack::build_authorize_url( false, true ) + ) ); + } + + /** * Gets a new connect raw URL with fresh nonce. * * @uses Jetpack::disconnect(); @@ -1206,7 +1307,6 @@ class Jetpack_Core_Json_Api_Endpoints { $updated = Jetpack_Options::update_option( 'master_user', $new_owner_id ); // Notify WPCOM about the master user change - Jetpack::load_xml_rpc_client(); $xml = new Jetpack_IXR_Client( array( 'user_id' => get_current_user_id(), ) ); @@ -1215,6 +1315,13 @@ class Jetpack_Core_Json_Api_Endpoints { ) ); if ( $updated && ! $xml->isError() ) { + + // Track it + if ( class_exists( 'Automattic\Jetpack\Tracking' ) ) { + $tracking = new Tracking(); + $tracking->record_user_event( 'set_connection_owner_success' ); + } + return rest_ensure_response( array( 'code' => 'success', @@ -1232,7 +1339,7 @@ class Jetpack_Core_Json_Api_Endpoints { * Unlinks current user from the WordPress.com Servers. * * @since 4.3.0 - * @uses Jetpack::unlink_user + * @uses Automattic\Jetpack\Connection\Manager::disconnect_user * * @param WP_REST_Request $request The request sent to the WP REST API. * @@ -1244,7 +1351,7 @@ class Jetpack_Core_Json_Api_Endpoints { return new WP_Error( 'invalid_param', esc_html__( 'Invalid Parameter', 'jetpack' ), array( 'status' => 404 ) ); } - if ( Jetpack::unlink_user() ) { + if ( Connection_Manager::disconnect_user() ) { return rest_ensure_response( array( 'code' => 'success' @@ -1270,7 +1377,7 @@ class Jetpack_Core_Json_Api_Endpoints { 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. ); } else { - $response = Jetpack_Client::wpcom_json_api_request_as_user( + $response = Client::wpcom_json_api_request_as_user( '/jetpack-user-tracking', 'v2', array( @@ -1303,7 +1410,7 @@ class Jetpack_Core_Json_Api_Endpoints { 'tracks_opt_out' => true, // Default to opt-out if not connected to wp.com. ); } else { - $response = Jetpack_Client::wpcom_json_api_request_as_user( + $response = Client::wpcom_json_api_request_as_user( '/jetpack-user-tracking', 'v2', array( @@ -1334,10 +1441,18 @@ class Jetpack_Core_Json_Api_Endpoints { $site_id = Jetpack_Options::get_option( 'id' ); if ( ! $site_id ) { - new WP_Error( 'site_id_missing' ); + new WP_Error( 'site_id_missing' ); + } + + $args = array( 'headers' => array() ); + + // Allow use a store sandbox. Internal ref: PCYsg-IA-p2. + if ( isset( $_COOKIE ) && isset( $_COOKIE['store_sandbox'] ) ) { + $secret = $_COOKIE['store_sandbox']; + $args['headers']['Cookie'] = "store_sandbox=$secret;"; } - $response = Jetpack_Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d', $site_id ) .'?force=wpcom', '1.1' ); + $response = Client::wpcom_json_api_request_as_blog( sprintf( '/sites/%d', $site_id ) .'?force=wpcom', '1.1', $args ); if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { return new WP_Error( 'site_data_fetch_failed' ); @@ -1377,6 +1492,57 @@ class Jetpack_Core_Json_Api_Endpoints { } /** + * Fetch AL data for this site and return it. + * + * @since 7.4 + * + * @return array|WP_Error + */ + public static function get_site_activity() { + $site_id = Jetpack_Options::get_option( 'id' ); + + if ( ! $site_id ) { + return new WP_Error( + 'site_id_missing', + esc_html__( 'Site ID is missing.', 'jetpack' ), + array( 'status' => 400 ) + ); + } + + $response = Client::wpcom_json_api_request_as_user( "/sites/$site_id/activity", '2', array( + 'method' => 'GET', + 'headers' => array( + 'X-Forwarded-For' => Jetpack::current_user_ip( true ), + ), + ), null, 'wpcom' ); + $response_code = wp_remote_retrieve_response_code( $response ); + + if ( 200 !== $response_code ) { + return new WP_Error( + 'activity_fetch_failed', + esc_html__( 'Could not retrieve site activity.', 'jetpack' ), + array( 'status' => $response_code ) + ); + } + + $data = json_decode( wp_remote_retrieve_body( $response ) ); + + if ( ! isset( $data->current->orderedItems ) ) { + return new WP_Error( + 'activity_not_found', + esc_html__( 'No activity found', 'jetpack' ), + array( 'status' => 204 ) // no content + ); + } + + return rest_ensure_response( array( + 'code' => 'success', + 'data' => $data->current->orderedItems, + ) + ); + } + + /** * Handles identity crisis mitigation, confirming safe mode for this site. * * @since 4.4.0 @@ -1484,8 +1650,6 @@ class Jetpack_Core_Json_Api_Endpoints { $default_modules = Jetpack::get_default_modules(); Jetpack::update_active_modules( $default_modules ); - // Jumpstart option is special - Jetpack_Options::update_option( 'jumpstart', 'new_connection' ); return rest_ensure_response( array( 'code' => 'success', 'message' => esc_html__( 'Jetpack options reset.', 'jetpack' ), @@ -1510,148 +1674,6 @@ class Jetpack_Core_Json_Api_Endpoints { } /** - * Retrieves the current status of Jumpstart. - * - * @since 4.5.0 - * - * @return bool - */ - public static function jumpstart_status() { - return array( - 'status' => Jetpack_Options::get_option( 'jumpstart' ) - ); - } - - /** - * Toggles activation or deactivation of the JumpStart - * - * @since 4.3.0 - * - * @param WP_REST_Request $request The request sent to the WP REST API. - * - * @return bool|WP_Error True if toggling Jumpstart succeeded. Otherwise, a WP_Error instance with the corresponding error. - */ - public static function jumpstart_toggle( $request ) { - - if ( $request[ 'active' ] ) { - return self::jumpstart_activate( $request ); - } else { - return self::jumpstart_deactivate( $request ); - } - } - - /** - * Activates a series of valid Jetpack modules and initializes some options. - * - * @since 4.3.0 - * - * @param WP_REST_Request $request The request sent to the WP REST API. - * - * @return bool|WP_Error True if Jumpstart succeeded. Otherwise, a WP_Error instance with the corresponding error. - */ - public static function jumpstart_activate( $request ) { - $modules = Jetpack::get_available_modules(); - $activate_modules = array(); - foreach ( $modules as $module ) { - $module_info = Jetpack::get_module( $module ); - if ( isset( $module_info['feature'] ) && is_array( $module_info['feature'] ) && in_array( 'Jumpstart', $module_info['feature'] ) ) { - $activate_modules[] = $module; - } - } - - // Collect success/error messages like modules that are properly activated. - $result = array( - 'activated_modules' => array(), - 'failed_modules' => array(), - ); - - // Update the jumpstart option - if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { - $result['jumpstart_activated'] = Jetpack_Options::update_option( 'jumpstart', 'jumpstart_activated' ); - } - - // Check for possible conflicting plugins - $module_slugs_filtered = Jetpack::init()->filter_default_modules( $activate_modules ); - - foreach ( $module_slugs_filtered as $module_slug ) { - Jetpack::log( 'activate', $module_slug ); - if ( Jetpack::activate_module( $module_slug, false, false ) ) { - $result['activated_modules'][] = $module_slug; - } else { - $result['failed_modules'][] = $module_slug; - } - } - - // Set the default sharing buttons and set to display on posts if none have been set. - $sharing_services = get_option( 'sharing-services' ); - $sharing_options = get_option( 'sharing-options' ); - if ( empty( $sharing_services['visible'] ) ) { - // Default buttons to set - $visible = array( - 'twitter', - 'facebook', - ); - $hidden = array(); - - // Set some sharing settings - if ( class_exists( 'Sharing_Service' ) ) { - $sharing = new Sharing_Service(); - $sharing_options['global'] = array( - 'button_style' => 'icon', - 'sharing_label' => $sharing->default_sharing_label, - 'open_links' => 'same', - 'show' => array( 'post' ), - 'custom' => isset( $sharing_options['global']['custom'] ) ? $sharing_options['global']['custom'] : array() - ); - - $result['sharing_options'] = update_option( 'sharing-options', $sharing_options ); - $result['sharing_services'] = update_option( 'sharing-services', array( 'visible' => $visible, 'hidden' => $hidden ) ); - } - } - - // If all Jumpstart modules were activated - if ( empty( $result['failed_modules'] ) ) { - return rest_ensure_response( array( - 'code' => 'success', - 'message' => esc_html__( 'Jumpstart done.', 'jetpack' ), - 'data' => $result, - ) ); - } - - return new WP_Error( 'jumpstart_failed', esc_html( sprintf( _n( 'Jumpstart failed activating this module: %s.', 'Jumpstart failed activating these modules: %s.', count( $result['failed_modules'] ), 'jetpack' ), join( ', ', $result['failed_modules'] ) ) ), array( 'status' => 400 ) ); - } - - /** - * Dismisses Jumpstart so user is not prompted to go through it again. - * - * @since 4.3.0 - * - * @param WP_REST_Request $request The request sent to the WP REST API. - * - * @return bool|WP_Error True if Jumpstart was disabled or was nothing to dismiss. Otherwise, a WP_Error instance with a message. - */ - public static function jumpstart_deactivate( $request ) { - - // If dismissed, flag the jumpstart option as such. - if ( 'new_connection' === Jetpack_Options::get_option( 'jumpstart' ) ) { - if ( Jetpack_Options::update_option( 'jumpstart', 'jumpstart_dismissed' ) ) { - return rest_ensure_response( array( - 'code' => 'success', - 'message' => esc_html__( 'Jumpstart dismissed.', 'jetpack' ), - ) ); - } else { - return new WP_Error( 'jumpstart_failed_dismiss', esc_html__( 'Jumpstart could not be dismissed.', 'jetpack' ), array( 'status' => 400 ) ); - } - } - - // If this was not a new connection and there was nothing to dismiss, don't fail. - return rest_ensure_response( array( - 'code' => 'success', - 'message' => esc_html__( 'Nothing to dismiss. This was not a new connection.', 'jetpack' ), - ) ); - } - - /** * Get the query parameters to update module options or general settings. * * @since 4.3.0 @@ -1705,7 +1727,7 @@ class Jetpack_Core_Json_Api_Endpoints { 'jp_group' => 'carousel', ), 'carousel_display_exif' => array( - 'description' => wp_kses( sprintf( __( 'Show photo metadata (<a href="http://en.wikipedia.org/wiki/Exchangeable_image_file_format" target="_blank">Exif</a>) in carousel, when available.', 'jetpack' ) ), array( 'a' => array( 'href' => true, 'target' => true ) ) ), + 'description' => wp_kses( sprintf( __( 'Show photo metadata (<a href="https://en.wikipedia.org/wiki/Exchangeable_image_file_format" target="_blank">Exif</a>) in carousel, when available.', 'jetpack' ) ), array( 'a' => array( 'href' => true, 'target' => true ) ) ), 'type' => 'boolean', 'default' => 0, 'validate_callback' => __CLASS__ . '::validate_boolean', @@ -2149,7 +2171,7 @@ class Jetpack_Core_Json_Api_Endpoints { // Stats 'admin_bar' => array( - 'description' => esc_html__( 'Put a chart showing 48 hours of views in the admin bar.', 'jetpack' ), + 'description' => esc_html__( 'Include a small chart in your admin bar with a 48-hour traffic snapshot.', 'jetpack' ), 'type' => 'boolean', 'default' => 1, 'validate_callback' => __CLASS__ . '::validate_boolean', @@ -3156,6 +3178,30 @@ class Jetpack_Core_Json_Api_Endpoints { } /** + * Ensures that Akismet is installed and activated. + * + * @since 7.7 + * + * @return WP_REST_Response A response indicating whether or not the installation was successful. + */ + public static function activate_akismet() { + jetpack_require_lib( 'plugins' ); + $result = Jetpack_Plugins::install_and_activate_plugin('akismet'); + + if ( is_wp_error( $result ) ) { + return rest_ensure_response( array( + 'code' => 'failure', + 'message' => esc_html__( 'Unable to activate Akismet', 'jetpack' ) + ) ); + } else { + return rest_ensure_response( array( + 'code' => 'success', + 'message' => esc_html__( 'Activated Akismet', 'jetpack' ) + ) ); + } + } + + /** * Get data about the queried plugin. Currently it only returns whether the plugin is active or not. * * @since 4.2.0 @@ -3193,4 +3239,38 @@ class Jetpack_Core_Json_Api_Endpoints { ) ); } + /** + * Proxies a request to WordPress.com to request that a magic link be sent to the current user + * to log this user in to the mobile app via email. + * + * @param WP_REST_REQUEST $request The request parameters. + * @return bool|WP_Error + */ + public static function send_mobile_magic_link( $request ) { + $xml = new Jetpack_IXR_Client( + array( + 'user_id' => get_current_user_id(), + ) + ); + + $xml->query( 'jetpack.sendMobileMagicLink', array() ); + if ( $xml->isError() ) { + return new WP_Error( + 'error_sending_mobile_magic_link', + sprintf( + '%s: %s', + $xml->getErrorCode(), + $xml->getErrorMessage() + ) + ); + } + + $response = $xml->getResponse(); + + return rest_ensure_response( + array( + 'code' => 'success', + ) + ); + } } // class end |