Skip to content

Commit

Permalink
fix: make payment field hidden for other vendor in api response (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonh3 authored and sabbir1991 committed Jun 21, 2019
1 parent 1950fd0 commit 6daf03e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
10 changes: 8 additions & 2 deletions includes/api/class-store-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,14 @@ public function delete_store( $request ) {
*
* @return bool
*/
public function update_store_permissions_check() {
return current_user_can( 'dokandar' );
public function update_store_permissions_check( $request ) {
if ( current_user_can( 'manage_woocommerce' ) ) {
return true;
}

if ( current_user_can( 'dokandar' ) ) {
return dokan_get_current_user_id() === absint( $request->get_param( 'id' ) );
}
}

/**
Expand Down
24 changes: 24 additions & 0 deletions includes/class-api-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct() {

// Send email to admin on adding a new product
add_action( 'dokan_rest_insert_product_object', array( $this, 'on_dokan_rest_insert_product' ), 10, 3 );
add_filter( 'dokan_vendor_to_array', [ $this, 'filter_payment_response' ] );
}

/**
Expand Down Expand Up @@ -149,4 +150,27 @@ public function on_dokan_rest_insert_product( $object, $request, $creating ) {

do_action( 'dokan_new_product_added', $object->get_id(), $request );
}

/**
* Make payment field hidden in api response for other vendor
*
* @param array $data
*
* @since DOKAN_LITE_SINCE
*
* @return array
*/
public function filter_payment_response( $data ) {
if ( current_user_can( 'manage_woocommerce' ) ) {
return $data;
}

$vendor_id = ! empty( $data['id'] ) ? absint( $data['id'] ) : 0;

if ( $vendor_id !== dokan_get_current_user_id() ) {
$data['payment'] = '******';
}

return $data;
}
}

0 comments on commit 6daf03e

Please sign in to comment.