Keep Selected Roles Out of Beaver Builder
Sends users without the chosen capability back to the normal page if they try to open Beaver Builder, and hides its admin bar link from them.
Opens WPIDE on
Code
// Capability needed to open the builder.
$wpide_bb_capability = 'manage_options';
add_action( 'template_redirect', function () use ( $wpide_bb_capability ) {
if ( ! isset( $_GET['fl_builder'] ) || ! is_user_logged_in() || current_user_can( $wpide_bb_capability ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
wp_safe_redirect( remove_query_arg( array( 'fl_builder', 'fl_builder_ui' ) ) );
exit;
}, 1 );
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) use ( $wpide_bb_capability ) {
if ( ! current_user_can( $wpide_bb_capability ) ) {
$wp_admin_bar->remove_node( 'fl-builder-frontend-edit-link' );
}
}, 999 );
Notes
Beaver Builder Pro's user access settings offer finer control; this is a quick lock for one 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.