wc_rest_check_post_permissions

Check permissions of posts on REST API.

Description

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

Parameters (3)

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

Usage

  1. if ( !function_exists( 'wc_rest_check_post_permissions' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-rest-functions.php'; 
  3.  
  4. // The post type. 
  5. $post_type = ''; 
  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_post_permissions($post_type, $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_post_permissions( $post_type, $context = 'read', $object_id = 0 ) { 
  2. $contexts = array( 
  3. 'read' => 'read_private_posts',  
  4. 'create' => 'publish_posts',  
  5. 'edit' => 'edit_post',  
  6. 'delete' => 'delete_post',  
  7. 'batch' => 'edit_others_posts',  
  8. ); 
  9.  
  10. if ( 'revision' === $post_type ) { 
  11. $permission = false; 
  12. } else { 
  13. $cap = $contexts[ $context ]; 
  14. $post_type_object = get_post_type_object( $post_type ); 
  15. $permission = current_user_can( $post_type_object->cap->$cap, $object_id ); 
  16.  
  17. return apply_filters( 'woocommerce_rest_check_permissions', $permission, $context, $object_id, $post_type );