Secure your content in the WordPress Gutenberg editor via login or by user role, with Secure Blocks for Gutenberg. Available for download now in the WordPress plugin repository.
Using Secure Blocks you can add any Gutenberg block inside a secure block, and have it render only to logged in users, or you can lock it down to a specific user role (or roles) of your choosing.
Secure Blocks also provides an additional area that displays blocks to users that do not have permission to view the content.
An Overview of Secure Blocks for Gutenberg
Here is a quick video walkthrough of how Secure Blocks for Gutenberg works:
There are a planned number of additional blocks that will be added to the Secure Blocks plugin, but for now the main functionality is as follows:
- Display content only to logged-users
- Display alternative content to logged-out users
- Display content to users within certain user roles
- Display alternative content to users not in those user roles
Making the Content Secure in the WordPress Gutenberg Editor with Secure Blocks
To add a secure block simply choose the ‘Secure Block’ block type when clicking the ‘insert block’ button.
Once you insert a secure block you will be presented with the default UI. In the top area you can add multiple sub-blocks that will be made secure (e.g. by default, content in this area is shown if a user is logged in)
In the bottom area you can add multiple sub-blocks that will be shown if the conditions you have set for restricting the top area are not met (e.g. by default, content in this area is shown if a user is logged out) .
There is no limit to the block types you can add in these areas. The next example simply shows a heading and a paragraph.
Then depending on the restrictions you have set for the secure area, and how you are viewing the site, you are presented with the appropriate content.
Restricting Content Further by User Role
By using the ‘Select Roles’ block inspector you can restrict content further to a user role.
You can select multiple roles that the content will be restricted to, and the content will only be shown if a user is in any of those roles.
You can clearly see how the content has been restricted as the blocks UI is updated with the selected options.
No Block Restrictions
You can add any type of Gutenberg block into the secure area, and you can choose any of the display options.
As you can see, the bounds of the secure block do not limit the rendering of the sub blocks.
Are You a Developer?
If you are a WordPress developer who has an interest in Gutenberg, checkout my previous and future Gutenberg articles.