Display Question
-
I’m not sure when this happened but I have noticed it before, but when I assign the custom dashboard to a specific user role, then create a user with that role, the actual assigned dashboard doesn’t display.
I have one site where the original user I created with the same role does see it, but the newer user doesn’t.
I fixed this by having Claude Code write me a custom snippet, but maybe something needs to updated in the core plugin?
This is what I used
/**
* Force Beaver Builder Dashboard Template
*
* Add as a custom snippet (via WPCodeBox, Code Snippets plugin, or functions.php).
* Reads the template already configured in the Dashboard Welcome for Beaver Builder
* plugin settings screen, then forces it to display — bypassing the plugin's
* role-checking and dismissal logic that can cause it to fail for some users.
*
* No configuration needed — it auto-detects the template from the plugin's settings.
* Optionally restrict to specific user IDs or roles below.
*/
// ── Optional Configuration ─────────────────────────────────────────────────
// Set to true to force for ALL users, or false to use the whitelist below.
define( 'FORCE_BB_DASHBOARD_ALL_USERS', true );
// If ALL_USERS is false, only these user IDs will see it.
// Example: array( 5 ) or array( 5, 12, 23 )
define( 'FORCE_BB_DASHBOARD_USER_IDS', serialize( array() ) );
// If ALL_USERS is false, these roles will also see it (checks all user roles, not just first).
// Example: array( 'editor', 'subscriber' )
define( 'FORCE_BB_DASHBOARD_ROLES', serialize( array() ) );
// ── End Configuration ──────────────────────────────────────────────────────
add_action( 'admin_init', 'force_bb_dashboard_init', 1 );
function force_bb_dashboard_init() {
global $pagenow;
if ( 'index.php' !== $pagenow ) {
return;
}
if ( ! force_bb_dashboard_user_qualifies() ) {
return;
}
// Resolve the template slug from the plugin's saved settings.
$slug = force_bb_dashboard_get_template_slug();
if ( ! $slug ) {
return;
}
// Store it for the render function.
$GLOBALS['force_bb_dashboard_slug'] = $slug;
// Force the welcome panel to be visible (resets any previous dismissal).
$user_id = get_current_user_id();
if ( '1' !== get_user_meta( $user_id, 'show_welcome_panel', true ) ) {
update_user_meta( $user_id, 'show_welcome_panel', 1 );
}
// Remove the default welcome panel and any existing plugin panel.
remove_action( 'welcome_panel', 'wp_welcome_panel' );
// Hook our forced template display.
if ( current_user_can( 'edit_theme_options' ) ) {
add_action( 'welcome_panel', 'force_bb_dashboard_render' );
} else {
add_action( 'admin_notices', 'force_bb_dashboard_render_notice' );
}
// Prevent dismissal.
add_action( 'admin_head-index.php', 'force_bb_dashboard_prevent_dismiss' );
add_filter( 'get_user_metadata', 'force_bb_dashboard_force_show_meta', 10, 4 );
}
/**
* Pull the template slug from the Dashboard Welcome plugin's settings.
* Checks all of the user's roles (not just the first) to find a match.
* Falls back to any configured template if no role-specific match is found.
*/
function force_bb_dashboard_get_template_slug() {
$templates = get_option( 'bbpd_template' );
if ( ! is_array( $templates ) || empty( $templates ) ) {
return false;
}
$user = wp_get_current_user();
$roles = (array) $user->roles;
// Check ALL of the user's roles for a configured template.
foreach ( $roles as $role ) {
if ( isset( $templates[ $role ] ) && 'none' !== $templates[ $role ] && ! empty( $templates[ $role ] ) ) {
return $templates[ $role ];
}
}
// Fallback: use the first non-empty template from settings (any role).
foreach ( $templates as $role => $slug ) {
if ( 'none' !== $slug && ! empty( $slug ) ) {
return $slug;
}
}
return false;
}
/**
* Check whether the current user qualifies.
*/
function force_bb_dashboard_user_qualifies() {
if ( ! is_user_logged_in() ) {
return false;
}
if ( FORCE_BB_DASHBOARD_ALL_USERS ) {
return true;
}
$user = wp_get_current_user();
$user_id = $user->ID;
$allowed_ids = unserialize( FORCE_BB_DASHBOARD_USER_IDS );
if ( ! empty( $allowed_ids ) && in_array( $user_id, $allowed_ids, true ) ) {
return true;
}
$allowed_roles = unserialize( FORCE_BB_DASHBOARD_ROLES );
if ( ! empty( $allowed_roles ) ) {
foreach ( $allowed_roles as $role ) {
if ( in_array( $role, $user->roles, true ) ) {
return true;
}
}
}
return false;
}
/**
* Force show_welcome_panel meta to always return 1.
*/
function force_bb_dashboard_force_show_meta( $value, $object_id, $meta_key, $single ) {
if ( 'show_welcome_panel' === $meta_key && force_bb_dashboard_user_qualifies() ) {
return $single ? '1' : array( '1' );
}
return $value;
}
/**
* Render the Beaver Builder template.
*/
function force_bb_dashboard_render() {
$slug = isset( $GLOBALS['force_bb_dashboard_slug'] ) ? $GLOBALS['force_bb_dashboard_slug'] : '';
if ( empty( $slug ) ) {
echo '<div class="notice notice-error"><p><strong>Force BB Dashboard:</strong> No template configured in Dashboard Welcome plugin settings.</p></div>';
return;
}
if ( class_exists( 'FLBuilderModel' ) ) {
$post = get_page_by_path( $slug, OBJECT, array( 'page', 'fl-builder-template' ) );
if ( $post ) {
FLBuilderModel::set_post_id( $post->ID );
}
}
echo '<div id="force-bb-dashboard-welcome" style="padding: 20px;">';
echo do_shortcode( '[fl_builder_insert_layout slug="' . esc_attr( $slug ) . '"]' );
echo '</div>';
}
/**
* Fallback render for users without edit_theme_options.
*/
function force_bb_dashboard_render_notice() {
echo '<div id="force-bb-dashboard-welcome-notice" style="margin: 20px 0;">';
force_bb_dashboard_render();
echo '</div>';
?>
<script>
(function() {
var notice = document.getElementById('force-bb-dashboard-welcome-notice');
var welcome = document.getElementById('welcome-panel');
if (notice && welcome) {
welcome.innerHTML = '';
welcome.appendChild(notice);
welcome.style.display = 'block';
}
})();
</script>
<?php
}
/**
* Prevent dismissal of the panel.
*/
function force_bb_dashboard_prevent_dismiss() {
?>
<style>
#welcome-panel .welcome-panel-close,
#force-bb-dashboard-welcome-notice .welcome-panel-close { display: none !important; }
#welcome-panel { display: block !important; }
</style>
<script>
jQuery(document).ready(function($) {
$(document).on('click', '.welcome-panel-close', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
return false;
});
});
</script>
<?php
}
You must be logged in to reply to this topic.