Disable HTML Blocks for specific roles				
							
			
	
		
		
		
			
			
	
	- 
		
			
				
	
		
		
			
ROParticipant
		 
				
					
		
	 
	
		
			
			Hi, 
I would like to disable HTML blocks for all roles, except admin.
How can I do that?
Thanks!
					
			
			
		 
	 
 
			
				
	
	
		
			
			Hello,
Try to add the following PHP code snippet to the child theme functions.php file to do this
if ( ! function_exists( 'change_capabilities_of_cms_block' ) ) {
	/**
	 * Grant access to html blocks only to users with administrator rights.
	 *
	 * @param array  $args Array of arguments for registering a post type.
	 *                     See the register_post_type() function for accepted arguments.
	 * @param string $post_type Post type key.
	 *
	 * @return array
	 */
	function change_capabilities_of_cms_block( $args, $post_type ) {
		if ( 'cms_block' !== $post_type ) {
			return $args;
		}
		$args['capabilities'] = array(
			'publish_posts'       => 'manage_options',
			'edit_posts'          => 'manage_options',
			'edit_others_posts'   => 'manage_options',
			'delete_posts'        => 'manage_options',
			'delete_others_posts' => 'manage_options',
			'read_private_posts'  => 'manage_options',
			'edit_post'           => 'manage_options',
			'delete_post'         => 'manage_options',
			'read_post'           => 'manage_options',
		);
		return $args;
	}
	add_filter( 'register_post_type_args', 'change_capabilities_of_cms_block', 10, 2 );
}
Kind Regards 
					
			
			
		 
	 
 
			
				
	
		
		
			
ROParticipant
		 
				
					
		
	 
	
		
			
			Hi, 
Thank you very much, it works perfect!
					
			
			
		 
	 
 
			
				
			
		
	 
	
			
			
		
		
	
		
			The topic ‘Disable HTML Blocks for specific roles’ is closed to new replies.