Skip to content

Snippet: Manually Enable WPBakery on Post Types For Specific User Roles

This snippet will show you how to manually filter the post types that are enabled for the WPBakery page builder by user role. It's important to note that once added to your site it will manually override the WPBakery settings and once removed you will have to either manually remove the capabilities or go to the WPBakery Role Manager and edit the settings there and save, this is because user capabilities are saved to the database.

Make sure to change "shop_manager" for the role name you want to edit. To set for multiple user roles change the $user_role variable to an array and then add a loop around the function so you can run the code for each user_role.

add_filter( 'vc_role_access_all_caps_role', function( $role ) {
	$user_role = 'shop_manager'; // change this to the user role you want to manually enable WPBakery post types for
	if ( empty( $role->name ) && $user_role !== $role->name ) {
		return $role; // security check
	}
	$types = array( 'page', 'post', 'portfolio', 'staff', 'testimonials' );
	foreach ( $types as $type ) {
		$role->capabilities['vc_access_rules_post_types/' . $type ] = 1;
	}
	return $role;
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top