How to Use the User Role Control


Control Overview

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, customers, members, etc.

Usage Examples

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

Configuration

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 by default for all blocks. You can choose which controls are automatically enabled in the plugin’s General Settings.

User Role control in the block settings sidebar (v1.9)

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 of the website.

We will use the Cover block to create the promotional banner.

Steps to Complete

  1. Navigate to the User Role control settings in the Visibility panel.
  2. Click on the “User Roles” option.
  3. Choose “Customer” and “Administrator” from the role selector.

The resulting configuration should resemble the screenshot below.

Configuring the User Role control (v1.9)

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.

Control Settings

User Role control allows you to control who can see the block. There are four options:

Public

When a block is set to Public, the block will be visible to everyone. This is the default option.

Logged-out

When a block is set to Logged-out, only website visitors that are not logged into your website will see the block.

Logged-in

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.

User Role

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 Administrator and 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.

Users

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.

Configuring the Users option in the User Role control in Block Visibility.
Configuring the Users option in the User Role control (v2.0)

Note that the Users option allows you to see all available users on your current WordPress installation. Because of this, the configuration of the Users option is restricted to Administrator-level users. Those who are not Administrators will see the following message.

Error message when a non-Admin users attempts to edit the Users option.

Hide on Selected Users

When the Users option is enabled, you will also see a toggle for “Hide on Selected Users”. By default, if a specific 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.

User Rule Sets

Like other Block Visibility controls, the User Role control can optionally be powered by rules and rule sets. This functionality was added in version 2.3.0 and allows you to create more advanced conditions. For example, you could display a block to all Administrators and Editors except a specific group of users.

Configuring the User Rule Sets option in the User Role control.
Configuring the User Rule Sets option in the User Role control (v2.3)

There are a couple of things to note when using rule sets:

This option allows you to see all available users on your current WordPress installation. Because of this, the User Rule Sets option configuration is restricted to Administrator-level users.

All rules within a rule set must be satisfied for the selected block to be visible. However, you can also create multiple rule sets. Only one rule set needs to apply for the block to be visible. 

Within a rule set, you are creating AND conditions between multiple rules. Between two rule sets, you are creating OR conditions.

There are instances when rule errors can occur. For example, if rule inputs are not completely filled out or if the rule is based on a custom user role that has since been deleted from your website. In these situations, the plugin defaults to showing the block unless other rules apply, which would hide the block.

User is Logged-out

This rule is the same as the main “Logged-out” setting but is included in User Rule Sets so you can combine it with other rules.

User is Logged-in

This rule is the same as the main “Logged-in” setting but is included in User Rule Sets so you can combine it with other rules.

User’s Role

Similar to the main “User role” setting, this rule allows you conditionally display the block based on the role(s) of the current user.

Users

Similar to the main “Users” setting, this rule allows you conditionally display the block based on who the current user is.

Hide When Rules Apply

By default, the block will be visible if the applied rules are satisfied. Simply toggle the “Hide when rules apply” setting to hide the block instead.


Ready to try Block Visibility?

Unlock the power of the Block Editor with location controls, advanced block scheduling, and more!