Skip to content

Commit

Permalink
My Jetpack: check user connectivity before hitting wpcom side (#22478)
Browse files Browse the repository at this point in the history
* my-jetpack: check user connectivity before to hit wpcom

* changelog
  • Loading branch information
retrofox authored Jan 25, 2022
1 parent d281792 commit 3dd572e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

My Jetpack: check user connectivity before to hit wpcom side
14 changes: 14 additions & 0 deletions projects/packages/my-jetpack/src/class-rest-purchases.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' );
}

Expand Down

0 comments on commit 3dd572e

Please sign in to comment.