Home Forums WoodMart support forum Disable HTML Blocks for specific roles

Disable HTML Blocks for specific roles

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #528343

    RO
    Participant

    Hi,

    I would like to disable HTML blocks for all roles, except admin.
    How can I do that?

    Thanks!

    #528369

    Artem Temos
    Keymaster

    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

    #528415

    RO
    Participant

    Hi,

    Thank you very much, it works perfect!

    #528529

    Artem Temos
    Keymaster

    Great, you are welcome!

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Disable HTML Blocks for specific roles’ is closed to new replies.