Posts, Post Types: Switch to restoring posts to draft status by default when they are untrashed.

This allows for edits to be made to a restored post before it goes live again. This also prevents scheduled posts being published unexpectedly if they are untrashed after their originally scheduled date.

The old behaviour of restoring untrashed posts to their original status can be reinstated using the `wp_untrash_post_set_previous_status()` helper function.

Also fixes an issue where the incorrect post ID gets passed to hooks if no post ID is passed to the function.

Props harrym, bananastalktome, jaredcobb, chriscct7, melchoyce, johnbillion, pankajmohale

Fixes #23022

Built from https://develop.svn.wordpress.org/trunk@49125


git-svn-id: http://core.svn.wordpress.org/trunk@48887 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn
2020-10-11 13:39:07 +00:00
parent 9bfc867e66
commit bd1fa2d998
5 changed files with 85 additions and 12 deletions

View File

@@ -134,6 +134,11 @@ if ( $doaction ) {
break;
case 'untrash':
$untrashed = 0;
if ( isset( $_GET['doaction'] ) && ( 'undo' === $_GET['doaction'] ) ) {
add_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 );
}
foreach ( (array) $post_ids as $post_id ) {
if ( ! current_user_can( 'delete_post', $post_id ) ) {
wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) );
@@ -146,6 +151,9 @@ if ( $doaction ) {
$untrashed++;
}
$sendback = add_query_arg( 'untrashed', $untrashed, $sendback );
remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 );
break;
case 'delete':
$deleted = 0;
@@ -419,6 +427,18 @@ foreach ( $bulk_counts as $message => $count ) {
$ids = preg_replace( '/[^0-9,]/', '', $_REQUEST['ids'] );
$messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ) . '">' . __( 'Undo' ) . '</a>';
}
if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
$ids = explode( ',', $_REQUEST['ids'] );
if ( 1 === count( $ids ) && current_user_can( 'edit_post', $ids[0] ) ) {
$messages[] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( get_edit_post_link( $ids[0] ) ),
esc_html( get_post_type_object( get_post_type( $ids[0] ) )->labels->edit_item )
);
}
}
}
if ( $messages ) {