I've created a post edit form in front-end of the site, this form is accessible on the front-end ONLY if the user is logged in. Now, for some reason, upon a certain condition is met, I want to DISABLE user capability to edit or delete the post and keep it read only.

I've modified the above mentioned user's capabilities (using a plugin) and have confirmed it via user_can( $user, $capability ) that the user no longer has edit_posts and delete_posts capability.

Now the issue is, the user is still able to edit or delete post(s) via front-end form or delete link. Is there something I am missing? Do I manually have to hook into some action/filter to stop edit/delete_posts action? If so, how can I do it?

Note: All relevant edit_*_posts and delete_*_posts are also disabled.

1 Answer 1


By using this functionality we can able to remove the delete option of the page or post.

function wp_restrict_page_deletion( $caps, $cap, $user_id, $args ) 
   $post_id = $args[0];
   if ( $cap === 'delete_post' && $post_id === your post id* ) 
       $caps[] = 'do_not_allow';
   return $caps;
 add_filter( 'map_meta_cap', 'wp_restrict_page_deletion', 10, 4 );

I think this one is apt for your requirement.

your post id*->Here you need to give the post id of the page or posts,thats you need to remove the delete option.

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.