WordPress.org

Make WordPress Core

Ticket #4529: post-trash-undo.diff

File post-trash-undo.diff, 8.0 KB (added by caesarsgrunt, 9 years ago)

Undo for trashing of posts, pages, and media.

  • wp-admin/post.php

     
    196196        if ( ! wp_trash_post($post_id) )
    197197                wp_die( __('Error in moving to trash...') );
    198198
    199         $sendback = wp_get_referer();
     199        $sendback = remove_query_arg(array('trashed','untrashed','deleted','ids'), wp_get_referer());
    200200        if ( strpos($sendback, 'post.php') !== false || strpos($sendback, 'post-new.php') !== false )
    201                 $sendback = admin_url('edit.php?trashed=1');
     201                $sendback = admin_url('edit.php?trashed=1&ids='.$post_id);
    202202        else
    203                 $sendback = add_query_arg('trashed', 1, $sendback);
     203                $sendback = add_query_arg(array('trashed' => 1, ids => $post_id), $sendback);
    204204
    205205        wp_redirect($sendback);
    206206        exit();
  • wp-admin/upload.php

     
    7373        if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
    7474                $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
    7575                $doaction = 'delete';
    76         } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['media']) ) {
    77                 $post_ids = $_GET['media'];
     76        } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && (isset($_GET['media']) || isset($_GET['ids'])) ) {
     77                $post_ids = isset($_GET['media']) ? $_GET['media'] : explode(',', $_GET['ids']);
    7878                $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
    7979        } else
    8080                wp_redirect($_SERVER['HTTP_REFERER']);
     
    8282        $location = 'upload.php';
    8383        if ( $referer = wp_get_referer() ) {
    8484                if ( false !== strpos($referer, 'upload.php') )
    85                         $location = $referer;
     85                        $location = remove_query_arg(array('trashed','untrashed','deleted','message','ids'), $referer);
    8686        }
    8787
    8888        switch ( $doaction ) {
     
    9494                                if ( !wp_trash_post($post_id) )
    9595                                        wp_die( __('Error in moving to trash...') );
    9696                        }
    97                         $location = add_query_arg('message', 4, $location);
     97                        $location = add_query_arg(array('message' => 4, 'ids' => join(',', $post_ids)), $location);
    9898                        break;
    9999                case 'untrash':
    100100                        foreach( (array) $post_ids as $post_id ) {
     
    202202$messages[1] = __('Media attachment updated.');
    203203$messages[2] = __('Media permanently deleted.');
    204204$messages[3] = __('Error saving media attachment.');
    205 $messages[4] = __('Media moved to the trash.') . ' <a href="' . admin_url('upload.php?status=trash') . '">' . __('View trash') . '</a> ';
     205$messages[4] = __('Media moved to the trash.') . ' <a href="' . esc_url( wp_nonce_url( 'upload.php?doaction=undo&action=untrash&ids='.$_GET['ids'], "bulk-media" ) ) . '">' . __('Undo?') . '</a>';
    206206$messages[5] = __('Media restored from the trash.');
    207207
    208208if ( isset($_GET['message']) && (int) $_GET['message'] ) {
  • wp-admin/edit.php

     
    2323// Handle bulk actions
    2424if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
    2525        check_admin_referer('bulk-posts');
    26         $sendback = wp_get_referer();
     26        $sendback = remove_query_arg(array('trashed','untrashed','deleted','ids'), wp_get_referer());
    2727
    2828        if ( strpos($sendback, 'post.php') !== false )
    2929                $sendback = admin_url('post-new.php');
     
    3232                $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
    3333                $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = %s", $post_status ) );
    3434                $doaction = 'delete';
    35         } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post']) ) {
    36                 $post_ids = array_map( 'intval', (array) $_GET['post'] );
     35        } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && (isset($_GET['post']) || isset($_GET['ids'])) ) {
     36                $post_ids = isset($_GET['post']) ? array_map( 'intval', (array) $_GET['post'] ) : explode(',', $_GET['ids']);
    3737                $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
    3838        } else {
    3939                wp_redirect( admin_url('edit.php') );
     
    5151
    5252                                $trashed++;
    5353                        }
    54                         $sendback = add_query_arg('trashed', $trashed, $sendback);
     54                        $sendback = add_query_arg(array('trashed' => $trashed, 'ids' => join(',', $post_ids)), $sendback);
    5555                        break;
    5656                case 'untrash':
    5757                        $untrashed = 0;
     
    167167
    168168if ( isset($_GET['trashed']) && (int) $_GET['trashed'] ) {
    169169        printf( _n( 'Post moved to the trash.', '%s posts moved to the trash.', $_GET['trashed'] ), number_format_i18n( $_GET['trashed'] ) );
    170         echo ' <a href="' . admin_url('edit.php?post_status=trash') . '">' . __('View trash') . '</a> ';
     170        $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
     171        echo ' <a href="' . esc_url( wp_nonce_url( "edit.php?doaction=undo&action=untrash&ids=$ids", "bulk-posts" ) ) . '">' . __('Undo?') . '</a><br />';
    171172        unset($_GET['trashed']);
    172173}
    173174
  • wp-admin/page.php

     
    156156        if ( !wp_trash_post($post_id) )
    157157                wp_die( __('Error in moving to trash...') );
    158158
    159         $sendback = wp_get_referer();
     159        $sendback = remove_query_arg(array('trashed','untrashed','deleted','ids'), wp_get_referer());
    160160        if ( strpos($sendback, 'page.php') !== false || strpos($sendback, 'page-new.php') !== false )
    161                 $sendback = admin_url('edit-pages.php?trashed=1');
     161                $sendback = admin_url('edit-pages.php?trashed=1&ids='.$post_id);
    162162        else
    163                 $sendback = add_query_arg('trashed', 1, $sendback);
     163                $sendback = add_query_arg(array('trashed' => 1, ids => $post_id), $sendback);
    164164
    165165        wp_redirect($sendback);
    166166        exit();
  • wp-admin/edit-pages.php

     
    1515// Handle bulk actions
    1616if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
    1717        check_admin_referer('bulk-pages');
    18         $sendback = wp_get_referer();
     18        $sendback = remove_query_arg(array('trashed','untrashed','deleted','ids'), wp_get_referer());
    1919
    2020        if ( strpos($sendback, 'page.php') !== false )
    2121                $sendback = admin_url('page-new.php');
     
    2424                $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
    2525                $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = %s", $post_status ) );
    2626                $doaction = 'delete';
    27         } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post']) ) {
    28                 $post_ids = array_map( 'intval', (array) $_GET['post'] );
     27        } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && (isset($_GET['post']) || isset($_GET['ids'])) ) {
     28                $post_ids = isset($_GET['post']) ? array_map( 'intval', (array) $_GET['post'] ) : explode(',', $_GET['ids']);
    2929                $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
    3030        } else {
    3131                wp_redirect( admin_url('edit-pages.php') );
     
    4343
    4444                                $trashed++;
    4545                        }
    46                         $sendback = add_query_arg('trashed', $trashed, $sendback);
     46                        $sendback = add_query_arg(array('trashed' => $trashed, 'ids' => join(',', $post_ids)), $sendback);
    4747                        break;
    4848                case 'untrash':
    4949                        $untrashed = 0;
     
    163163}
    164164if ( isset($_GET['trashed']) && (int) $_GET['trashed'] ) {
    165165        printf( _n( 'Page moved to the trash.', '%s pages moved to the trash.', $_GET['trashed'] ), number_format_i18n( $_GET['trashed'] ) );
    166         echo ' <a href="' . admin_url('edit-pages.php?post_status=trash') . '">' . __('View trash') . '</a> ';
     166        $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
     167        echo ' <a href="' . esc_url( wp_nonce_url( "edit-pages.php?doaction=undo&action=untrash&ids=$ids", "bulk-pages" ) ) . '">' . __('Undo?') . '</a><br />';
    167168        unset($_GET['trashed']);
    168169}
    169170if ( isset($_GET['untrashed']) && (int) $_GET['untrashed'] ) {