Support » Plugin: Content Blocks (Custom Post Widget) » How can we exclude editors from changing Content Blocks?

  • Resolved ScottCodes



    If we create a new User Role that can edit posts how do we exclude the role from editing Content Blocks?

    Here is the code we tried in functions.php. It creates a new user role we called “Post Editor.” But they can still edit all custom post types including Content Blocks. We’re trying to exclude Content Blocks. Any idea how we do that?

    We retried naming this capability edit_content_block, edit_content_blocks, edit_custom-post-type but they still showed up in the dashboard of our new “Post Editor”.

    We’ll understand if this is beyond your expertise!

    function add_role_post_editor(){
    if ( get_option( ‘role_post_editor_version’ ) !== 1 ){ // this prevent running on each pageload
    update_option( ‘role_post_editor_version’, 1 );

    $post_editor_capabilities = array(
    ‘edit_posts’ => true,
    ‘edit_others_posts’ => true,
    ‘edit_published_posts’ => true,
    ‘read’ => true,
    ‘read_custom-post-widget’ => false,
    ‘edit_custom-post-widget’ => false,
    ‘edit_custom-post-widget’ => false,
    ‘edit_custom-post-widget’ => false,
    add_role( ‘post_editor’, ‘Post Editor’, $post_editor_capabilities );

    add_action( ‘init’, ‘add_role_post_editor’ );

Viewing 1 replies (of 1 total)
  • Plugin Author Johan van der Wijk


    Hi Scott,

    The capability_type for the content_block custom post type is ‘post’ which means that the capabilities are the same as for ‘post’.

    I think for your purposes it would be best to create a new capability type for the content blocks and then override the default capability as mentioned in this post:

    Let me know if this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘How can we exclude editors from changing Content Blocks?’ is closed to new replies.