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?
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.
user_has_cap
filter.