I just started using Stage Switcher, and it’s great. I have an idea for a feature, and wanted to solicit some feedback before putting work into it. It would be nice if there was a way to only show the dropdown for certain users. I’m using it on a WP based webapp, where all users are logged in, and currently, they all see stage switcher’s options – but don’t need to. On this site it could be role based, but on other sites I may have non-technical admin users who don’t need to see it either.
I can think of a few ways to do this:
Add a checkbox to user profiles, allowing stage switcher to be enabled.
Adding an options page / config options to select who it shows up for.
Thoughts? There are caveats to both of those ways.
Hi @swalkinshaw, could you explain to me how bedrock/stage_switcher_visibility filter works? I would like to disable the switcher for non admins users, thank you.
Sorry @swalkinshaw, but this doesn’t work for me and by default, I see the switcher for all users. Maybe could be an issue caused by this, using and (&&) conditional instead of or (||)? Thank you for the support.
Are you using what @swalkinshaw provided or something else? You’ll need to modify his example as is_admin only checks to see whether or not you’re in the WP admin (and not someone who isn’t an administrator).
add_filter('bedrock/stage_switcher_visibility', function($visibility) {
global $current_user;
$role = $current_user->roles[0];
if ($role === 'subscriber') {
return false;
}
return true;
});
I’ve also tried to invert the return (true and false), but nothing happens, I can’t hide the switcher for non-admin users (or at least for the subscriber role).
I’ve also tried to deactivate all the plugins (except wp-stage-switcher) to prevent conflicts.