Keep Selected Roles Out of the Bricks Builder
Sends users without the chosen capability back to the page when they try to open the Bricks builder and hides its admin bar link, as an extra lock on top of Bricks' builder access settings.
Opens WPIDE on
Code
// Capability needed to open the builder.
$wpide_bricks_capability = 'manage_options';
add_action( 'template_redirect', function () use ( $wpide_bricks_capability ) {
if ( ! isset( $_GET['bricks'] ) || ! is_user_logged_in() || current_user_can( $wpide_bricks_capability ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}
wp_safe_redirect( remove_query_arg( 'bricks' ) );
exit;
}, 1 );
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) use ( $wpide_bricks_capability ) {
if ( ! current_user_can( $wpide_bricks_capability ) ) {
$wp_admin_bar->remove_node( 'edit_with_bricks' );
}
}, 999 );
Notes
Change manage_options to edit_others_pages to let editors in too.
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.