Change WordPress user roles and capabilities Forums New Feature Request restrict/hide Gutenberg blocks by role

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #5669
    crumpetchris
    Participant

    this would be great to have, I love the shortcodes but this would be more intuitive

    #5676
    Vladimir
    Keymaster

    Thanks for the suggestion. I fully agree with you.
    It’s a subject for further development. I will realize this feature this year.

    #6954
    WolfE1963
    Participant

    Hello Vladimir,
    did you realize it?
    Thanks

    #6956
    Vladimir
    Keymaster

    Hi,

    Sorry, this feature is not realized. I still agree that it would be good to add to URE Pro. I can not tell you the date though.

    #7097
    datendrang
    Participant

    Hello!

    This Feature would be GREAT! In the new Version of WP the Block Library and the “Gutenberg Templates” are improved. So it would be perfect, do restrict them with permissions for different editor roles.

    Give complex Blocks, Block library elements and Templates only to advanced users.
    Give simple ones to regular editors.

    I did a lot of research for this features. No one is really offering it at the moment! So this would be a big improvement for all of us. The only plugin which is pointing in this direction is https://wordpress.org/plugins/advanced-gutenberg/ (but i think it is restricted to their own blocks….)

    Also there is no option to share/import/export profiles, or use them over multisite.

    What do you think about this feature?

    We are building two multisites for 2 non-profit organisations at the moment, where we could need this feature.
    => so if you need some Beta-testing and Feedback, i would be happy to assist you!

    Best regards
    David

    #7104
    Vladimir
    Keymaster

    Hi David!

    Thank you for the detailed explanation. I plan to work in this feature.

    #7105
    datendrang
    Participant

    Hello Vladimir, this are GOOD News! Thank you!!!

    #7221
    WolfE1963
    Participant

    Hi Vladimir, hi David,

    I found a code that allow/disallow blocks for specific post types. Is it possible to change that code in a way that I can allow all blocks for admins and only specific blocks for the user roles?
    I’m not a coder ;-), maybe something like If(!current_user_can(‘author’) array a,b,c …

    That’s the code from https://rudrastyh.com/gutenberg/remove-default-blocks.html#remove_blocks

    add_filter( 'allowed_block_types', 'misha_allowed_block_types', 10, 2 );
     
    function misha_allowed_block_types( $allowed_blocks, $post ) {
     
    	$allowed_blocks = array(
    		'core/image',
    		'core/paragraph',
    		'core/heading',
    		'core/list'
    	);
     
    	if( $post->post_type === 'page' ) {
    		$allowed_blocks[] = 'core/shortcode';
    	}
     
    	return $allowed_blocks;
     
    } 
    

    Please stay safe
    Wolfgang

    #7232
    Vladimir
    Keymaster

    Hi Wolfgang,

    You can try this version:

    
    add_filter( 'allowed_block_types', 'misha_allowed_block_types', 10, 2 );
     
    function misha_allowed_block_types( $allowed_blocks, $post ) {
        
        $user = wp_get_current_user();
        
        if ( in_array('administrator', $user->roles ) ) {
            // Do not change the list of default blocks for user with administrator role
            return $allowed_blocks;
        }
    
        if ( in_array('author', $user->roles ) ) {
            // Customize the list of allowed blockes for user with role author
            $allowed_blocks = array(
                'core/image',
                'core/paragraph',
                'core/heading',
                'core/list'
            );    
            return $allowed_blocks;
        }
    	  
    	return $allowed_blocks;
    } 
    
    #7418
    WolfE1963
    Participant

    Dear Vladimir,

    so sorry, I overlooked your reply.

    IT WORKS!!! What a game changer.
    Thank you so much for what you are doing and for your support.
    Yours,
    Wolfgang

    #7423
    datendrang
    Participant

    Hello Vladimir!

    yes, that works! Thank you very much! Are you still planning to implement this in your plugin somehow?

    Maybe this plugin is somehow helpful to get the list of all used blocks?

    Find My Blocks

    best regards
    David

    #7424
    Vladimir
    Keymaster

    Hi David!

    Thanks for the remind and references on possibly useful code references from existing plugins.

    Sure. This feature is a must have for User Role Editor Pro and I still plan to realize it.
    I can not tell an exact time when I will be ready to introduce it though. So please wait a little bit more…

    #8240
    UserRole Supporter
    Participant

    Hi Vladimir,

    If you implement this it would be great to allow us to add blocks to it via their address path eg – “flexblocks/column” etc. This way we can add all the 3rd party blocks we need restricted.

    Is it still planned?

    Thanks

    #8241
    Vladimir
    Keymaster

    Hi,

    Thanks for suggestion. Yes, it’s still planned and finally will be realized.

    #8242
    UserRole Supporter
    Participant

    But I guess it wouldn’t need my last suggestion as it would already know all registered blocks 🙁

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.