From 3dd572ef0cca21cc5e03800efc8788a98fa66339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Su=C3=A1rez?= Date: Tue, 25 Jan 2022 10:15:22 -0300 Subject: [PATCH] My Jetpack: check user connectivity before hitting wpcom side (#22478) * my-jetpack: check user connectivity before to hit wpcom * changelog --- ...e-my-jetpack-check-connectivity-when-requesting | 4 ++++ .../my-jetpack/src/class-rest-purchases.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 projects/packages/my-jetpack/changelog/update-my-jetpack-check-connectivity-when-requesting diff --git a/projects/packages/my-jetpack/changelog/update-my-jetpack-check-connectivity-when-requesting b/projects/packages/my-jetpack/changelog/update-my-jetpack-check-connectivity-when-requesting new file mode 100644 index 0000000000000..3f963f39d18bb --- /dev/null +++ b/projects/packages/my-jetpack/changelog/update-my-jetpack-check-connectivity-when-requesting @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +My Jetpack: check user connectivity before to hit wpcom side diff --git a/projects/packages/my-jetpack/src/class-rest-purchases.php b/projects/packages/my-jetpack/src/class-rest-purchases.php index 3439c4f8da78d..e01089e45238e 100644 --- a/projects/packages/my-jetpack/src/class-rest-purchases.php +++ b/projects/packages/my-jetpack/src/class-rest-purchases.php @@ -8,6 +8,7 @@ namespace Automattic\Jetpack\My_Jetpack; use Automattic\Jetpack\Connection\Client as Client; +use Automattic\Jetpack\Connection\Manager as Connection_Manager; /** * Registers the REST routes for Purchases. @@ -37,6 +38,19 @@ public function __construct() { * @return true|WP_Error */ public static function permissions_callback() { + $connection = new Connection_Manager(); + $is_user_connected = $connection->is_connected(); + + if ( ! $is_user_connected ) { + return new \WP_Error( + 'not_connected', + __( 'You are not connected to Jetpack.', 'jetpack-my-jetpack' ), + array( + 'status' => 400, + ) + ); + } + return current_user_can( 'manage_options' ); }