wc_rest_check_product_reviews_permissions()WC 3.5.0

Check product reviews permissions on REST API.

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

Возвращает

true|false.

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

wc_rest_check_product_reviews_permissions( $context, $object_id );
$context(строка)
Request context.
По умолчанию: 'read'
$object_id(строка)
Object ID.

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

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

Код wc_rest_check_product_reviews_permissions() WC 6.9.4

function wc_rest_check_product_reviews_permissions( $context = 'read', $object_id = 0 ) {
	$permission = false;
	$contexts   = array(
		'read'   => 'moderate_comments',
		'create' => 'edit_products',
		'edit'   => 'edit_products',
		'delete' => 'edit_products',
		'batch'  => 'edit_products',
	);

	if ( $object_id > 0 ) {
		$object = get_comment( $object_id );

		if ( ! is_a( $object, 'WP_Comment' ) || get_comment_type( $object ) !== 'review' ) {
			return false;
		}
	}

	if ( isset( $contexts[ $context ] ) ) {
		$permission = current_user_can( $contexts[ $context ], $object_id );
	}

	return apply_filters( 'woocommerce_rest_check_permissions', $permission, $context, $object_id, 'product_review' );
}