Today, I’m happy to announce my first plugin created specifically for the block editor (Gutenberg). This is an idea that’s been sitting around in an open ticket on GitHub since January 2018, so I’m happy to finally cross it off the ol’ to-do list.
Members – Block Permissions is a plugin that allows you to show/hide blocks on the front end of your site by user logged-in status, user role, or capability.
Note: While this plugin is within the Members “family” of plugins, it is completely standalone and does not require that Members be installed.
The history behind this plugin
For years, users have asked me for several different, sort-of related features for Members. Sometimes it’d be extra shortcodes. Other times, it’d be for an extension of the existing shortcodes. The problem was that the WordPress shortcode system is horribly inflexible for what users were wanting.
Along came the block editor. Gutenberg.
This time has allowed me to think on the problem and come up with a solution that beautifully handles the various features I’ve been tasked with building by the awesome Members plugin users.
This plugin does one thing: it allows you to show or hide content on a per-block basis.
For every block (core or even blocks from other plugins), you’ll see a new “Permissions” box under the “Block” panel on the right. Within that box, you’ll have several options, which appear based on selection:
- Show the block to everyone.
- Show the block to selected.
- Hide the block from selected.
- User Status
- User Role
- User Status (if selected)
- Logged In
- Logged Out
- User Roles (if selected)
- Capability (if selected)
- Error Message
If you’ve selected any permissions for the block, the block will only be shown if they meet those conditions on the front end of the site. You can also optionally choose to display an error message.
Who can assign block permissions?
By default, only administrators can assign block permissions. In order to give other user roles the capability to do this, you’ll need to install the Members plugin or another user role editor and grant them the
Feel free to watch me using the plugin on my test install in the above video. Folks tell me I have a deep Southern accent. I can’t tell. Honestly.
There are situations where this plugin may not work correctly at this time, but there’s a fix.
Primarily, blocks that are “dynamic” or what we called “server-side rendered” blocks are slightly different from normal blocks in how they work. There’s an existing bug filed with the Gutenberg team about this. The “Archives” block is a good example of a dynamic block. It won’t properly load in the editor if permissions are applied to it.
It’s also possible that there are third-party plugin blocks where you’ll run into a similar situation. Or, a situation where permissions apply in the editor but not on the front end.
If this is an issue, the solution is easy. Simply wrap the offending block within the “Group” block. That way, permissions are applied on the group, which works great with Block Permissions.
Currently the plugin works by user status, user role, and capability. However, there are other rule types that I could certainly add in the future, such as:
- Specific users.
- User taxonomies (rarely used but a possibility).
- Time-based blocks.
Feel free to suggest ideas in the comments.
Get the plugin
If you’ve already purchased Members Pro or the All-Access bundle, you can grab a copy of the plugin via your account page.