wc_rest_check_post_permissions()WC 2.6.0

Check permissions of posts on REST API.

Хуки из функции

Возвращает

true|false.

Использование

wc_rest_check_post_permissions( $post_type, $context, $object_id );
$post_type(строка) (обязательный)
Post type.
$context(строка)
Request context.
По умолчанию: 'read'
$object_id(int)
Post ID.

Список изменений

С версии 2.6.0 Введена.

Код wc_rest_check_post_permissions() 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 );
}