• Hi –

    Thanks for the Content Blocks plugin!

    We’re trying to remove some capabilities from the editor role, including the ability to edit, publish or delete Content Blocks.

    Here is the code we’ve tried. It doesn’t work yet. Any suggestions, please?

    function editor_remove_caps() {
        if( current_user_can( 'editor' ) ){
          $role = get_role( 'editor' );
          $role -> remove_cap( 'edit_content_block' ); // also tried 'edit_content_blocks'
          $role -> remove_cap( 'publish_content_block' ); // also tried 'publish_content_blocks'
          $role -> remove_cap( 'delete_content_block' );
        };
    };
    
    add_action( 'admin_menu', 'editor_remove_caps' );
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Johan van der Wijk

    (@vanderwijk)

    Hi Scott,

    The rights for editing the content_block post type is set as 'capability_type' => 'post' which means that anyone who can edit posts can also edit content blocks.

    There are many ways to use your own capabilities but one way is to create a new role and then override it like this in your functions.php:

    function content_block_args( $args, $post_type ) {
        if ( $post_type == 'content_block' ) {
            $args['role'] = 'content_block_editor'
        }
        return $args;
    }
    add_filter( 'register_post_type_args', 'content_block_args', 20, 2 );

    Note that I have not tested the above code but it can hopefully lead you in the right direction.

    Plugin Author Johan van der Wijk

    (@vanderwijk)

    On second thought, using the role administrator instead of creating the content_block_editor role might be better.

    Thread Starter ScottCodes

    (@scottlush)

    Thanks for your response.

    I think that we are trying to do the inverse:

    We like the “Editor” role because it can edit posts. But we want to remove the capability for an ‘Editor’ to edit Content Blocks. This will allow our editors to edit posts but not edit content blocks. That is what we are trying to achieve.

    We are not trying to create a new role that can edit Content Blocks.

    Hope this makes sense.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to remove capability from editors to access Content Blocks’ is closed to new replies.