Make WordPress Core


Ignore:
Timestamp:
10/11/2020 01:37:04 PM (6 years ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit.php

    r48352 r49125  
    135135                case 'untrash':
    136136                        $untrashed = 0;
     137
     138                        if ( isset( $_GET['doaction'] ) && ( 'undo' === $_GET['doaction'] ) ) {
     139                                add_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 );
     140                        }
     141
    137142                        foreach ( (array) $post_ids as $post_id ) {
    138143                                if ( ! current_user_can( 'delete_post', $post_id ) ) {
     
    147152                        }
    148153                        $sendback = add_query_arg( 'untrashed', $untrashed, $sendback );
     154
     155                        remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 );
     156
    149157                        break;
    150158                case 'delete':
     
    420428                $messages[] = '<a href="' . esc_url( wp_nonce_url( "edit.php?post_type=$post_type&doaction=undo&action=untrash&ids=$ids", 'bulk-posts' ) ) . '">' . __( 'Undo' ) . '</a>';
    421429        }
     430
     431        if ( 'untrashed' === $message && isset( $_REQUEST['ids'] ) ) {
     432                $ids = explode( ',', $_REQUEST['ids'] );
     433
     434                if ( 1 === count( $ids ) && current_user_can( 'edit_post', $ids[0] ) ) {
     435                        $messages[] = sprintf(
     436                                '<a href="%1$s">%2$s</a>',
     437                                esc_url( get_edit_post_link( $ids[0] ) ),
     438                                esc_html( get_post_type_object( get_post_type( $ids[0] ) )->labels->edit_item )
     439                        );
     440                }
     441        }
    422442}
    423443
Note: See TracChangeset for help on using the changeset viewer.