WC_API_Resource::check_permission()privateWC 2.1

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

Метод класса: WC_API_Resource{}

Хуков нет.

Возвращает

true|false. true if the current user has the permissions to perform the context on the post

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

// private - только в коде основоного (родительского) класса
$result = $this->check_permission( $post, $context );
$post(WP_Post|int) (обязательный)
-
$context(строка) (обязательный)
the type of permission to check, either read, write, or delete

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

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

Код WC_API_Resource::check_permission() WC 8.1.1

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;
	}
}