Keep Selected Roles Out of the Divi Visual Builder
Sends users without the capability you choose back to the normal page when they try to open the Divi Visual Builder, and hides the "Enable Visual Builder" admin bar link from them.
Opens WPIDE on
Code
// Capability needed to use the Visual Builder.
$wpide_divi_builder_capability = 'manage_options';
add_action( 'template_redirect', function () use ( $wpide_divi_builder_capability ) {
if ( empty( $_GET['et_fb'] ) || ! is_user_logged_in() || current_user_can( $wpide_divi_builder_capability ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
wp_safe_redirect( remove_query_arg( array( 'et_fb', 'PageSpeed' ) ) );
exit;
} );
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) use ( $wpide_divi_builder_capability ) {
if ( ! current_user_can( $wpide_divi_builder_capability ) ) {
$wp_admin_bar->remove_node( 'et-use-visual-builder' );
}
}, 999 );
Notes
Divi's Role Editor gives finer control; this is a quick way to lock layouts for everyone below the chosen capability.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.