I’m working in wordpress multi site, but this question is relevant for regular use in wordpress.
How can I hide certain sidebars from certain user groups (e.g. editors or admins) ? I have already tried the trivial:
if(is_admin() && user_can(...)){
register_sidebar...
}
But this doesn’t hide the sidebar, it shows that this sidebar is not active and the editor, for that matter, can still drag in and out as he or she pleases.
Thanks.
I am assuming you mean to limit access to edit a sidebar in the admin interface, not to remove it on the theme.
Without getting to deep into how the widgets/sidebar framework functions behind the scenes, your best bet is going to be to fiddle with the
$wp_registered_sidebars
global. However, the key is when – too early and the wp-admin/widgets.php template will see the missing sidebar and move it over to the Inactive Sidebars ‘sidebar’. Too late and, well, you get no effect.