#23022 closed enhancement (fixed)
Always set posts to draft status when untrashing
Reported by: | harrym | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 5.6 | Priority: | normal |
Severity: | normal | Version: | 2.9 |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests commit |
Focuses: | administration | Cc: |
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 (6)
Change History (31)
#3
@
12 years ago
Should probably also stop adding _wp_trash_meta_status
to a post as well, then (patch by @harrym updated to include this)
#6
in reply to:
↑ 5
@
11 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.
#9
@
9 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
@
7 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
@
7 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.
@
7 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.
#13
@
7 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
@
7 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
@
7 years ago
- Owner set to jaredcobb
- Status changed from new to assigned
Assigning to mark the good-first-bug
as "claimed".
#16
@
7 years 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:
- The
Undo
action that appears immediately after trashing a post. I think clicking theUndo
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. - Untrashing a media file when
MEDIA_TRASH
is defined andtrue
. Attachments can't be draft, so this needs testing.
#17
@
4 years ago
- Milestone changed from Future Release to 5.6
- Owner changed from jaredcobb to johnbillion
- Status changed from assigned to reviewing
#20
@
4 years ago
- Keywords needs-testing removed
I refreshed the most recent patch. As a reminder, this:
- Switches to always restoring posts from the trash as a draft
- Adds a
wp_untrash_post_status
filter to change this behaviour - Restores a post to its original status when the user hits
Undo
after trashing a post - Adds tests
Additionally in 23022.diff:
- Adds the
$previous_status
parameter to the various hooks insidewp_untrash_post()
- Adds an
Edit Post
link to the confirmation message after restoring a single post from the trash (see #50618) - Fixes an existing issue in
wp_untrash_post()
where$post_id
might remain as0
in the unlikely event the function is called without a$post_id
parameter
To recap some reasons why making this change is a good idea:
- Restoring a previously published post causes it to be re-published
- Restoring a scheduled post can cause it to be published (#37366)
#21
@
4 years ago
One item left to test: Behaviour when MEDIA_TRASH
is defined and set to true
. Might need a condition for the default value passed to the wp_untrash_post_status
filter to account for this.
#22
@
4 years ago
- Keywords commit added
This change works fine when MEDIA_TRASH
is in use because wp_insert_post()
converts most post statuses to inherit
when working with the attachment
post type, but just for clarity I've added a line to explicitly use inherit
for attachments.
#24
follow-up:
↓ 25
@
3 years ago
This broke bbPress, which relied pretty heavily on the previous behavior for topic and reply moderation.
https://bbpress.trac.wordpress.org/ticket/3433
The new wp_untrash_post_status
filter did not help existing plugins maintain their status quo's.
Why was there was no developer note for this breakage?
In my opinion, the committed solution here is suboptimal. The wp_untrash_post_set_previous_status()
implementation should have been the first clue this was not a great idea.
A new property could have been added to WP_Post_Type
to define the untrash status/behavior – core post types could have updated themselves (to default to draft
per this issue) and the world of a thousand registered custom post types could migrate at their convenience, and no new single-use filter or function shim would have been necessary.
#25
in reply to:
↑ 24
@
3 years ago
Replying to johnjamesjacoby:
This broke bbPress, which relied pretty heavily on the previous behavior for topic and reply moderation.
The good news is that the patch in 3433 fixes the issue in bbPress.
Sets untrashed posts to draft status instead of their original status