WC_API_Resource::check_permission()privateWC 2.1

Checks the permissions for the current user given a post and context

Method of the class: WC_API_Resource{}

Hooks from the method

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() code WC 8.9.0

private function check_permission( $post, $context ) {
	$permission = false;

	if ( ! is_a( $post, 'WP_Post' ) ) {
		$post = get_post( $post );
	}

	if ( is_null( $post ) ) {
		return $permission;
	}

	$post_type = get_post_type_object( $post->post_type );

	if ( 'read' === $context ) {
		$permission = 'revision' !== $post->post_type && current_user_can( $post_type->cap->read_private_posts, $post->ID );
	} elseif ( 'edit' === $context ) {
		$permission = current_user_can( $post_type->cap->edit_post, $post->ID );
	} elseif ( 'delete' === $context ) {
		$permission = current_user_can( $post_type->cap->delete_post, $post->ID );
	}

	return apply_filters( 'woocommerce_api_check_permission', $permission, $context, $post, $post_type );
}