wc_rest_check_post_permissions()
Check permissions of posts on REST API.
Hooks from the function
Return
true|false
.
Usage
wc_rest_check_post_permissions( $post_type, $context, $object_id );
- $post_type(string) (required)
- Post type.
- $context(string)
- Request context.
Default: 'read' - $object_id(int)
- Post ID.
Changelog
Since 2.6.0 | Introduced. |
wc_rest_check_post_permissions() wc rest check post permissions code WC 7.7.0
function wc_rest_check_post_permissions( $post_type, $context = 'read', $object_id = 0 ) { $contexts = array( 'read' => 'read_private_posts', 'create' => 'publish_posts', 'edit' => 'edit_post', 'delete' => 'delete_post', 'batch' => 'edit_others_posts', ); if ( 'revision' === $post_type ) { $permission = false; } else { $cap = $contexts[ $context ]; $post_type_object = get_post_type_object( $post_type ); $permission = current_user_can( $post_type_object->cap->$cap, $object_id ); } return apply_filters( 'woocommerce_rest_check_permissions', $permission, $context, $object_id, $post_type ); }