Skip to content

Commit b067c71

Browse files
authored
Merge pull request #80 from saucal/bugfix/shop-manager-permissions
Bugfix/shop manager permissions
2 parents 498232a + c5c97ac commit b067c71

8 files changed

Lines changed: 26 additions & 26 deletions

class-pinterest-for-woocommerce.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,12 @@ private function init_hooks() {
195195
add_action( 'init', array( $this, 'verification_rewrite' ) );
196196
add_filter( 'query_vars', array( $this, 'verification_query_var' ), 10, 1 );
197197
add_action( 'parse_request', array( $this, 'verification_request' ), 10, 1 );
198+
199+
// Allow access to our option through the REST API.
200+
add_filter( 'woocommerce_rest_api_option_permissions', array( $this, 'add_option_permissions' ), 10, 1 );
198201
}
199202

203+
200204
/**
201205
* Init Pinterest_For_Woocommerce when WordPress Initialises.
202206
*/
@@ -264,6 +268,21 @@ public function ajax_url() {
264268
}
265269

266270

271+
/**
272+
* Allow access to our option through the REST API for a user that can manage the store.
273+
* The UI relies on this option being available through the API.
274+
*
275+
* @param array $permissions The permissions array.
276+
*
277+
* @return array
278+
*/
279+
public function add_option_permissions( $permissions ) {
280+
281+
$permissions[ PINTEREST_FOR_WOOCOMMERCE_OPTION_NAME ] = current_user_can( 'manage_woocommerce' );
282+
return $permissions;
283+
}
284+
285+
267286
/**
268287
* Return APP Settings
269288
*

includes/admin/class-pinterest-for-woocommerce-admin-settings-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public function maybe_go_to_service_login_url() {
417417
return;
418418
}
419419

420-
if ( ! current_user_can( 'manage_options' ) ) {
420+
if ( ! current_user_can( 'manage_woocommerce' ) ) {
421421
wp_die( esc_html__( 'Cheatin’ huh?', 'pinterest-for-woocommerce' ) );
422422
return false;
423423
}

src/API/Advertisers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct() {
4343
* @return boolean
4444
*/
4545
public function permissions_check( WP_REST_Request $request ) {
46-
return current_user_can( 'manage_options' );
46+
return current_user_can( 'manage_woocommerce' );
4747
}
4848

4949

src/API/DomainVerification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct() {
5252
* @return boolean
5353
*/
5454
public function permissions_check( WP_REST_Request $request ) {
55-
return current_user_can( 'manage_options' );
55+
return current_user_can( 'manage_woocommerce' );
5656
}
5757

5858

src/API/FeedIssues.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct() {
5454
* @return boolean
5555
*/
5656
public function permissions_check( WP_REST_Request $request ) {
57-
return current_user_can( 'manage_options' );
57+
return current_user_can( 'manage_woocommerce' );
5858
}
5959

6060

src/API/FeedState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function __construct() {
8080
* @return boolean
8181
*/
8282
public function permissions_check( WP_REST_Request $request ) {
83-
return current_user_can( 'manage_options' );
83+
return current_user_can( 'manage_woocommerce' );
8484
}
8585

8686

src/API/Tags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct() {
4343
* @return boolean
4444
*/
4545
public function permissions_check( WP_REST_Request $request ) {
46-
return current_user_can( 'manage_options' );
46+
return current_user_can( 'manage_woocommerce' );
4747
}
4848

4949

src/API/VendorAPI.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,6 @@ public function register_routes() {
104104
* @return boolean
105105
*/
106106
public function permissions_check( WP_REST_Request $request ) {
107-
108-
return true;
109-
}
110-
111-
/**
112-
* Return is user has permissions to edit option
113-
*
114-
* @param string $option the option to check for permission.
115-
* @param WP_REST_Request $request The request.
116-
*
117-
* @return boolean
118-
*/
119-
public function user_has_option_permission( $option, $request ) {
120-
121-
$permissions = apply_filters( PINTEREST_FOR_WOOCOMMERCE_PREFIX . '_rest_api_option_permissions', array(), $option, $request );
122-
if ( isset( $permissions[ $option ] ) ) {
123-
return $permissions[ $option ];
124-
}
125-
126-
return current_user_can( 'manage_options' );
107+
return current_user_can( 'manage_woocommerce' );
127108
}
128109
}

0 commit comments

Comments
 (0)