Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
WC_API_Resource::check_permission( WP_Post|int $post, string $context )
Checks the permissions for the current user given a post and context
Description Description
Parameters Parameters
- $post
-
(Required)
- $context
-
(Required) the type of permission to check, either
read
,write
, ordelete
Return Return
(bool) true if the current user has the permissions to perform the context on the post
Source Source
File: includes/legacy/api/v2/class-wc-api-resource.php
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 ( 'revision' !== $post->post_type && 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; } }
Changelog Changelog
Version | Description |
---|---|
2.1 | Introduced. |