The User Role control allows you to conditionally show or hide blocks based on the “role” of the user viewing the webpage. This control can be extremely useful for showing specific content to logged-in users, customer, members, etc.
- Conditionally display a navigation block to logged-in users for account settings.
- Display a special promotion to customers that are logged into your store website.
- Entice website visitors that are not logged in to subscribe to your blog.
- You are using a membership plugin that registers a number of custom user roles. Show and hide certain content depending on the membership role of each user.
How to Enable
Click on any block in the Block Editor and navigate to the Visibility panel in the Settings Sidebar. You will notice the User Role control located beneath the Date & Time control. See the screenshot below. This control is enabled be default for all blocks. You can choose which controls are automatically enabled in the plugin’s General Settings.
How to Configure
Instructions are always better with examples. Let’s assume that we are running a promotion that should only be visible to logged-in users that are also “customers” of our WooCommerce store or Administrators to the website.
We will use the Cover block to create the promotional banner.
Steps to Complete
- Navigate to the User Role control settings in the Visibility panel.
- Click on the “User Roles” option.
- Choose “Customer” and “Administrator” from the role selector.
The resulting configuration should resemble the screenshot below.
How to Disable
If you would like to disable the User Role control at the block level, simply click on the ellipsis icon in the “Controls” bar and deselect it. That said, if you don’t think you will need this control on your website at all, it can be disabled globally in the Visibility Control Settings.
Note that if this control is disabled globally, any blocks that are actively being hidden by the User Role control will become visible again.
User Role control allows you to control who can see the block. There are four options:
When a block is set to Public, the block will be visible to everyone. This is the default option.
When a block is set to Logged-out, only website visitors that are not logged into your website will see the block.
When a block is set to Logged-in, only website visitors that are logged into your website will see the block. This setting does not care about the user’s specific user role (Administrator, Subscriber, Customer…), they just need to be logged in.
The User Role setting allows you to fine-tune the visibility of the block. When enabled, you will be able to select the individual user roles that should be able to see the block. For example, in the screenshot above, the block is only visible to administrators and authors on the website.
The list of available roles includes the standard user roles that come with WordPress, as well as any additional roles provided by third-party plugins or themes.
Hide on Selected Roles
When the User Roles option is enabled, you will also see a toggle for “Hide on Selected Roles”. By default, if specific user roles are selected, the block will only display to users of those selected roles. For example if
Author are selected, the block will only be visible to administrators and authors.
But what if you wanted to display the block to everyone except administrators and authors? That is where “Hide on Selected Roles” comes in. Simply toggle that setting and now the block will only be visible to users without the selected roles.
The Users option was introduced in version 2.0.0 and allows you to restrict the selected block to specific users on your website. For example, in the screenshot below only the users
Ron Swanson and
Tom Haverford would be able to view the selected block.
Note that the Users option allows you to see all available users on your current WordPress installation. Because of this, configuration of the Users option is restricted to Administrator-level users. Those who are not Administrators will see the following message.
Hide on Selected Users
When the Users option is enabled, you will also see a toggle for “Hide on Selected Users”. By default, if specific a user(s) is chosen, the block will only display to that user(s). For example if
Ron Swanson and
Tom Haverford are selected, the block will only be visible to those two users.
But what if you wanted to display the block to everyone except
Ron Swanson and
Tom Haverford ? That is where “Hide on Selected Users” comes in. Simply toggle that setting and now the block will only be visible to users that have not been selected.