Excluding WordPress Widgets from Page Builder Panel
WordPress Widgets are listing under WordPress Widgets category at page builder panel. You are willing to
1. remove the non beaver compatible widgets
2. hide for specific user like your client
3. hide for specific user roles (capabilities like editor, author, contributor etc)
In this article I am sharing the small PHP snippet how you will exclude or remove some widgets from existing lists. As an example I am removing the Calendar, RSS and Tag Cloud WordPress widgets. I am sharing the three possibilities. You will use them as per your requirements. You will add the following PHP snippets at your theme’s functions.php file or plugin’s file.
Excluding for All Users
1 2 3 4 5 6 7 8 9 |
add_filter( 'fl_get_wp_widgets_exclude', 'probb_exclude_wp_widgets' ); function probb_exclude_wp_widgets( $exclude_widgets ) { $exclude_widgets[] = 'WP_Widget_Calendar'; //* Removing Calendar Widget $exclude_widgets[] = 'WP_Widget_RSS'; //* Removing RSS Widget $exclude_widgets[] = 'WP_Widget_Tag_Cloud'; //* Removing Tag Cloud Widget return $exclude_widgets; } |
Excluding for Specific User Role
Assuming that you will disable the some widgets for Editor role users. Here is the snippets for it:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
add_filter( 'fl_get_wp_widgets_exclude', 'probb_exclude_wp_widgets' ); function probb_exclude_wp_widgets( $exclude_widgets ) { $user = wp_get_current_user(); if( is_object($user) && in_array( 'editor', $user->roles ) ) { $exclude_widgets[] = 'WP_Widget_Calendar'; //* Removing Calendar Widget $exclude_widgets[] = 'WP_Widget_RSS'; //* Removing RSS Widget $exclude_widgets[] = 'WP_Widget_Tag_Cloud'; //* Removing Tag Cloud Widget } return $exclude_widgets; } |
Excluding for Specific user
Assuming that you will disable the some widgets for user ID 5. You will try this PHP snippets
1 2 3 4 5 6 7 8 9 10 11 12 13 |
add_filter( 'fl_get_wp_widgets_exclude', 'probb_exclude_wp_widgets' ); function probb_exclude_wp_widgets( $exclude_widgets ) { $user = wp_get_current_user(); if( is_object($user) && $user->ID == 5 ) { $exclude_widgets[] = 'WP_Widget_Calendar'; //* Removing Calendar Widget $exclude_widgets[] = 'WP_Widget_RSS'; //* Removing RSS Widget $exclude_widgets[] = 'WP_Widget_Tag_Cloud'; //* Removing Tag Cloud Widget } return $exclude_widgets; } |
Latest Beaver Builder plugin have an new filter fl_get_wp_widgets_exclude. You will return the widget class name as an array variable with this filter. Above example I am sending three class names: WP_Widget_Calendar, WP_Widget_RSS and WP_Widget_Tag_Cloud.