wc_rest_check_user_permissions

Check permissions of users on REST API.

Description

wc_rest_check_user_permissions( (string) $context = 'read', (int) $object_id = 0 ); 

Parameters (2)

0. $context — Optional. (string) => 'read'
Request context.
1. $object_id — Optional. (int)
The object id.

Usage

  1. if ( !function_exists( 'wc_rest_check_user_permissions' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-rest-functions.php'; 
  3.  
  4. // Request context. 
  5. $context = 'read'; 
  6.  
  7. // The object id. 
  8. $object_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_rest_check_user_permissions($context, $object_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-rest-functions.php  
  1. function wc_rest_check_user_permissions( $context = 'read', $object_id = 0 ) { 
  2. $contexts = array( 
  3. 'read' => 'list_users',  
  4. 'create' => 'edit_users',  
  5. 'edit' => 'edit_users',  
  6. 'delete' => 'delete_users',  
  7. 'batch' => 'edit_users',  
  8. ); 
  9.  
  10. $permission = current_user_can( $contexts[ $context ], $object_id ); 
  11.  
  12. return apply_filters( 'woocommerce_rest_check_permissions', $permission, $context, $object_id, 'user' );