If you decide you have a type of user you’d like to add and edit posts but don’t wish for them to completely delete posts, here is a solution.
Note: the user can still move content to trash. From there, they won’t be able to delete.
function restrict_post_deletion($post_id){ /* * Get logged in user details */ $user_id = get_current_user_id(); $data = get_userdata($user_id); /* * In this example, restrict 'editor' role * from completely deleting posts. */ if(in_array('editor', $data->roles)) { echo "You are not authorised to delete this content."; exit; } } add_action('delete_post', 'restrict_post_deletion', 10, 1); |
Be First to Comment