gum
11/13/2015 - 9:55 PM

Remove all Woocommerce custom capabilities from DB after deactivating Woo

Remove all Woocommerce custom capabilities from DB after deactivating Woo

//Delete old custom capabilities
add_action( 'admin_init', 'gum_delete_woo_caps' );
function gum_delete_woo_caps(){
	$delete_caps = array(
		'assign_product_terms', 
		'assign_shop_order_terms', 
		'assign_shop_webhook_terms', 
		'delete_others_products',
		'delete_others_shop_coupons', 
		'delete_others_shop_orders',
		'manage_woocommerce',
		'view_woocommerce_reports',
		'edit_product',
		'read_product',
		'delete_product',
		'edit_products',
		'edit_others_products',
		'publish_products',
		'read_private_products',
		'delete_products',
		'delete_private_products',
		'delete_published_products',
		'edit_private_products',
		'edit_published_products',
		'manage_product_terms',
		'edit_product_terms',
		'delete_product_terms',
		'edit_shop_order',
		'read_shop_order',
		'delete_shop_order',
		'edit_shop_orders',
		'edit_others_shop_orders',
		'publish_shop_orders',
		'read_private_shop_orders',
		'delete_shop_orders',
		'delete_private_shop_orders',
		'delete_published_shop_orders',
		'edit_private_shop_orders',
		'edit_published_shop_orders',
		'manage_shop_order_terms',
		'edit_shop_order_terms',
		'delete_shop_order_terms',
		'edit_shop_coupon',
		'read_shop_coupon',
		'delete_shop_coupon',
		'edit_shop_coupons',
		'edit_others_shop_coupons',
		'publish_shop_coupons',
		'read_private_shop_coupons',
		'delete_shop_coupons',
		'delete_private_shop_coupons',
		'delete_published_shop_coupons',
		'delete_others_shop_coupons',
		'edit_private_shop_coupons',
		'edit_published_shop_coupons',
		'manage_shop_coupon_terms',
		'edit_shop_coupon_terms',
		'delete_shop_coupon_terms',
		'assign_shop_coupon_terms',
		'edit_shop_webhook',
		'read_shop_webhook',
		'delete_shop_webhook',
		'edit_shop_webhooks',
		'edit_others_shop_webhooks',
		'publish_shop_webhooks',
		'read_private_shop_webhooks',
		'delete_shop_webhooks',
		'delete_private_shop_webhooks',
		'delete_published_shop_webhooks',
		'delete_others_shop_webhooks',
		'edit_private_shop_webhooks',
		'edit_published_shop_webhooks',
		'manage_shop_webhook_terms',
		'edit_shop_webhook_terms',
		'delete_shop_webhook_terms'
	);
	
	global $wp_roles;
	
	foreach ($delete_caps as $cap) {
		foreach (array_keys($wp_roles->roles) as $role) {
			$wp_roles->remove_cap($role, $cap);
		}
	}
}

$data = get_userdata( get_current_user_id() );
 
if ( is_object( $data) ) {
    $current_user_caps = $data->allcaps;
     
    // print it to the screen
    echo '<pre>' . print_r( $current_user_caps, true ) . '</pre>';
}

$caps = get_role( 'shop_manager' );
echo '<pre>' . print_r( $caps ) . '</pre>';
//exit;