Beaver Themer is an add-on of Beaver Page Builder plugin. This add-on lets you create layouts for archive pages, template an entire post type, 404 and search pages, and create parts like headers and footers.
I create lot of themer layouts for my site. I want to restrict the editing access of only certain layouts for selected WP users. For example, say I have a header/footer layouts and single post layout. I want someone to be able to edit the header, but not be able to change the post layout.
In this article I shall share my procedure. I use following tools:
- Advanced Custom Field Plugin (ACF Pro)
- Beaver Page Builder Plugin
- Beaver Theme Builder Plugin
At first I create the user meta box for themer layouts post type by Advanced Custom Fields plugin. See the screenshot below:
A user meta box will appear below Beaver Theme Layout settings box like attached screenshot.
Therefore I add this small PHP script into the functions.php file of my active theme.
/** * Restricting the editing access of selected users * * @author Paul Chinmoy * @link https://www.paulchinmoy.com */ add_filter( 'map_meta_cap', 'cp_map_meta_cap', 10, 4 ); function cp_map_meta_cap( $caps, $cap, $user_ID, $args ) { if ( in_array( $cap, array( 'delete_post', 'edit_post' ) ) && $args ) { $post_id = $args[0]; if ( ! $post = get_post( $post_id ) ) return $caps; if( $post->post_type !== 'fl-theme-layout' ) return $caps; $restricted_users = get_post_meta( $post->ID, 'restricted_users', true ); if( is_array( $restricted_users ) ) { foreach ( $restricted_users as $user ) { if( $user_ID == $user ) { $caps[] = 'not_allowed'; return $caps; } } } } return $caps; }
map_meta_cap does not actually compare whether the user ID has the actual capability, just what the capability or capabilities are. Above script is only working for delete_post and edit_post capability.
Line no 17 is checking the themer layout post type.
Line no 20 is getting the selected users ID.
Line no 22-28 Not allowing the edit/delete permission if logged user’s ID is matching with restricted users list.
Now I am editing the themer layout and putting the restriction for selected users.
I created a simple plugin “Restrict Editing of Beaver Content” which is working on any post types (not only themer layouts). You can setup the access permission based on individual user or role.