I have a custom post type and a custom role that is allowed to write and publish for that post type only.
I do not want them to be able to delete their own posts.
However, when I uncheck Delete Own it also unchecks Publish.
It will not allow me to uncheck Delete Own while Publish is checked.
I believe the only way to accomplish this in the current system is to remove the Publish permission for this custom role. This will effectively require all of their posts to be moderated by an Editor or Admin. They would be unable to publish immediately to the site, but they could add their own posts for review. Would this approach be suitable for you?
Thank you but no it wouldn't help. I will have many regular contributors who, between them, will be publishing hundreds of posts. I wouldn't have the time to go through and approve them all.
It seems strange that this cannot be done. The people are writing for me and I simply do not want them to suddenly delete their posts. Perhaps this could be changed in a future version?
I'll ask our developers if this is something they could take on as a change request. I can't guarantee they'll pick it up, but I will update you here with any information I get. In the meantime, I would like to explain why it's actually not easy to unintentionally and permanently delete a post.
- In order to delete a post, you must first move it into the Trash. There is no way to permanently delete a post accidentally from the Post management screens, you can only Trash it. To do that, you must click a link that says "Move to Trash", or select multiple posts and batch update them.
- If you move a post into the Trash, you will then see a notification at the top of the Post list screen: "1 page moved to the Trash. Undo?" The user now has the immediate option to restore that page from the Trash, and a visual cue that something has been Trashed. Screenshot attached.
- In order to permanently delete a post, you must delete it manually from the Trash. That means navigating into the Trash screen and clicking one or more buttons from the Trash screen, with multiple visual cues along the way warning that they are about to delete a post.
So it would actually be quite difficult to permanently delete a post by mistake. The worst you could do from most post management screens is move a post into the Trash, which is easily revertible.
Thank you Christian.
Yes, I realise that it goes into the trash bin. However, I am not bothered about accidental deletions, my concern is if they suddenly want to stop writing for me and deliberately delete all the posts they have written.
I see, I misunderstood your concern. Building on that concern, a "rogue author" could just as easily edit their existing posts to deface your site or slander you, or otherwise republish them with harmful content, right? That's why I believe the best defense against this group of concerns is to require moderation as I was describing. An Admin or Editor can batch publish entire groups of posts from the Pending queue, with or without reviewing them individually. You could also set up an action hook that automatically publishes posts in the "pending" state, for certain users or posts types. It's not a standard workflow but it's an option.
Are you making regular site backups? I think having regularly scheduled backups on a large site is a good idea, since it allows you to revert quickly when there's a problem and set up staging sites for testing updates.
LOL! Yes you are right, but in my situation it really is doubtful that would happen, but possible that they just get fed up with writing and think that it is their own content and thus delete it.
Your suggestion of an action hook to automatically publish posts for certain users or post types is VERY interesting, but I wouldn't know how or where to start. Are there any pointers for doing this? Is it something you can help with?
Yes, backups are done every day.
Yes, backups are done every day.
Okay great, so it's easy to restore posts if someone deletes them.
Are there any pointers for doing this? Is it something you can help with?
Sure. One thing to consider: your users will be able to automatically publish a post by submitting it for review, but they will not actually be able to publish posts directly. Therefore, once the post is published, they will be unable to edit it. It's a bit of a catch, because in order to edit the post they would need to be able to directly publish a post - and they can't. Neither can they modify a published post to set it into another status like "Draft" or "Pending" where they would be able to edit it. I just wanted you to be aware before we continue, as it could introduce a bit of a hassle for you if you need to manually unpublish their posts (i.e. set them back to "Draft" status) anytime they need to edit them after publishing.
With that being said, here is a sample PHP script. Please place this in your theme's functions.php file:
function auto_publish_pending_posts( $post_id ) {
$status = get_post_status( $post_id );
$type = get_post_type( $post_id );
$role = in_array( "customroleslug", get_userdata(get_current_user_id())->roles);
if ( $type == 'customposttypeslug' && $status == 'pending' ) {
$args = array( 'post_status' => 'publish', 'ID' => $post_id );
wp_update_post( $args );
}
}
add_action( 'save_post', 'auto_publish_pending_posts' );
Change "customroleslug" to match the slug of your custom author role that should not have the ability to delete their own posts. Change 'customposttypeslug' to match the slug of the custom post type they can publish.
Sign in as a user in your custom role, and submits a post for review. It should automatically publish.