wc_rest_check_post_permissions( string $post_type, string $context = 'read', int $object_id )

Check permissions of posts on REST API.


Description Description


Parameters Parameters

$post_type

(Required) Post type.

$context

(Optional) Request context.

Default value: 'read'

$object_id

(Required) Post ID.


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/wc-rest-functions.php

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

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.