Hide widget from non-admins?
-
Hello,
Thanks for very handy plugin! I’m looking for a way to hide the dashboard widget from everyone but the site admin. I have tried the following code, without success:
add_action('wp_dashboard_setup', 'jr_mss_hide_widget_on_dashboard'); function jr_mss_hide_widget_on_dashboard() { global $pagenow; if (!is_admin() || $pagenow !== 'index.php') { return; } if (!current_user_can('administrator')) { remove_meta_box('simple_space_widget', 'dashboard', 'side'); } }I have also tried the above code with the ‘admin_init’ hook, with the same (unsuccessful) result. Is it at all possible to hide the widget from specific user roles?
Thanks. 🙂
Edit: …aaand, it turns out, all I had to do was to add a priority argument, like this:
add_action('wp_dashboard_setup', 'jr_mss_hide_widget_on_dashboard', 999); function jr_mss_hide_widget_on_dashboard() { global $pagenow; if (!is_admin() || $pagenow !== 'index.php') { return; } if (!current_user_can('administrator')) { remove_meta_box('simple_space_widget', 'dashboard', 'side'); } }I really should explore things more carefully before I ask questions in the forum, hehe. Thanks again for a neat plugin! 🙂
/jenny
-
This topic was modified 5 years ago by
ninsan. Reason: Found a solution
-
This topic was modified 5 years ago by
The topic ‘Hide widget from non-admins?’ is closed to new replies.