From b04ac83818ac13f0e69107c2c588006b92515bdb Mon Sep 17 00:00:00 2001 From: Miguel Lezama Date: Thu, 1 Jun 2023 13:28:10 -0300 Subject: [PATCH] [not verified] Use ( new Host() )->is_wpcom_simple() --- ...est-api-v2-endpoint-send-email-preview.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-send-email-preview.php b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-send-email-preview.php index 0dbc332825006..12832c13eddcd 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-send-email-preview.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-send-email-preview.php @@ -6,6 +6,7 @@ */ use Automattic\Jetpack\Connection\Manager; +use Automattic\Jetpack\Status\Host; require_once __DIR__ . '/trait-wpcom-rest-api-proxy-request-trait.php'; @@ -39,11 +40,12 @@ public function __construct() { */ public function register_routes() { $options = array( - 'show_in_index' => true, - 'methods' => 'POST', + 'show_in_index' => true, + 'methods' => 'POST', // if this is not a wpcom site, we need to proxy the request to wpcom - 'callback' => ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? array( $this, 'send_email_preview' ) : array( $this, 'proxy_request_to_wpcom_as_user' ), - 'args' => array( + 'callback' => ( ( new Host() )->is_wpcom_simple() ) ? array( $this, 'send_email_preview' ) : array( $this, 'proxy_request_to_wpcom_as_user' ), + 'permission_callback' => array( $this, 'permissions_check' ), + 'args' => array( 'id' => array( 'description' => __( 'Unique identifier for the post.', 'jetpack' ), 'type' => 'integer', @@ -66,12 +68,14 @@ public function register_routes() { * @return true|WP_Error True if the request has edit access, WP_Error object otherwise. */ public function permissions_check( $request ) { - if ( ! ( new Manager() )->is_user_connected() ) { - return new WP_Error( - 'rest_cannot_send_email_preview', - __( 'Please connect your user account to WordPress.com', 'jetpack' ), - array( 'status' => rest_authorization_required_code() ) - ); + if ( ! ( new Host() )->is_wpcom_simple() ) { + if ( ! ( new Manager() )->is_user_connected() ) { + return new WP_Error( + 'rest_cannot_send_email_preview', + __( 'Please connect your user account to WordPress.com', 'jetpack' ), + array( 'status' => rest_authorization_required_code() ) + ); + } } $post = get_post( $request->get_param( 'id' ) );