2

My Wordpress page has a few editors. They need this permission because they need to be allowed to change the posts/pages of others. However there two pages I want only me, the administrator to be able to edit.

How can I accomplish that?

2
  • Please show us what have you tried so far. Commented Jun 23, 2015 at 9:39
  • I think it's also possible to use the user_has_cap filter.
    – birgire
    Commented Jun 30, 2015 at 21:08

1 Answer 1

3

You can try the map_meta_cap filter:

/**
 * Uneditable posts/pages for editors
 */
add_filter( 'map_meta_cap', function ( $caps, $cap, $user_id, $args )  
{
    // Edit to your needs:
    $post_ids = [123, 234, 345, 456]; // Uneditable posts   
    $role     = 'editor';             // Uneditable by this user role

    // Make given posts uneditable for the above user role:
    if (
            'edit_post' === $cap
         && isset( $args[0] )
         && in_array( $args[0], $post_ids ) 
         && current_user_can( $role )
    )
        $caps[] = 'do_not_allow';

    return $caps;

}, 10, 4 );

to make certain pages/posts uneditable by editors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.