wc_rest_check_product_term_permissions

Check permissions of product terms on REST API.

Description

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

Parameters (3)

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

Usage

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

Defined (1)

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

/includes/wc-rest-functions.php  
  1. function wc_rest_check_product_term_permissions( $taxonomy, $context = 'read', $object_id = 0 ) { 
  2. $contexts = array( 
  3. 'read' => 'manage_terms',  
  4. 'create' => 'edit_terms',  
  5. 'edit' => 'edit_terms',  
  6. 'delete' => 'delete_terms',  
  7. 'batch' => 'edit_terms',  
  8. ); 
  9.  
  10. $cap = $contexts[ $context ]; 
  11. $taxonomy_object = get_taxonomy( $taxonomy ); 
  12. $permission = current_user_can( $taxonomy_object->cap->$cap, $object_id ); 
  13.  
  14. return apply_filters( 'woocommerce_rest_check_permissions', $permission, $context, $object_id, $taxonomy );