wc_rest_check_post_permissions()WC 2.6.0

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() code WC 8.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 );
}