diff options
Diffstat (limited to 'plugins/jetpack/jetpack_vendor/automattic/jetpack-connection/src/class-rest-connector.php')
-rw-r--r-- | plugins/jetpack/jetpack_vendor/automattic/jetpack-connection/src/class-rest-connector.php | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/plugins/jetpack/jetpack_vendor/automattic/jetpack-connection/src/class-rest-connector.php b/plugins/jetpack/jetpack_vendor/automattic/jetpack-connection/src/class-rest-connector.php index c327d7df..a348d0c6 100644 --- a/plugins/jetpack/jetpack_vendor/automattic/jetpack-connection/src/class-rest-connector.php +++ b/plugins/jetpack/jetpack_vendor/automattic/jetpack-connection/src/class-rest-connector.php @@ -145,7 +145,7 @@ class REST_Connector { '/connection/plugins', array( 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_connection_plugins' ), + 'callback' => array( __CLASS__, 'get_connection_plugins' ), 'permission_callback' => __CLASS__ . '::connection_plugins_permission_check', ) ); @@ -179,10 +179,6 @@ class REST_Connector { 'type' => 'string', 'required' => true, ), - 'no_iframe' => array( - 'description' => __( 'Disable In-Place connection flow and go straight to Calypso', 'jetpack-connection' ), - 'type' => 'boolean', - ), 'redirect_uri' => array( 'description' => __( 'URI of the admin page where the user should be redirected after connection flow', 'jetpack-connection' ), 'type' => 'string', @@ -204,10 +200,6 @@ class REST_Connector { 'callback' => array( $this, 'connection_authorize_url' ), 'permission_callback' => __CLASS__ . '::user_connection_data_permission_check', 'args' => array( - 'no_iframe' => array( - 'description' => __( 'Disable In-Place connection flow and go straight to Calypso', 'jetpack-connection' ), - 'type' => 'boolean', - ), 'redirect_uri' => array( 'description' => __( 'URI of the admin page where the user should be redirected after connection flow', 'jetpack-connection' ), 'type' => 'string', @@ -323,7 +315,7 @@ class REST_Connector { 'filter' => ( apply_filters( 'jetpack_development_mode', false ) || apply_filters( 'jetpack_offline_mode', false ) ), // jetpack_development_mode is deprecated. 'wpLocalConstant' => defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV, ), - 'isPublic' => '1' == get_option( 'blog_public' ), // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison + 'isPublic' => '1' == get_option( 'blog_public' ), // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual ); /** @@ -347,12 +339,15 @@ class REST_Connector { /** * Get plugins connected to the Jetpack. * + * @param bool $rest_response Should we return a rest response or a simple array. Default to rest response. + * * @since 1.13.1 + * @since 1.38.0 Added $rest_response param. * * @return WP_REST_Response|WP_Error Response or error object, depending on the request result. */ - public function get_connection_plugins() { - $plugins = $this->connection->get_connected_plugins(); + public static function get_connection_plugins( $rest_response = true ) { + $plugins = ( new Manager() )->get_connected_plugins(); if ( is_wp_error( $plugins ) ) { return $plugins; @@ -365,7 +360,12 @@ class REST_Connector { } ); - return rest_ensure_response( array_values( $plugins ) ); + if ( $rest_response ) { + return rest_ensure_response( array_values( $plugins ) ); + } + + return array_values( $plugins ); + } /** @@ -425,11 +425,13 @@ class REST_Connector { * Information about the master/primary user. * Information about the current user. * + * @param bool $rest_response Should we return a rest response or a simple array. Default to rest response. + * * @since 1.30.1 * - * @return \WP_REST_Response + * @return \WP_REST_Response|array */ - public static function get_user_connection_data() { + public static function get_user_connection_data( $rest_response = true ) { $connection = new Manager(); $current_user = wp_get_current_user(); @@ -484,7 +486,13 @@ class REST_Connector { 'currentUser' => $current_user_connection_data, 'connectionOwner' => $owner_display_name, ); - return rest_ensure_response( $response ); + + if ( $rest_response ) { + return rest_ensure_response( $response ); + } + + return $response; + } /** @@ -523,13 +531,13 @@ class REST_Connector { return false; } - $signature = base64_decode( $_GET['signature'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode + $signature = base64_decode( filter_var( wp_unslash( $_GET['signature'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode $signature_data = wp_json_encode( array( - 'rest_route' => $_GET['rest_route'], + 'rest_route' => filter_var( wp_unslash( $_GET['rest_route'] ) ), 'timestamp' => (int) $_GET['timestamp'], - 'url' => wp_unslash( $_GET['url'] ), + 'url' => filter_var( wp_unslash( $_GET['url'] ) ), ) ); @@ -668,17 +676,9 @@ class REST_Connector { $redirect_uri = $request->get_param( 'redirect_uri' ) ? admin_url( $request->get_param( 'redirect_uri' ) ) : null; if ( class_exists( 'Jetpack' ) ) { - $authorize_url = \Jetpack::build_authorize_url( $redirect_uri, ! $request->get_param( 'no_iframe' ) ); + $authorize_url = \Jetpack::build_authorize_url( $redirect_uri ); } else { - if ( ! $request->get_param( 'no_iframe' ) ) { - add_filter( 'jetpack_use_iframe_authorization_flow', '__return_true' ); - } - $authorize_url = $this->connection->get_authorization_url( null, $redirect_uri ); - - if ( ! $request->get_param( 'no_iframe' ) ) { - remove_filter( 'jetpack_use_iframe_authorization_flow', '__return_true' ); - } } /** @@ -711,18 +711,9 @@ class REST_Connector { * @return \WP_REST_Response|WP_Error */ public function connection_authorize_url( $request ) { - $redirect_uri = $request->get_param( 'redirect_uri' ) ? admin_url( $request->get_param( 'redirect_uri' ) ) : null; - - if ( ! $request->get_param( 'no_iframe' ) ) { - add_filter( 'jetpack_use_iframe_authorization_flow', '__return_true' ); - } - + $redirect_uri = $request->get_param( 'redirect_uri' ) ? admin_url( $request->get_param( 'redirect_uri' ) ) : null; $authorize_url = $this->connection->get_authorization_url( null, $redirect_uri ); - if ( ! $request->get_param( 'no_iframe' ) ) { - remove_filter( 'jetpack_use_iframe_authorization_flow', '__return_true' ); - } - return rest_ensure_response( array( 'authorizeUrl' => $authorize_url, |