WC_API_Resource::check_permission()
Checks the permissions for the current user given a post and context
Method of the class: WC_API_Resource{}
No Hooks.
Return
true|false
. true if the current user has the permissions to perform the context on the post
Usage
// private - for code of main (parent) class only $result = $this->check_permission( $post, $context );
- $post(WP_Post|int) (required)
- -
- $context(string) (required)
- the type of permission to check, either read, write, or delete
Changelog
Since 2.1 | Introduced. |
WC_API_Resource::check_permission() WC API Resource::check permission code WC 7.7.0
private function check_permission( $post, $context ) { if ( ! is_a( $post, 'WP_Post' ) ) { $post = get_post( $post ); } if ( is_null( $post ) ) { return false; } $post_type = get_post_type_object( $post->post_type ); if ( 'read' === $context ) { return current_user_can( $post_type->cap->read_private_posts, $post->ID ); } elseif ( 'edit' === $context ) { return current_user_can( $post_type->cap->edit_post, $post->ID ); } elseif ( 'delete' === $context ) { return current_user_can( $post_type->cap->delete_post, $post->ID ); } else { return false; } }