WordPress.org

Make WordPress Core

Opened 7 years ago

Last modified 22 months ago

#23022 assigned enhancement

Always set posts to draft status when untrashing

Reported by: harrym Owned by: jaredcobb
Milestone: Future Release Priority: normal
Severity: normal Version: 2.9
Component: Posts, Post Types Keywords: has-patch needs-testing has-unit-tests
Focuses: administration Cc:
PR Number:

Description

In some situations it is bad when trashed posts immediately go live after being untrashed. Such as:

  • A published post is found to have libellous/wrong/other_bad content in it
  • Admin trashes the post
  • Admin wants to edit the post and republish it without the bad things
  • Admin cannot do this without republishing the bad things, which they cannot do.

I appreciate that the user should have unpublished the post rather than trashing it but people don't always think clearly in these situations, and once you're in it, you can't get out -- your options are to republish, permanently delete, or leave the post in limbo.

I did wonder if it would be better to make trashed posts viewable/editable in the admin but that felt like a pretty big move, and one that would make the status of a trashed post much less clear and rather ambiguous.

So, the attached patch sets all untrashed posts to draft status, rather than restoring their original status, which was the only other thing I could think of.

(Definitely happy to debate alternative solutions)

Attachments (4)

alwaysdraft.diff (533 bytes) - added by harrym 7 years ago.
Sets untrashed posts to draft status instead of their original status
23022.2.patch (761 bytes) - added by bananastalktome 7 years ago.
23022.3.patch (1.2 KB) - added by jaredcobb 2 years ago.
When applied, this causes posts to be assigned a post_status of draft by default when they are untrashed (restored). Also adds a new filter for the post status called wp_untrash_post_status to allow customization of this post status.
23022.patch (5.1 KB) - added by johnbillion 22 months ago.

Download all attachments as: .zip

Change History (20)

@harrym
7 years ago

Sets untrashed posts to draft status instead of their original status

#1 @SergeyBiryukov
7 years ago

  • Version changed from trunk to 3.5

#2 @nacin
7 years ago

  • Component changed from Administration to Trash
  • Version changed from 3.5 to 2.9

#3 @bananastalktome
7 years ago

Should probably also stop adding _wp_trash_meta_status to a post as well, then (patch by @harrym updated to include this)

#4 @kovshenin
7 years ago

  • Cc kovshenin added
  • Keywords editorial-flow added

#5 follow-up: @harrym
6 years ago

Is it possible to consider this for inclusion in 3.7?

#6 in reply to: ↑ 5 @DrewAPicture
6 years ago

  • Milestone changed from Awaiting Review to Future Release

Replying to harrym:

Is it possible to consider this for inclusion in 3.7?

It's too late for 3.7 as it's an enhancement and we're already in beta. 3.8 may be a possibility though.

#7 @nacin
6 years ago

  • Component changed from Trash to Posts, Post Types

#9 @chriscct7
4 years ago

  • Focuses administration added
  • Keywords dev-feedback ux-feedback added; 2nd-opinion removed

What about adding the ability to "preview" the trashed post, in the admin, similar to the screen for editing the post minus the ability to change any of the content, but you'd still get the publish metabox where the restore, delete permenantly, and change status to dropdown could be. In a site with many trashed posts, particularly on sites with many posts of the same name, there's no way to tell which page you're actually restoring. In allowing for the ability to "preview" the post, we can easily offer the ability to set the status to something like draft or pending.

#10 @melchoyce
2 years ago

I like this idea — it's a good safety net for folks.

However, I'm a -1 for @chriscct7's idea, which sounds very complex. I think restoring as a draft is good enough, FWIW.

#11 @johnbillion
2 years ago

  • Keywords needs-patch good-first-bug added; has-patch dev-feedback ux-feedback removed

I think the preferred behaviour here would be to always restore trashed posts to draft status, along with a new filter so that the restored post status can be filtered.

The functionality of the _wp_trash_meta_status meta field should remain.

@jaredcobb
2 years ago

When applied, this causes posts to be assigned a post_status of draft by default when they are untrashed (restored). Also adds a new filter for the post status called wp_untrash_post_status to allow customization of this post status.

#12 @jaredcobb
2 years ago

  • Keywords has-patch added; needs-patch removed

#13 @jaredcobb
2 years ago

Note: In order to keep the previous behavior (where a restored post receives the post_status it had before it was trashed) use the wp_untrash_post_status filter like so:

<?php
add_filter( 'wp_untrash_post_status', function( $new_status, $post_id, $previous_status ) {
        return $previous_status;
}, 10, 3 );

#14 in reply to: ↑ description @pankajmohale
2 years ago

Replying to harrym:

In some situations it is bad when trashed posts immediately go live after being untrashed. Such as:

  • A published post is found to have libellous/wrong/other_bad content in it
  • Admin trashes the post
  • Admin wants to edit the post and republish it without the bad things
  • Admin cannot do this without republishing the bad things, which they cannot do.

I appreciate that the user should have unpublished the post rather than trashing it but people don't always think clearly in these situations, and once you're in it, you can't get out -- your options are to republish, permanently delete, or leave the post in limbo.

I did wonder if it would be better to make trashed posts viewable/editable in the admin but that felt like a pretty big move, and one that would make the status of a trashed post much less clear and rather ambiguous.

So, the attached patch sets all untrashed posts to draft status, rather than restoring their original status, which was the only other thing I could think of.

(Definitely happy to debate alternative solutions)

<?php
// define the untrash_post callback 
function action_untrash_post( $post_id ) { 
    
    $post_status = get_post_meta($post_id, '_wp_trash_meta_status', true);
 
    $post['post_status'] = $post_status;
 
    delete_post_meta($post_id, '_wp_trash_meta_status');
    delete_post_meta($post_id, '_wp_trash_meta_time');
 
    wp_insert_post( wp_slash( $post ) );
 
    wp_untrash_post_comments($post_id);

}; 
         
// add the action 
add_action( 'untrash_post', 'action_untrash_post', 10, 1 ); 

#15 @DrewAPicture
22 months ago

  • Owner set to jaredcobb
  • Status changed from new to assigned

Assigning to mark the good-first-bug as "claimed".

@johnbillion
22 months ago

#16 @johnbillion
22 months ago

  • Keywords needs-testing has-unit-tests added; editorial-flow good-first-bug removed

23022.patch is a refreshed patch that includes unit tests.

Two scenarios that haven't yet been considered:

  1. The Undo action that appears immediately after trashing a post. I think clicking the Undo button should restore the post to its original status. Only untrashing a post from the trash should restore it to draft. 23022.patch includes this functionality.
  2. Untrashing a media file when MEDIA_TRASH is defined and true. Attachments can't be draft, so this needs testing.
Note: See TracTickets for help on using tickets.