# Stage Switcher - Limit user visibility

**URL:** https://discourse.roots.io/t/stage-switcher-limit-user-visibility/8877
**Category:** plugins
**Created:** 2017-02-20T21:56:59Z
**Posts:** 12

## Post 1 by @mckernanin — 2017-02-20T21:56:59Z

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:

1. Add a checkbox to user profiles, allowing stage switcher to be enabled.
2. Adding an options page / config options to select who it shows up for.

Thoughts? There are caveats to both of those ways.

---

## Post 2 by @swalkinshaw — 2017-02-20T22:09:24Z

That sounds like a good idea but I don’t think we’d include it in the plugin by default. Right now it’s a pretty simple plugin.

You can easily add your own functionality and set the `bedrock/stage_switcher_visibility` filter which is included for purposes like this one :slight_smile:

---

## Post 3 by @mckernanin — 2017-02-20T22:13:59Z

Cool beans! Thanks for the input

---

## Post 4 by @valentinocossar — 2018-07-05T22:59:49Z

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. :slight_smile:

---

## Post 5 by @swalkinshaw — 2018-07-06T03:10:45Z

```
add_filter('bedrock/stage_switcher_visibility', function($visibility) {
  return !is_admin();
});
```

It’s a standard filter so something like that should work. By default it’s hidden for non-super admins.

---

## Post 6 by @valentinocossar — 2018-07-06T14:25:11Z

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](https://github.com/roots/wp-stage-switcher/blob/master/wp-stage-switcher.php#L46-L48), using `and` (&&) conditional instead of `or` (||)? Thank you for the support.

---

## Post 7 by @ben — 2018-07-06T14:46:39Z

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).

---

## Post 8 by @valentinocossar — 2018-07-09T11:53:08Z

Hi @ben, sorry for the delay. Sure, I’ve tried these two snippets:

```
add_filter('bedrock/stage_switcher_visibility', function($visibility) {
    if (!current_user_can('manage_options')) {
        return false;
    }
    return true;
});
```

```
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.

Thank you for the support.

---

## Post 9 by @codepuncher — 2018-07-11T10:43:12Z

Doesn’t seem to work for me either. Even this has no effect to the site:

```
add_filter('bedrock/stage_switcher_visibility', function ($visible) {
    die;
    return $visible;
}, PHP_INT_MAX);
```

---

## Post 10 by @valentinocossar — 2018-07-13T01:30:00Z

@swalkinshaw @ben any hint about this issue? Thank you all. :slight_smile:

---

## Post 11 by @ben — 2018-07-13T01:43:10Z

Nope, we have not looked into it. If this is a bug with the plugin then a PR that fixes the issue would be very appreciated.

---

## Post 12 by @valentinocossar — 2018-07-16T17:27:04Z

Hi @ben, I’ve opened [a pull request](https://github.com/roots/wp-stage-switcher/pull/13) with a fix for the issue. Thank you!
