WordPress.org

Make WordPress Core

Ticket #4529: trash.diff

File trash.diff, 90.2 KB (added by caesarsgrunt, 12 years ago)

Many tweaks and refinements to all parts of the trash system, including remembering previous status and better separation of trash from ordinary deletion.

  • wp-app.php

     
    12311231                log_app('Status','204: No Content');
    12321232                header('Content-Type: text/plain');
    12331233                status_header('204');
    1234                 echo "Deleted.";
     1234                echo "Moved to Trash.";
    12351235                exit;
    12361236        }
    12371237
  • wp-includes/post.php

     
    998998
    999999        $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    10001000
    1001         $stats = array( 'publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0 );
     1001        $stats = array( 'publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0, 'trash' => 0 );
    10021002        foreach( (array) $count as $row_num => $row ) {
    10031003                $stats[$row['post_status']] = $row['num_posts'];
    10041004        }
     
    10271027        global $wpdb;
    10281028
    10291029        $and = wp_post_mime_type_where( $mime_type );
    1030         $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' $and GROUP BY post_mime_type", ARRAY_A );
     1030        $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A );
    10311031
    10321032        $stats = array( );
    10331033        foreach( (array) $count as $row ) {
    10341034                $stats[$row['post_mime_type']] = $row['num_posts'];
    10351035        }
     1036        $stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");
    10361037
    10371038        return (object) $stats;
    10381039}
     
    11401141        if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) )
    11411142                return $post;
    11421143
    1143         if ( 'attachment' == $post->post_type )
     1144        if (($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS > 0)
     1145                return wp_trash_post($postid);
     1146               
     1147        if ($post->post_type == 'attachment')
    11441148                return wp_delete_attachment($postid);
    11451149
    11461150        do_action('delete_post', $postid);
     1151       
     1152        $trash_meta = get_option('wp_trash_meta');
     1153        if (is_array($trash_meta) && isset($trash_meta['posts'][$postid])) {
     1154                unset($trash_meta['posts'][$postid]);
     1155                update_option('wp_trash_meta', $trash_meta);
     1156        }
    11471157
    11481158        /** @todo delete for pluggable post taxonomies too */
    11491159        wp_delete_object_term_relationships($postid, array('category', 'post_tag'));
     
    12051215}
    12061216
    12071217/**
     1218 * Moves a post or page to the Trash
     1219 *
     1220 * @since 2.9.0
     1221 * @uses do_action() on 'trash_post' before trashing
     1222 * @uses do_action() on 'trashed_post' after trashing
     1223 *
     1224 * @param int $postid Post ID.
     1225 * @return mixed False on failure
     1226 */
     1227function wp_trash_post($postid = 0) {
     1228        if (EMPTY_TRASH_DAYS == 0)
     1229                return wp_delete_post($postid);
     1230       
     1231        if (!$post = wp_get_single_post($postid, ARRAY_A))
     1232                return $post;
     1233       
     1234        do_action('trash_post', $postid);
     1235       
     1236        $trash_meta = get_option('wp_trash_meta');
     1237        if (!is_array($trash_meta))
     1238                $trash_meta = array();
     1239        $trash_meta['posts'][$postid]['status'] = $post['post_status'];
     1240        $trash_meta['posts'][$postid]['time'] = time();
     1241        update_option('wp_trash_meta', $trash_meta);
     1242       
     1243        $post['post_status'] = 'trash';
     1244        wp_insert_post($post);
     1245       
     1246        do_action('trashed_post', $postid);
     1247       
     1248        return $post;
     1249}
     1250
     1251/**
     1252 * Removes a post or page from the Trash
     1253 *
     1254 * @since 2.9.0
     1255 * @uses do_action() on 'untrash_post' before undeletion
     1256 * @uses do_action() on 'untrashed_post' after undeletion
     1257 *
     1258 * @param int $postid Post ID.
     1259 * @return mixed False on failure
     1260 */
     1261function wp_untrash_post($postid = 0) {
     1262        if (!$post = wp_get_single_post($postid, ARRAY_A))
     1263                return $post;
     1264
     1265        do_action('untrash_post', $postid);
     1266       
     1267        $post['post_status'] = 'draft';
     1268       
     1269        $trash_meta = get_option('wp_trash_meta');
     1270        if (is_array($trash_meta) && isset($trash_meta['posts'][$postid])) {
     1271                $post['post_status'] = $trash_meta['posts'][$postid]['status'];
     1272                unset($trash_meta['posts'][$postid]);
     1273                update_option('wp_trash_meta', $trash_meta);
     1274        }
     1275       
     1276        wp_insert_post($post);
     1277       
     1278        do_action('untrashed_post', $postid);
     1279
     1280        return $post;
     1281}
     1282
     1283/**
    12081284 * Retrieve the list of categories for a post.
    12091285 *
    12101286 * Compatibility layer for themes and plugins. Also an easy layer of abstraction
     
    25862662
    25872663        if ( 'attachment' != $post->post_type )
    25882664                return false;
     2665       
     2666        if (get_post_status($postid) != 'trash') {
     2667                return wp_trash_post($postid);
     2668        }
     2669       
     2670        $trash_meta = get_option('wp_trash_meta');
     2671        if (is_array($trash_meta) && isset($trash_meta['posts'][$postid])) {
     2672                unset($trash_meta['posts'][$postid]);
     2673                update_option('wp_trash_meta', $trash_meta);
     2674        }
    25892675
    25902676        $meta = wp_get_attachment_metadata( $postid );
    25912677        $file = get_attached_file( $postid );
  • wp-includes/comment.php

     
    208208                $approved = "comment_approved = '1'";
    209209        elseif ( 'spam' == $status )
    210210                $approved = "comment_approved = 'spam'";
    211         elseif ( 'deleted' == $status )
    212                 $approved = "comment_approved = 'deleted'";
     211        elseif ( 'trash' == $status )
     212                $approved = "comment_approved = 'trash'";
    213213        else
    214214                $approved = "( comment_approved = '0' OR comment_approved = '1' )";
    215215
     
    694694        if ( false !== $count )
    695695                return $count;
    696696
    697         $where = '';
     697        $where = 'WHERE ';
    698698        if( $post_id > 0 )
    699                 $where = $wpdb->prepare( "WHERE comment_post_ID = %d", $post_id );
     699                $where .= $wpdb->prepare( "c.comment_post_ID = %d AND ", $post_id );
     700        $where .= "p.post_status <> 'trash'";
    700701
    701         $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
     702        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} c LEFT JOIN {$wpdb->posts} p ON c.comment_post_ID = p.ID {$where} GROUP BY comment_approved", ARRAY_A );
    702703
    703704        $total = 0;
    704         $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'deleted' => 'deleted');
     705        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash');
    705706        $known_types = array_keys( $approved );
    706707        foreach( (array) $count as $row_num => $row ) {
    707708                $total += $row['num_comments'];
     
    737738 * @return bool False if delete comment query failure, true on success.
    738739 */
    739740function wp_delete_comment($comment_id) {
    740         if (wp_get_comment_status($comment_id) != 'deleted' && wp_get_comment_status($comment_id) != 'spam')
    741                 return wp_set_comment_status($comment_id, 'delete');
     741        global $wpdb;
     742        if (!$comment = get_comment($comment_id))
     743                return false;
     744
     745        if (wp_get_comment_status($comment_id) != 'trash' && wp_get_comment_status($comment_id) != 'spam' && EMPTY_TRASH_DAYS > 0)
     746                return wp_trash_comment($comment_id);
    742747       
    743         global $wpdb;
    744748        do_action('delete_comment', $comment_id);
    745749       
    746         wp_unschedule_comment_delete($comment_id);
     750        $trash_meta = get_option('wp_trash_meta');
     751        if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) {
     752                unset($trash_meta['comments'][$comment_id]);
     753                update_option('wp_trash_meta', $trash_meta);
     754        }
    747755
    748         $comment = get_comment($comment_id);
    749 
    750756        if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) )
    751757                return false;
    752758
     
    769775}
    770776
    771777/**
     778 * Moves a comment to the Trash
     779 *
     780 * @since 2.9.0
     781 * @uses do_action() on 'trash_comment' before trashing
     782 * @uses do_action() on 'trashed_comment' after trashing
     783 *
     784 * @param int $comment_id Comment ID.
     785 * @return mixed False on failure
     786 */
     787function wp_trash_comment($comment_id = 0) {
     788        if (EMPTY_TRASH_DAYS == 0)
     789                return wp_delete_comment($comment_id);
     790       
     791        if (!$comment = get_comment($comment_id))
     792                return false;
     793
     794        do_action('trash_comment', $comment_id);
     795       
     796        $trash_meta = get_option('wp_trash_meta', array());
     797        $trash_meta['comments'][$comment_id]['status'] = $comment->comment_approved;
     798        $trash_meta['comments'][$comment_id]['time'] = time();
     799        update_option('wp_trash_meta', $trash_meta);
     800       
     801        wp_set_comment_status($comment_id, 'trash');
     802       
     803        do_action('trashed_comment', $comment_id);
     804       
     805        return true;
     806}
     807
     808/**
     809 * Removes a comment from the Trash
     810 *
     811 * @since 2.9.0
     812 * @uses do_action() on 'untrash_comment' before undeletion
     813 * @uses do_action() on 'untrashed_comment' after undeletion
     814 *
     815 * @param int $comment_id Comment ID.
     816 * @return mixed False on failure
     817 */
     818function wp_untrash_comment($comment_id = 0) {
     819        do_action('untrash_comment', $comment_id);
     820       
     821        $comment = array('comment_ID'=>$comment_id, 'comment_approved'=>'0');
     822       
     823        $trash_meta = get_option('wp_trash_meta');
     824        if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id])) {
     825                $comment['comment_approved'] = $trash_meta['comments'][$comment_id]['status'];
     826                unset($trash_meta['comments'][$comment_id]);
     827                update_option('wp_trash_meta', $trash_meta);
     828        }
     829       
     830        wp_update_comment($comment);
     831       
     832        do_action('untrashed_comment', $comment_id);
     833
     834        return true;
     835}
     836
     837/**
    772838 * The status of a comment by ID.
    773839 *
    774840 * @since 1.0.0
    775841 *
    776842 * @param int $comment_id Comment ID
    777  * @return string|bool Status might be 'deleted', 'approved', 'unapproved', 'spam'. False on failure.
     843 * @return string|bool Status might be 'trash', 'approved', 'unapproved', 'spam'. False on failure.
    778844 */
    779845function wp_get_comment_status($comment_id) {
    780846        $comment = get_comment($comment_id);
     
    784850        $approved = $comment->comment_approved;
    785851
    786852        if ( $approved == NULL )
    787                 return 'deleted';
     853                return false;
    788854        elseif ( $approved == '1' )
    789855                return 'approved';
    790856        elseif ( $approved == '0' )
    791857                return 'unapproved';
    792858        elseif ( $approved == 'spam' )
    793859                return 'spam';
    794         elseif ( $approved == 'deleted' )
    795                 return 'deleted';
     860        elseif ( $approved == 'trash' )
     861                return 'trash';
    796862        else
    797863                return false;
    798864}
     
    10371103 */
    10381104function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {
    10391105        global $wpdb;
    1040         wp_unschedule_comment_delete($comment_id);
    1041        
     1106               
    10421107        $status = '0';
    1043         switch ( $comment_status ) {
     1108        switch ($comment_status) {
    10441109                case 'hold':
    10451110                        $status = '0';
    10461111                        break;
     
    10541119                case 'spam':
    10551120                        $status = 'spam';
    10561121                        break;
    1057                 case 'delete':
    1058                         if (wp_get_comment_status($comment_id) == 'deleted' || wp_get_comment_status($comment_id) == 'spam')
    1059                                 return wp_delete_comment($comment_id);
    1060                         $status = 'deleted';
    1061                         wp_schedule_comment_delete($comment_id);
     1122                case 'trash':
     1123                        $status = 'trash';
    10621124                        break;
    10631125                default:
    10641126                        return false;
     
    10841146}
    10851147
    10861148/**
    1087  * Schedules a comment for destruction in 30 days.
    1088  *
    1089  * @since 2.9.0
    1090  *
    1091  * @param int $comment_id Comment ID.
    1092  * @return void
    1093  */
    1094 function wp_schedule_comment_delete($comment_id) {
    1095         $to_delete = get_option('wp_scheduled_delete');
    1096         if ( !is_array($to_delete) )
    1097                 $to_delete = array();
    1098        
    1099         $to_delete['comments'][$comment_id] = time();
    1100        
    1101         update_option('wp_scheduled_delete', $to_delete);
    1102 }
    1103 
    1104 /**
    1105  * Unschedules a comment for destruction.
    1106  *
    1107  * @since 2.9.0
    1108  *
    1109  * @param int $comment_id Comment ID.
    1110  * @return void
    1111  */
    1112 function wp_unschedule_comment_delete($comment_id) {
    1113         $to_delete = get_option('wp_scheduled_delete');
    1114         if ( !is_array($to_delete) )
    1115                 return;
    1116        
    1117         unset($to_delete['comments'][$comment_id]);
    1118        
    1119         update_option('wp_scheduled_delete', $to_delete);
    1120 }
    1121 
    1122 /**
    11231149 * Updates an existing comment in the database.
    11241150 *
    11251151 * Filters the comment and makes sure certain fields are valid before updating.
  • wp-includes/functions.php

     
    33393339}
    33403340
    33413341/**
    3342  * Permanently deletes comments that have been scheduled for deleting.
    3343  * Will do the same for posts, pages, etc in the future.
     3342 * Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS.
    33443343 *
    3345  * @access private
    33463344 * @since 2.9.0
    33473345 *
    33483346 * @return void
    33493347 */
    33503348function wp_scheduled_delete() {
    3351         $to_delete = get_option('wp_scheduled_delete');
    3352         if (!is_array($to_delete))
     3349        $trash_meta = get_option('wp_trash_meta');
     3350        if (!is_array($trash_meta))
    33533351                return;
    33543352
    3355         if ( !isset($to_delete['comments']) || !is_array($to_delete['comments']) )
    3356                 $to_delete['comments'] = array();
    3357 
    3358         $delete_delay = defined('EMPTY_TRASH_TIMEOUT') ? (int) EMPTY_TRASH_TIMEOUT : (60*60*24*30);
    3359         $deletetimestamp = time() - $delete_delay;
    3360         foreach ($to_delete['comments'] as $comment_id => $timestamp) {
    3361                 if ($timestamp < $deletetimestamp) {
    3362                         wp_delete_comment($comment_id);
    3363                         unset($to_delete['comments'][$comment_id]);
     3353        $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
     3354       
     3355        foreach ($trash_meta['comments'] as $id => $meta) {
     3356                if ($meta['time'] < $delete_timestamp) {
     3357                        wp_delete_comment($id);
     3358                        unset($trash_meta['comments'][$id]);
    33643359                }
    33653360        }
     3361        foreach ($trash_meta['posts'] as $id => $meta) {
     3362                if ($meta['time'] < $delete_timestamp) {
     3363                        wp_delete_post($id);
     3364                        unset($to_delete['posts'][$id]);
     3365                }
     3366        }
    33663367
    33673368        update_option('wp_scheduled_delete', $to_delete);
    33683369}
  • wp-includes/query.php

     
    20992099                                $p_status[] = "$wpdb->posts.post_status = 'private'";
    21002100                        if ( in_array( 'publish', $q_status ) )
    21012101                                $r_status[] = "$wpdb->posts.post_status = 'publish'";
     2102                        if ( in_array( 'trash', $q_status ) )
     2103                                $r_status[] = "$wpdb->posts.post_status = 'trash'";
    21022104
    21032105                        if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) {
    21042106                                $r_status = array_merge($r_status, $p_status);
  • wp-includes/script-loader.php

     
    204204                        'upload_stopped' => __('Upload stopped.'),
    205205                        'dismiss' => __('Dismiss'),
    206206                        'crunching' => __('Crunching&hellip;'),
    207                         'deleted' => __('Deleted'),
     207                        'deleted' => __('Moved to Trash'),
    208208                        'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};'
    209209        ) );
    210210
  • wp-settings.php

     
    534534if ( !defined( 'AUTOSAVE_INTERVAL' ) )
    535535        define( 'AUTOSAVE_INTERVAL', 60 );
    536536
     537/**
     538 * It is possible to define this in wp-config.php
     539 * @since 2.9.0
     540 */
     541if ( !defined( 'EMPTY_TRASH_DAYS' ) )
     542        define( 'EMPTY_TRASH_DAYS', 30 );
    537543
     544
    538545require (ABSPATH . WPINC . '/vars.php');
    539546
    540547// make taxonomies available to plugins and themes
  • wp-admin/edit-comments.php

     
    1414
    1515$post_id = isset($_REQUEST['p']) ? (int) $_REQUEST['p'] : 0;
    1616
    17 if ( isset($_REQUEST['doaction']) ||  isset($_REQUEST['doaction2']) || isset($_REQUEST['destroy_all']) || isset($_REQUEST['destroy_all2']) ) {
     17if ( isset($_REQUEST['doaction']) ||  isset($_REQUEST['doaction2']) || isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) ) {
    1818        check_admin_referer('bulk-comments');
    1919       
    20         if ((isset($_REQUEST['destroy_all']) || isset($_REQUEST['destroy_all2'])) && !empty($_REQUEST['pagegen_timestamp'])) {
     20        if ((isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) && !empty($_REQUEST['pagegen_timestamp'])) {
    2121                $comment_status = $wpdb->escape($_REQUEST['comment_status']);
    2222                $delete_time = $wpdb->escape($_REQUEST['pagegen_timestamp']);
    2323                $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
    24                 $doaction = 'destroy';
     24                $doaction = 'delete';
    2525        } elseif (($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments'])) {
    2626                $comment_ids = $_REQUEST['delete_comments'];
    2727                $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
    2828        } else wp_redirect($_SERVER['HTTP_REFERER']);
    2929       
    30         $approved = $unapproved = $spammed = $deleted = $destroyed = 0;
     30        $approved = $unapproved = $spammed = $trashed = $untrashed = $deleted = 0;
    3131       
    3232        foreach ($comment_ids as $comment_id) { // Check the permissions on each
    3333                $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
     
    4848                                wp_set_comment_status($comment_id, 'spam');
    4949                                $spammed++;
    5050                                break;
     51                        case 'trash' :
     52                                wp_trash_comment($comment_id);
     53                                $trashed++;
     54                                break;
     55                        case 'untrash' :
     56                                wp_untrash_comment($comment_id);
     57                                $untrashed++;
     58                                break;
    5159                        case 'delete' :
    52                                 wp_set_comment_status($comment_id, 'delete');
     60                                wp_delete_comment($comment_id);
    5361                                $deleted++;
    5462                                break;
    55                         case 'destroy' :
    56                                 wp_set_comment_status($comment_id, 'delete');
    57                                 $destroyed++;
    58                                 break;
    5963                }
    6064        }
    6165
    62         $redirect_to = 'edit-comments.php?approved=' . $approved . '&unapproved=' . $unapproved . '&spam=' . $spammed . '&deleted=' . $deleted . '&destroyed=' . $destroyed;
     66        $redirect_to = 'edit-comments.php?approved=' . $approved . '&unapproved=' . $unapproved . '&spam=' . $spammed . '&trashed=' . $trashed . '&untrashed=' . $untrashed . '&deleted=' . $deleted;
    6367        if ( $post_id )
    6468                $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
    6569        if ( isset($_REQUEST['apage']) )
     
    8690$mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
    8791
    8892$comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
    89 if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'deleted')) )
     93if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'trash')) )
    9094        $comment_status = 'all';
    9195
    9296$comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
     
    102106</h2>
    103107
    104108<?php
    105 if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['destroyed'] ) || isset( $_GET['spam'] ) ) {
    106         $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0;
    107         $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0;
    108         $destroyed = isset( $_GET['destroyed'] ) ? (int) $_GET['destroyed'] : 0;
    109         $spam = isset( $_GET['spam'] ) ? (int) $_GET['spam'] : 0;
     109if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spam']) ) {
     110        $approved = isset($_GET['approved']) ? (int) $_GET['approved'] : 0;
     111        $deleted = isset($_GET['deleted']) ? (int) $_GET['deleted'] : 0;
     112        $trashed = isset($_GET['trashed']) ? (int) $_GET['trashed'] : 0;
     113        $untrashed = isset($_GET['untrashed']) ? (int) $_GET['untrashed'] : 0;
     114        $spam = isset($_GET['spam']) ? (int) $_GET['spam'] : 0;
    110115
    111         if ( $approved > 0 || $deleted > 0 || $destroyed > 0 || $spam > 0 ) {
     116        if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spam > 0 ) {
    112117                echo '<div id="moderated" class="updated fade"><p>';
    113118
    114119                if ( $approved > 0 ) {
     
    119124                        printf( _n( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
    120125                        echo '<br />';
    121126                }
    122                 if ( $deleted > 0 ) {
    123                         printf( _n( '%s comment deleted', '%s comments deleted', $deleted ), $deleted );
     127                if ( $trashed > 0 ) {
     128                        printf( _n( '%s comment moved to the trash', '%s comments moved to the trash', $trashed ), $trashed );
    124129                        echo '<br />';
    125130                }
    126                 if ( $destroyed > 0 ) {
    127                         printf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $destroyed ), $destroyed );
     131                if ( $untrashed > 0 ) {
     132                        printf( _n( '%s comment removed from the trash', '%s comments removed from the trash', $untrashed ), $untrashed );
    128133                        echo '<br />';
    129134                }
     135                if ( $deleted > 0 ) {
     136                        printf( _n( '%s comment permanently deleted', '%s comments permanently deleted', $deleted ), $deleted );
     137                        echo '<br />';
     138                }
    130139
    131140                echo '</p></div>';
    132141        }
     
    145154                'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'),
    146155                'approved' => _n_noop('Approved', 'Approved'), // singular not used
    147156                'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'),
    148                 'deleted' => _n_noop('Trash <span class="count">(<span class="deleted-count">%s</span>)</span>', 'Trash <span class="count">(<span class="deleted-count">%s</span>)</span>')
     157                'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>')
    149158        );
    150159$link = 'edit-comments.php';
    151160if ( !empty($comment_type) && 'all' != $comment_type )
     
    256265<?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
    257266<option value="markspam"><?php _e('Mark as Spam'); ?></option>
    258267<?php endif; ?>
    259 <?php if ( 'deleted' == $comment_status ): ?>
    260 <option value="unapprove"><?php _e('Return to Pending'); ?></option>
     268<?php if ( 'trash' == $comment_status ): ?>
     269<option value="untrash"><?php _e('Remove from Trash'); ?></option>
    261270<?php endif; ?>
    262 <?php if ( 'deleted' == $comment_status || 'spam' == $comment_status ): ?>
    263 <option value="destroy"><?php _e('Delete Permanently'); ?></option>
     271<?php if ( 'trash' == $comment_status || 'spam' == $comment_status ): ?>
     272<option value="delete"><?php _e('Delete Permanently'); ?></option>
    264273<?php else: ?>
    265 <option value="delete"><?php _e('Move to Trash'); ?></option>
     274<option value="trash"><?php _e('Move to Trash'); ?></option>
    266275<?php endif; ?>
    267276</select>
    268277<input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
     
    289298        <input type="hidden" name="apage" value="<?php echo esc_attr( absint( $_GET['apage'] ) ); ?>" />
    290299<?php }
    291300
    292 if ( ( 'spam' == $comment_status || 'deleted' == $comment_status) && current_user_can ('moderate_comments') ) {
     301if ( ( 'spam' == $comment_status || 'trash' == $comment_status) && current_user_can ('moderate_comments') ) {
    293302        wp_nonce_field('bulk-destroy', '_destroy_nonce');
    294303    if ( 'spam' == $comment_status ) { ?>
    295                 <input type="submit" name="destroy_all" id="destroy_all" value="<?php esc_attr_e('Permanently Delete All'); ?>" class="button-secondary apply" />
    296 <?php } elseif ( 'deleted' == $comment_status ) { ?>
    297                 <input type="submit" name="destroy_all" id="destroy_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-primary apply" />
     304                <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
     305<?php } elseif ( 'trash' == $comment_status ) { ?>
     306                <input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
    298307<?php }
    299308} ?>
    300309<?php do_action('manage_comments_nav', $comment_status); ?>
     
    352361<?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
    353362<option value="markspam"><?php _e('Mark as Spam'); ?></option>
    354363<?php endif; ?>
    355 <?php if ( 'deleted' == $comment_status ): ?>
    356 <option value="unapprove"><?php _e('Return to Pending'); ?></option>
     364<?php if ( 'trash' == $comment_status ): ?>
     365<option value="untrash"><?php _e('Remove from Trash'); ?></option>
    357366<?php endif; ?>
    358 <?php if ( 'deleted' == $comment_status || 'spam' == $comment_status ): ?>
    359 <option value="destroy"><?php _e('Delete Permanently'); ?></option>
     367<?php if ( 'trash' == $comment_status || 'spam' == $comment_status ): ?>
     368<option value="delete"><?php _e('Delete Permanently'); ?></option>
    360369<?php else: ?>
    361 <option value="delete"><?php _e('Move to Trash'); ?></option>
     370<option value="trash"><?php _e('Move to Trash'); ?></option>
    362371<?php endif; ?>
    363372</select>
    364373<input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
    365374
    366375<?php if ( 'spam' == $comment_status ) { ?>
    367 <input type="submit" name="destroy_all2" id="destroy_all2" value="<?php esc_attr_e('Empty Quarantine'); ?>" class="button-secondary apply" />
    368 <?php } elseif ( 'deleted' == $comment_status ) { ?>
    369 <input type="submit" name="destroy_all2" id="destroy_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
     376<input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Spam'); ?>" class="button-secondary apply" />
     377<?php } elseif ( 'trash' == $comment_status ) { ?>
     378<input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
    370379<?php } ?>
    371380<?php do_action('manage_comments_nav', $comment_status); ?>
    372381</div>
  • wp-admin/admin-ajax.php

     
    181181$id = isset($_POST['id'])? (int) $_POST['id'] : 0;
    182182switch ( $action = $_POST['action'] ) :
    183183case 'delete-comment' : // On success, die with time() instead of 1
    184         check_ajax_referer( "delete-comment_$id" );
    185184        if ( !$comment = get_comment( $id ) )
    186185                die( (string) time() );
    187186        if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) )
    188187                die('-1');
    189188
    190         if ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
     189        if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
     190                check_ajax_referer( "trash-comment_$id" );
     191                if ( 'trash' == wp_get_comment_status( $comment->comment_ID ) )
     192                        die( (string) time() );
     193                $r = wp_trash_comment( $comment->comment_ID );
     194        } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) {
     195                check_ajax_referer( "untrash-comment_$id" );
     196                $r = wp_untrash_comment( $comment->comment_ID );
     197        } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
     198                check_ajax_referer( "delete-comment_$id" );
    191199                if ( 'spam' == wp_get_comment_status( $comment->comment_ID ) )
    192200                        die( (string) time() );
    193201                $r = wp_set_comment_status( $comment->comment_ID, 'spam' );
    194202        } else {
    195                 $r = wp_set_comment_status( $comment->comment_ID, 'delete' );
     203                check_ajax_referer( "delete-comment_$id" );
     204                $r = wp_delete_comment( $comment->comment_ID );
    196205        }
    197206        if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
    198207                _wp_ajax_delete_comment_response( $comment->comment_ID );
  • wp-admin/wp-admin.css

     
    409409}
    410410
    411411#doaction,
    412 #doaction2 {
     412#doaction2,
     413#post-query-submit {
    413414        margin-right: 8px;
    414415}
    415416
     
    444445        display: none;
    445446}
    446447
    447 .unapproved .approve, .spam .approve, .deleted .approve {
     448.unapproved .approve, .spam .approve, .trash .approve {
    448449        display: inline;
    449450}
    450451
  • wp-admin/includes/post.php

     
    795795                                'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
    796796                                'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
    797797                                'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
     798                                'trash' => array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')),
    798799                        );
    799800
    800801        $post_stati = apply_filters('post_stati', $post_stati);
  • wp-admin/includes/dashboard.php

     
    480480        $comments = array();
    481481        $start = 0;
    482482
    483         while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments ORDER BY comment_date_gmt DESC LIMIT $start, 50" ) ) {
     483        while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
    484484
    485485                foreach ( $possible as $comment ) {
    486486                        if ( count( $comments ) >= 5 )
  • wp-admin/includes/template.php

     
    14331433                case 'title':
    14341434                        $attributes = 'class="post-title column-title"' . $style;
    14351435                ?>
    1436                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
     1436                <td <?php echo $attributes ?>><strong><?php if ( current_user_can('edit_post', $post->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states($post); ?></strong>
    14371437                <?php
    14381438                        if ( 'excerpt' == $mode )
    14391439                                the_excerpt();
    14401440
    14411441                        $actions = array();
    1442                         if ( current_user_can('edit_post', $post->ID) ) {
    1443                                 $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this post')) . '">' . __('Edit') . '</a>';
    1444                                 $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
    1445                         }
    1446                         if ( current_user_can('delete_post', $post->ID) ) {
    1447                                 $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this post')) . "' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this post '%s'\n 'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
    1448                         }
    1449                         if ( in_array($post->post_status, array('pending', 'draft')) ) {
    1450                                 if ( current_user_can('edit_post', $post->ID) )
    1451                                         $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
     1442                        if ( 'trash' == $post->post_status && current_user_can('delete_post', $post->ID) ) {
     1443                                $actions['untrash'] = "<a title='" . esc_attr(__('Remove this post from the Trash')) . "' href='" . wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID) . "'>" . __('Remove from Trash') . "</a>";
     1444                                $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this post permanently')) . "' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "'>" . __('Delete Permanently') . "</a>";
    14521445                        } else {
    1453                                 $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     1446                                if ( current_user_can('edit_post', $post->ID) ) {
     1447                                        $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '" title="' . esc_attr(__('Edit this post')) . '">' . __('Edit') . '</a>';
     1448                                        $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr(__('Edit this post inline')) . '">' . __('Quick&nbsp;Edit') . '</a>';
     1449                                }
     1450                                if ( current_user_can('delete_post', $post->ID) ) {
     1451                                        $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this post to the Trash')) . "' href='" . wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID) . "'>" . __('Trash') . "</a>";
     1452                                }
     1453                                if ( in_array($post->post_status, array('pending', 'draft')) ) {
     1454                                        if ( current_user_can('edit_post', $post->ID) )
     1455                                                $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
     1456                                } else {
     1457                                        $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     1458                                }
    14541459                        }
    14551460                        $actions = apply_filters('post_row_actions', $actions, $post);
    14561461                        $action_count = count($actions);
     
    16511656                $attributes = 'class="post-title page-title column-title"' . $style;
    16521657                $edit_link = get_edit_post_link( $page->ID );
    16531658                ?>
    1654                 <td <?php echo $attributes ?>><strong><?php if ( current_user_can( 'edit_page', $page->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . __('Parent Page: ') . esc_html($parent_name) : ''; ?></strong>
     1659                <td <?php echo $attributes ?>><strong><?php if ( current_user_can('edit_page', $page->ID) && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $title)); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states($page); echo isset($parent_name) ? ' | ' . __('Parent Page: ') . esc_html($parent_name) : ''; ?></strong>
    16551660                <?php
    16561661                $actions = array();
    1657                 if ( current_user_can('edit_page', $page->ID) ) {
    1658                         $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr(__('Edit this page')) . '">' . __('Edit') . '</a>';
    1659                         $actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
    1660                 }
    1661                 if ( current_user_can('delete_page', $page->ID) ) {
    1662                         $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this page')) . "' href='" . wp_nonce_url("page.php?action=delete&amp;post=$page->ID", 'delete-page_' . $page->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf( ('draft' == $page->post_status) ? __("You are about to delete this draft '%s'\n 'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this page '%s'\n 'Cancel' to stop, 'OK' to delete."), $page->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
    1663                 }
    1664                 if ( in_array($post->post_status, array('pending', 'draft')) ) {
    1665                         if ( current_user_can('edit_page', $page->ID) )
    1666                                 $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
     1662                if ($post->post_status == 'trash' && current_user_can('delete_page', $page->ID)) {
     1663                        $actions['untrash'] = "<a title='" . esc_attr(__('Remove this page from the Trash')) . "' href='" . wp_nonce_url("page.php?action=untrash&amp;post=$page->ID", 'untrash-page_' . $page->ID) . "'>" . __('Remove from Trash') . "</a>";
     1664                        $actions['delete'] = "<a class='submitdelete' title='" . esc_attr(__('Delete this page permanently')) . "' href='" . wp_nonce_url("page.php?action=delete&amp;post=$page->ID", 'delete-page_' . $page->ID) . "'>" . __('Delete Permanently') . "</a>";
    16671665                } else {
    1668                         $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     1666                        if ( current_user_can('edit_page', $page->ID) ) {
     1667                                $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr(__('Edit this page')) . '">' . __('Edit') . '</a>';
     1668                                $actions['inline'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>';
     1669                        }
     1670                        if ( current_user_can('delete_page', $page->ID) ) {
     1671                                $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this page to the Trash')) . "' href='" . wp_nonce_url("page.php?action=trash&amp;post=$page->ID", 'trash-page_' . $page->ID) . "'>" . __('Trash') . "</a>";
     1672                        }
     1673                        if ( in_array($post->post_status, array('pending', 'draft')) ) {
     1674                                if ( current_user_can('edit_page', $page->ID) )
     1675                                        $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('Preview &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('Preview') . '</a>';
     1676                        } else {
     1677                                $actions['view'] = '<a href="' . get_permalink($page->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     1678                        }
    16691679                }
    16701680                $actions = apply_filters('page_row_actions', $actions, $page);
    16711681                $action_count = count($actions);
     
    19811991 *
    19821992 * @since unknown
    19831993 *
    1984  * @param string $status Comment status (approved, spam, deleted, etc)
     1994 * @param string $status Comment status (approved, spam, trash, etc)
    19851995 * @param string $s Term to search for
    19861996 * @param int $start Offset to start at for pagination
    19871997 * @param int $num Maximum number of comments to return
     
    19992009        $index = '';
    20002010
    20012011        if ( 'moderated' == $status ) {
    2002                 $approved = "comment_approved = '0'";
     2012                $approved = "c.comment_approved = '0'";
    20032013                $total = $count->moderated;
    20042014        } elseif ( 'approved' == $status ) {
    2005                 $approved = "comment_approved = '1'";
     2015                $approved = "c.comment_approved = '1'";
    20062016                $total = $count->approved;
    20072017        } elseif ( 'spam' == $status ) {
    2008                 $approved = "comment_approved = 'spam'";
     2018                $approved = "c.comment_approved = 'spam'";
    20092019                $total = $count->spam;
    2010         } elseif ( 'deleted' == $status ) {
    2011                 $approved = "comment_approved = 'deleted'";
    2012                 $total = $count->deleted;
     2020        } elseif ( 'trash' == $status ) {
     2021                $approved = "c.comment_approved = 'trash'";
     2022                $total = $count->trash;
    20132023        } else {
    2014                 $approved = "( comment_approved = '0' OR comment_approved = '1' )";
     2024                $approved = "( c.comment_approved = '0' OR c.comment_approved = '1' )";
    20152025                $total = $count->moderated + $count->approved;
    2016                 $index = 'USE INDEX (comment_date_gmt)';
     2026                $index = 'USE INDEX (c.comment_date_gmt)';
    20172027        }
    20182028
    20192029        if ( $post ) {
    20202030                $total = '';
    2021                 $post = " AND comment_post_ID = '$post'";
    2022                 $orderby = "ORDER BY comment_date_gmt ASC LIMIT $start, $num";
     2031                $post = " AND c.comment_post_ID = '$post'";
     2032                $orderby = "ORDER BY c.comment_date_gmt ASC LIMIT $start, $num";
    20232033        } else {
    20242034                $post = '';
    2025                 $orderby = "ORDER BY comment_date_gmt DESC LIMIT $start, $num";
     2035                $orderby = "ORDER BY c.comment_date_gmt DESC LIMIT $start, $num";
    20262036        }
    20272037
    20282038        if ( 'comment' == $type )
    2029                 $typesql = "AND comment_type = ''";
     2039                $typesql = "AND c.comment_type = ''";
    20302040        elseif ( 'pings' == $type )
    2031                 $typesql = "AND ( comment_type = 'pingback' OR comment_type = 'trackback' )";
     2041                $typesql = "AND ( c.comment_type = 'pingback' OR c.comment_type = 'trackback' )";
    20322042        elseif ( !empty($type) )
    2033                 $typesql = $wpdb->prepare("AND comment_type = %s", $type);
     2043                $typesql = $wpdb->prepare("AND c.comment_type = %s", $type);
    20342044        else
    20352045                $typesql = '';
    20362046
    20372047        if ( !empty($type) )
    20382048                $total = '';
    20392049
     2050        $query = "FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ";
    20402051        if ( $s ) {
    20412052                $total = '';
    20422053                $s = $wpdb->escape($s);
    2043                 $query = "FROM $wpdb->comments WHERE
    2044                         (comment_author LIKE '%$s%' OR
    2045                         comment_author_email LIKE '%$s%' OR
    2046                         comment_author_url LIKE ('%$s%') OR
    2047                         comment_author_IP LIKE ('%$s%') OR
    2048                         comment_content LIKE ('%$s%') ) AND
     2054                $query .= "AND
     2055                        (c.comment_author LIKE '%$s%' OR
     2056                        c.comment_author_email LIKE '%$s%' OR
     2057                        c.comment_author_url LIKE ('%$s%') OR
     2058                        c.comment_author_IP LIKE ('%$s%') OR
     2059                        c.comment_content LIKE ('%$s%') ) AND
    20492060                        $approved
    20502061                        $typesql";
    20512062        } else {
    2052                 $query = "FROM $wpdb->comments $index WHERE $approved $post $typesql";
     2063                $query .= "AND $approved $post $typesql";
    20532064        }
    2054 
     2065       
    20552066        $comments = $wpdb->get_results("SELECT * $query $orderby");
    20562067        if ( '' === $total )
    2057                 $total = $wpdb->get_var("SELECT COUNT(comment_ID) $query");
     2068                $total = $wpdb->get_var("SELECT COUNT(c.comment_ID) $query");
    20582069
    20592070        update_comment_cache($comments);
    20602071
     
    20952106        $approve_url = esc_url( wp_nonce_url( "comment.php?action=approvecomment&p=$post->ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
    20962107        $unapprove_url = esc_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$post->ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
    20972108        $spam_url = esc_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$post->ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
     2109        $trash_url = esc_url( wp_nonce_url( "comment.php?action=trashcomment&p=$post->ID&c=$comment->comment_ID", "trash-comment_$comment->comment_ID" ) );
     2110        $untrash_url = esc_url( wp_nonce_url( "comment.php?action=untrashcomment&p=$post->ID&c=$comment->comment_ID", "untrash-comment_$comment->comment_ID" ) );
    20982111
    20992112        echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
    21002113        $columns = get_column_headers('edit-comments');
     
    21342147                                $actions = array();
    21352148
    21362149                                if ( $user_can ) {
    2137                                         if ( 'deleted' == $the_comment_status ) {
    2138                                                 $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . __( 'Return this comment to Unapproved status' ) . "'>" . __( 'Return to Pending' ) . '</a>';
    2139                                                 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::deleted=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
     2150                                        if ( 'trash' == $the_comment_status ) {
     2151                                                $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID::untrash=1 vim-t vim-destructive''>" . __( 'Remove from Trash' ) . '</a>';
     2152                                                $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
    21402153                                        } else {
    21412154                                                $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
    21422155                                                $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
     
    21522165                                                }
    21532166
    21542167                                                if ( 'spam' == $the_comment_status ) {
    2155                                                         $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::deleted=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
     2168                                                        $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
    21562169                                                } else {
    21572170                                                        $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
    2158                                                         $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Move to Trash') . '</a>';
     2171                                                        $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-t vim-destructive'>" . __('Trash') . '</a>';
    21592172                                                }
    21602173
    21612174                                                $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
     
    21762189                                                // Reply and quickedit need a hide-if-no-js span when not added with ajax
    21772190                                                if ( ('reply' == $action || 'quickedit' == $action) && ! $from_ajax )
    21782191                                                        $action .= ' hide-if-no-js';
     2192                                                elseif ($action == 'untrash' && $the_comment_status == 'trash') {
     2193                                                        $trash_meta = get_option('wp_trash_meta');
     2194                                                        if (is_array($trash_meta) && isset($trash_meta['comments'][$comment_id]['status'])) {
     2195                                                                if ($trash_meta['comments'][$comment_id]['status'] == '1')
     2196                                                                        $action .= ' approve';
     2197                                                                else
     2198                                                                        $action .= ' unapprove';
     2199                                                        }
     2200                                                }
    21792201
    21802202                                                echo "<span class='$action'>$sep$link</span>";
    21812203                                        }
  • wp-admin/includes/media.php

     
    11661166                'extra_rows' => array(),
    11671167        );
    11681168
    1169         $delete_href = wp_nonce_url("post.php?action=delete-post&amp;post=$attachment_id", 'delete-post_' . $attachment_id);
     1169        $delete_href = wp_nonce_url("post.php?action=trash&amp;post=$attachment_id", 'delete-post_' . $attachment_id);
    11701170        if ( $send )
    11711171                $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />";
    11721172        if ( $delete )
    1173                 $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a>";
     1173                $delete = "<a href=\"$delete_href\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Move to Trash') . "</a>";
    11741174        if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
    1175                 $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete
    1176                 <div id=\"del_attachment_$attachment_id\" class=\"del-attachment\" style=\"display:none;\">" . sprintf(__("You are about to delete <strong>%s</strong>."), $filename) . " <a href=\"$delete_href\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Continue') . "</a>
    1177                 <a href=\"#\" class=\"del-link\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div></td></tr>\n");
     1175                $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete</td></tr>\n");
    11781176
    11791177        $hidden_fields = array();
    11801178
  • wp-admin/post.php

     
    116116        $post = get_post($post_ID);
    117117
    118118        if ( empty($post->ID) ) wp_die( __('You attempted to edit a post that doesn&#8217;t exist. Perhaps it was deleted?') );
     119        if ( $post->post_status == 'trash' ) wp_die( __('You can&#8217;t edit this post because it is in the Trash. Please move it out of the Trash and try again.') );
    119120
    120121        if ( 'post' != $post->post_type ) {
    121122                wp_redirect( get_edit_post_link( $post->ID, 'url' ) );
     
    181182        exit();
    182183        break;
    183184
     185case 'trash':
     186        $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
     187        check_admin_referer('trash-post_' . $post_id);
     188
     189        $post = & get_post($post_id);
     190
     191        if ( !current_user_can('delete_post', $post_id) )
     192                wp_die( __('You are not allowed to move this post to the trash.') );
     193
     194        if ( ! wp_trash_post($post_id) )
     195                wp_die( __('Error in moving to trash...') );
     196
     197        $sendback = wp_get_referer();
     198        if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?trashed=1');
     199        elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
     200        else $sendback = add_query_arg('trashed', 1, $sendback);
     201        wp_redirect($sendback);
     202        exit();
     203        break;
     204
     205case 'untrash':
     206        $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
     207        check_admin_referer('untrash-post_' . $post_id);
     208
     209        $post = & get_post($post_id);
     210
     211        if ( !current_user_can('delete_post', $post_id) )
     212                wp_die( __('You are not allowed to remove this post from the trash.') );
     213
     214        if ( ! wp_untrash_post($post_id) )
     215                wp_die( __('Error in removing from trash...') );
     216
     217        $sendback = wp_get_referer();
     218        if (strpos($sendback, 'post.php') !== false) $sendback = admin_url('edit.php?untrashed=1');
     219        elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
     220        else $sendback = add_query_arg('untrashed', 1, $sendback);
     221        wp_redirect($sendback);
     222        exit();
     223        break;
     224
    184225case 'delete':
    185226        $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
    186227        check_admin_referer('delete-post_' . $post_id);
  • wp-admin/js/common.dev.js

     
    154154        $('div.wrap h2 ~ div.updated, div.wrap h2 ~ div.error').addClass('below-h2');
    155155        $('div.updated, div.error').not('.below-h2').insertAfter('div.wrap h2:first');
    156156
    157         // show warnings
    158         $('#doaction, #doaction2').click(function(){
    159                 if ( $('select[name="action"]').val() == 'destroy' || $('select[name="action2"]').val() == 'destroy' ) {
    160                         return showNotice.warn();
    161                 }
    162         });
    163         $('#destroy_all, #destroy_all2').click(function(){
    164                 return showNotice.warn();
    165         });
    166 
    167157        // screen settings tab
    168158        $('#show-settings-link').click(function () {
    169159                if ( ! $('#screen-options-wrap').hasClass('screen-options-open') ) {
  • wp-admin/js/edit-comments.dev.js

     
    3838                settings.data._page = pageInput.val();
    3939                settings.data._url = document.location.href;
    4040
    41                 if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && settings.data.deleted)
    42                         return showNotice.warn() ? settings : false;
    43 
    4441                return settings;
    4542        };
    4643
     
    10198                        a.html(n);
    10299                });
    103100
    104                 $('span.deleted-count').each( function() {
     101                $('span.trash-count').each( function() {
    105102                        var a = $(this), n;
    106103                        n = a.html().replace(/[ ,.]+/g, '');
    107104                        n = parseInt(n,10);
    108105                        if ( isNaN(n) ) return;
    109                         if ( $(settings.target).parents( 'span.delete' ).size() && $('#' + settings.element).is('.deleted,.spam') ) { // we destroyed a deleted or spam comment
    110                                 n--;
    111                         } else if ( $(settings.target).parents( 'span.delete' ).size() ) { // we deleted a comment
    112                                 n++;
    113                         } else if ( $('#' + settings.element).is('.deleted') ) { // we approved or spammed a deleted comment
    114                                 n--;
     106                        if ( $(settings.target).parents( 'span.trash' ).size() ) { // we trashed a comment
     107                                n = n + 1;
     108                        } else if ( $('#' + settings.element).is('.trash') ) { // we deleted or untrashed a trash comment
     109                                n = n - 1;
    115110                        }
    116111                        if ( n < 0 ) { n = 0; }
    117112                        n = n.toString();
  • wp-admin/edit-page-form.php

     
    216216<div id="delete-action">
    217217<?php
    218218if ( ( 'edit' == $action ) && current_user_can('delete_page', $post->ID) ) { ?>
    219 <a class="submitdelete deletion" href="<?php echo wp_nonce_url("page.php?action=delete&amp;post=$post->ID", 'delete-page_' . $post->ID); ?>" onclick="if ( confirm('<?php echo esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n  'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this page '%s'\n  'Cancel' to stop, 'OK' to delete."), $post->post_title )); ?>') ) {return true;}return false;"><?php _e('Delete'); ?></a>
     219<a class="submitdelete deletion" href="<?php echo wp_nonce_url("page.php?action=trash&amp;post=$post->ID", 'trash-page_' . $post->ID); ?>"><?php _e('Move to Trash'); ?></a>
    220220<?php } ?>
    221221</div>
    222222
  • wp-admin/comment.php

     
    4444        if ( !current_user_can('edit_post', $comment->comment_post_ID) )
    4545                comment_footer_die( __('You are not allowed to edit comments on this post.') );
    4646
    47         if ( 'deleted' == $comment->comment_status )
    48                 comment_footer_die( __('This comment has been deleted. Please move it out of the Trash if you want to edit it.') );
     47        if ( 'trash' == $comment->comment_status )
     48                comment_footer_die( __('This comment is in the Trash. Please move it out of the Trash if you want to edit it.') );
    4949       
    5050        $comment = get_comment_to_edit( $comment_id );
    5151
     
    166166        die;
    167167        break;
    168168
     169case 'trashcomment' :
     170case 'untrashcomment' :
     171        $comment_id = absint( $_REQUEST['c'] );
     172        $noredir = isset($_REQUEST['noredir']);
     173       
     174        if (!$comment = get_comment($comment_id))
     175                comment_footer_die( __('Oops, no comment with this ID.') . sprintf(' <a href="%s">'.__('Go back').'</a>!', 'edit-comments.php') );
     176        if (!current_user_can('edit_post', $comment->comment_post_ID ))
     177                comment_footer_die( __('You are not allowed to edit comments on this post.') );
     178       
     179        if ($action == 'trashcomment') {
     180                check_admin_referer( 'trash-comment_' . $comment_id );
     181                wp_trash_comment($comment_id);
     182        }
     183        else {
     184                check_admin_referer( 'untrash-comment_' . $comment_id );
     185                wp_untrash_comment($comment_id);
     186        }
     187       
     188        if ('' != wp_get_referer() && false == $noredir && false === strpos(wp_get_referer(), 'comment.php' ))
     189                wp_redirect( wp_get_referer() );
     190        else if ('' != wp_get_original_referer() && false == $noredir)
     191                wp_redirect(wp_get_original_referer());
     192        else
     193                wp_redirect(admin_url('edit-comments.php'));
     194
     195        die;
     196        break;
     197
    169198case 'unapprovecomment' :
    170199        $comment_id = absint( $_GET['c'] );
    171200        check_admin_referer( 'unapprove-comment_' . $comment_id );
  • wp-admin/edit-attachment-rows.php

     
    2929$posts_columns = get_column_headers('upload');
    3030$hidden = get_hidden_columns('upload');
    3131while (have_posts()) : the_post();
     32if ($is_trash && $post->post_status != 'trash') continue;
     33elseif (!$is_trash && $post->post_status == 'trash') continue;
    3234$alt = ( 'alternate' == $alt ) ? '' : 'alternate';
    3335global $current_user;
    3436$post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
     
    6062                ?>
    6163                <td <?php echo $attributes ?>><?php
    6264                        if ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) {
     65                                if ($is_trash) echo $thumb;
     66                                else {
    6367?>
    64 
    6568                                <a href="media.php?action=edit&amp;attachment_id=<?php the_ID(); ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>">
    6669                                        <?php echo $thumb; ?>
    6770                                </a>
    6871
    6972<?php                   }
     73                        }
    7074                ?></td>
    7175                <?php
    7276                // TODO
     
    7478
    7579        case 'media':
    7680                ?>
    77                 <td <?php echo $attributes ?>><strong><a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>"><?php echo $att_title; ?></a></strong><br />
     81                <td <?php echo $attributes ?>><strong><?php if ($is_trash) echo $att_title; else { ?><a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo esc_attr(sprintf(__('Edit &#8220;%s&#8221;'), $att_title)); ?>"><?php echo $att_title; ?></a><?php } ?></strong><br />
    7882                <?php echo strtoupper(preg_replace('/^.*?\.(\w+)$/', '$1', get_attached_file($post->ID))); ?>
    7983                <p>
    8084                <?php
    8185                $actions = array();
    82                 if ( current_user_can('edit_post', $post->ID) )
    83                         $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '">' . __('Edit') . '</a>';
    84                 if ( current_user_can('delete_post', $post->ID) )
    85                         $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this attachment '%s'\n  'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this attachment '%s'\n  'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
    86                 $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     86                if ($is_trash && current_user_can('delete_post', $post->ID)) {
     87                        $actions['untrash'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=untrash&amp;post=$post->ID", 'untrash-post_' . $post->ID) . "'>" . __('Remove from Trash') . "</a>";
     88                        $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "'>" . __('Delete Permanently') . "</a>";
     89                } else {
     90                        if (current_user_can('edit_post', $post->ID))
     91                                $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '">' . __('Edit') . '</a>';
     92                        if (current_user_can('delete_post', $post->ID))
     93                                $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID) . "'>" . __('Trash') . "</a>";
     94                        $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
     95                }
    8796                $action_count = count($actions);
    8897                $i = 0;
    8998                echo '<div class="row-actions">';
  • wp-admin/media.php

     
    5858
    5959        $att = get_post($att_id);
    6060
     61        if ( empty($att->ID) ) wp_die( __('You attempted to edit an attachment that doesn&#8217;t exist. Perhaps it was deleted?') );
     62        if ( $att->post_status == 'trash' ) wp_die( __('You can&#8217;t edit this attachment because it is in the Trash. Please move it out of the Trash and try again.') );
     63       
    6164        add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
    6265
    6366        wp_enqueue_script( 'wp-ajax-response' );
  • wp-admin/upload.php

     
    6767                exit;
    6868        }
    6969
    70 } elseif ( isset($_GET['action']) && isset($_GET['media']) && ( -1 != $_GET['action'] || -1 != $_GET['action2'] ) ) {
     70} elseif ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
    7171        check_admin_referer('bulk-media');
    72         $doaction = ( -1 != $_GET['action'] ) ? $_GET['action'] : $_GET['action2'];
     72       
     73        if (isset($_GET['delete_all']) || isset($_GET['delete_all2'])) {
     74                $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='attachment' AND post_status = 'trash'" );
     75                $doaction = 'delete';
     76        } elseif (($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['media'])) {
     77                $post_ids = $_GET['media'];
     78                $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
     79        } else wp_redirect($_SERVER['HTTP_REFERER']);
     80       
     81        $location = 'upload.php';
     82        if ( $referer = wp_get_referer() ) {
     83                if ( false !== strpos($referer, 'upload.php') )
     84                        $location = $referer;
     85        }
    7386
    74         if ( 'delete' == $doaction ) {
    75                 foreach( (array) $_GET['media'] as $post_id_del ) {
    76                         $post_del = & get_post($post_id_del);
    77 
    78                         if ( !current_user_can('delete_post', $post_id_del) )
    79                                 wp_die( __('You are not allowed to delete this post.') );
    80 
    81                         if ( $post_del->post_type == 'attachment' )
    82                                 if ( ! wp_delete_attachment($post_id_del) )
     87        switch ( $doaction ) {
     88                case 'trash':
     89                        foreach( (array) $post_ids as $post_id ) {
     90                                if ( !current_user_can('delete_post', $post_id) )
     91                                        wp_die( __('You are not allowed to move this post to the trash.') );
     92                               
     93                                if ( !wp_trash_post($post_id) )
     94                                        wp_die( __('Error in moving to trash...') );
     95                        }
     96                        $location = add_query_arg('message', 4, $location);
     97                        break;
     98                case 'untrash':
     99                        foreach( (array) $post_ids as $post_id ) {
     100                                if ( !current_user_can('delete_post', $post_id) )
     101                                        wp_die( __('You are not allowed to remove this post from the trash.') );
     102                               
     103                                if ( !wp_untrash_post($post_id) )
     104                                        wp_die( __('Error in removing from trash...') );
     105                        }
     106                        $location = add_query_arg('message', 5, $location);
     107                        break;
     108                case 'delete':
     109                        foreach( (array) $post_ids as $post_id_del ) {
     110                                if ( !current_user_can('delete_post', $post_id_del) )
     111                                        wp_die( __('You are not allowed to delete this post.') );
     112       
     113                                if ( !wp_delete_attachment($post_id_del) )
    83114                                        wp_die( __('Error in deleting...') );
    84                 }
     115                        }
     116                        $location = add_query_arg('message', 2, $location);
     117                        break;
     118        }
    85119
    86                 $location = 'upload.php';
    87                 if ( $referer = wp_get_referer() ) {
    88                         if ( false !== strpos($referer, 'upload.php') )
    89                                 $location = $referer;
    90                 }
    91 
    92                 $location = add_query_arg('message', 2, $location);
    93                 $location = remove_query_arg('posted', $location);
    94                 wp_redirect($location);
    95                 exit;
    96         }
     120        $location = remove_query_arg('posted', $location);
     121        wp_redirect($location);
     122        exit;
    97123} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
    98124         wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
    99125         exit;
     
    115141                $orphans = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'attachment' AND ID IN ($lost) LIMIT $start, 50" );
    116142        } else {
    117143                $start = ( $_GET['paged'] - 1 ) * 25;
    118                 $orphans = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent < 1 LIMIT $start, 25" );
     144                $orphans = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT $start, 25" );
    119145                $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / 25);
    120146        }
    121147
     
    135161        list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
    136162}
    137163
     164$is_trash = (isset($_GET['status']) && $_GET['status'] == 'trash');
     165
    138166wp_enqueue_script('media');
    139167require_once('admin-header.php'); ?>
    140168
     
    153181$messages[1] = __('Media attachment updated.');
    154182$messages[2] = __('Media deleted.');
    155183$messages[3] = __('Error saving media attachment.');
     184$messages[4] = __('Media moved to Trash.');
     185$messages[5] = __('Media removed from Trash.');
    156186
    157187if ( isset($_GET['message']) && (int) $_GET['message'] ) {
    158188        $message = $messages[$_GET['message']];
     
    180210<?php
    181211$type_links = array();
    182212$_num_posts = (array) wp_count_attachments();
    183 $_total_posts = array_sum( $_num_posts );
     213$_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
    184214$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
    185215foreach ( $matches as $type => $reals )
    186216        foreach ( $reals as $real )
    187217                $num_posts[$type] = ( isset( $num_posts[$type] ) ) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
    188218
    189 $class = empty($_GET['post_mime_type']) && ! isset($_GET['detached']) ? ' class="current"' : '';
     219$class = (empty($_GET['post_mime_type']) && !isset($_GET['detached']) && !isset($_GET['status'])) ? ' class="current"' : '';
    190220$type_links[] = "<li><a href='upload.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $_total_posts, 'uploaded files' ), number_format_i18n( $_total_posts ) ) . '</a>';
    191221foreach ( $post_mime_types as $mime_type => $label ) {
    192222        $class = '';
     
    199229
    200230        $type_links[] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
    201231}
    202 $class = isset($_GET['detached']) ? ' class="current"' : '';
    203 $type_links[] = '<li><a href="upload.php?detached=1"' . $class . '>' . __('Unattached') . '</a>';
     232$type_links[] = '<li><a href="upload.php?detached=1"' . (isset($_GET['detached']) ? ' class="current"' : '') . '>' . __('Unattached') . '</a>';
     233$type_links[] = '<li><a href="upload.php?status=trash"' . ((isset($_GET['status']) && $_GET['status'] == 'trash') ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>';
    204234
    205235echo implode( " |</li>\n", $type_links) . '</li>';
    206236unset($type_links);
     
    242272<div class="alignleft actions">
    243273<select name="action" class="select-action">
    244274<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
    245 <option value="delete"><?php _e('Delete'); ?></option>
    246 <?php if ( isset($orphans) ) { ?>
     275<?php if ($is_trash) { ?>
     276<option value="untrash"><?php _e('Remove from Trash'); ?></option>
     277<option value="delete"><?php _e('Delete Permanently'); ?></option>
     278<?php } else { ?>
     279<option value="trash"><?php _e('Move to Trash'); ?></option>
     280<?php } if (isset($orphans)) { ?>
    247281<option value="attach"><?php _e('Attach to a post'); ?></option>
    248282<?php } ?>
    249283</select>
     
    251285<?php wp_nonce_field('bulk-media'); ?>
    252286
    253287<?php
    254 if ( ! is_singular() && ! isset($_GET['detached']) ) {
     288if ( !is_singular() && !isset($_GET['detached']) && !$is_trash ) {
    255289        $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";
    256290
    257291        $arc_result = $wpdb->get_results( $arc_query );
     
    286320
    287321<?php if ( isset($_GET['detached']) ) { ?>
    288322        <input type="submit" id="find_detached" name="find_detached" value="<?php esc_attr_e('Scan for lost attachments'); ?>" class="button-secondary" />
     323<?php } elseif ( isset($_GET['status']) && $_GET['status'] == 'trash' ) { ?>
     324        <input type="submit" id="delete_all" name="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
    289325<?php } ?>
    290326
    291327</div>
     
    341377                if ( current_user_can('edit_post', $post->ID) )
    342378                        $actions['edit'] = '<a href="' . get_edit_post_link($post->ID, true) . '">' . __('Edit') . '</a>';
    343379                if ( current_user_can('delete_post', $post->ID) )
    344                         $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID) . "' onclick=\"if ( confirm('" . esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this attachment '%s'\n  'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this attachment '%s'\n  'Cancel' to stop, 'OK' to delete."), $post->post_title )) . "') ) { return true;}return false;\">" . __('Delete') . "</a>";
     380                        $actions['trash'] = "<a class='submitdelete' href='" . wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID) . "'>" . __('Trash') . "</a>";
    345381                $actions['view'] = '<a href="' . get_permalink($post->ID) . '" title="' . esc_attr(sprintf(__('View &#8220;%s&#8221;'), $title)) . '" rel="permalink">' . __('View') . '</a>';
    346382                if ( current_user_can('edit_post', $post->ID) )
    347383                        $actions['attach'] = '<a href="#the-list" onclick="findPosts.open(\'media[]\',\''.$post->ID.'\');return false;">'.__('Attach').'</a>';
     
    398434<div class="alignleft actions">
    399435<select name="action2" class="select-action">
    400436<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
    401 <option value="delete"><?php _e('Delete'); ?></option>
    402 <?php if ( isset($orphans) ) { ?>
     437<?php if ($is_trash) { ?>
     438<option value="untrash"><?php _e('Remove from Trash'); ?></option>
     439<option value="delete"><?php _e('Delete Permanently'); ?></option>
     440<?php } else { ?>
     441<option value="trash"><?php _e('Move to Trash'); ?></option>
     442<?php } if (isset($orphans)) { ?>
    403443<option value="attach"><?php _e('Attach to a post'); ?></option>
    404444<?php } ?>
    405445</select>
    406446<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
     447
     448<?php if ( isset($_GET['status']) && $_GET['status'] == 'trash' ) { ?>
     449        <input type="submit" id="delete_all2" name="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
     450<?php } ?>
    407451</div>
    408452
    409453<br class="clear" />
  • wp-admin/edit-form-comment.php

     
    6464
    6565<div id="major-publishing-actions">
    6666<div id="delete-action">
    67 <?php echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "' onclick=\"if ( confirm('" . esc_js(__("You are about to delete this comment. \n  'Cancel' to stop, 'OK' to delete.")) . "') ){return true;}return false;\">" . __('Delete') . "</a>\n"; ?>
     67<?php echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "'>" . __('Move to Trash') . "</a>\n"; ?>
    6868</div>
    6969<div id="publishing-action">
    7070<input type="submit" name="save" value="<?php esc_attr_e('Update Comment'); ?>" tabindex="4" class="button-primary" />
  • wp-admin/edit-form-advanced.php

     
    229229<div id="delete-action">
    230230<?php
    231231if ( ( 'edit' == $action ) && current_user_can('delete_post', $post->ID) ) { ?>
    232 <a class="submitdelete deletion" href="<?php echo wp_nonce_url("post.php?action=delete&amp;post=$post->ID", 'delete-post_' . $post->ID); ?>" onclick="if ( confirm('<?php echo esc_js(sprintf( ('draft' == $post->post_status) ? __("You are about to delete this draft '%s'\n  'Cancel' to stop, 'OK' to delete.") : __("You are about to delete this post '%s'\n  'Cancel' to stop, 'OK' to delete."), $post->post_title )); ?>') ) {return true;}return false;"><?php _e('Delete'); ?></a>
     232<a class="submitdelete deletion" href="<?php echo wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID); ?>"><?php _e('Move to Trash'); ?></a>
    233233<?php } ?>
    234234</div>
    235235
  • wp-admin/edit.php

     
    1818}
    1919
    2020// Handle bulk actions
    21 if ( isset($_GET['action']) && ( -1 != $_GET['action'] || -1 != $_GET['action2'] ) ) {
    22         $doaction = ( -1 != $_GET['action'] ) ? $_GET['action'] : $_GET['action2'];
    23 
     21if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
     22        check_admin_referer('bulk-posts');
     23       
     24        if (isset($_GET['delete_all']) || isset($_GET['delete_all2'])) {
     25                $post_status = $wpdb->escape($_GET['post_status']);
     26                $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = '$post_status'" );
     27                $doaction = 'delete';
     28        } elseif (($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post'])) {
     29                $post_ids = $_GET['post'];
     30                $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
     31        } else wp_redirect($_SERVER['HTTP_REFERER']);
     32       
    2433        switch ( $doaction ) {
    25                 case 'delete':
    26                         if ( isset($_GET['post']) && ! isset($_GET['bulk_edit']) && (isset($_GET['doaction']) || isset($_GET['doaction2'])) ) {
    27                                 check_admin_referer('bulk-posts');
    28                                 $deleted = 0;
    29                                 foreach( (array) $_GET['post'] as $post_id_del ) {
    30                                         $post_del = & get_post($post_id_del);
     34                case 'trash':
     35                        $trashed = 0;
     36                        foreach( (array) $post_ids as $post_id ) {
     37                                $post_del = & get_post($post_id);
    3138
    32                                         if ( !current_user_can('delete_post', $post_id_del) )
    33                                                 wp_die( __('You are not allowed to delete this post.') );
     39                                if ( !current_user_can('delete_post', $post_id_del) )
     40                                        wp_die( __('You are not allowed to move this post to the trash.') );
    3441
    35                                         if ( $post_del->post_type == 'attachment' ) {
    36                                                 if ( ! wp_delete_attachment($post_id_del) )
    37                                                         wp_die( __('Error in deleting...') );
    38                                         } else {
    39                                                 if ( !wp_delete_post($post_id_del) )
    40                                                         wp_die( __('Error in deleting...') );
    41                                         }
    42                                         $deleted++;
    43                                 }
     42                                if ( !wp_trash_post($post_id) )
     43                                        wp_die( __('Error in moving to trash...') );
     44                               
     45                                $trashed++;
    4446                        }
    4547                        break;
    46                 case 'edit':
    47                         if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
    48                                 check_admin_referer('bulk-posts');
     48                case 'untrash':
     49                        $untrashed = 0;
     50                        foreach( (array) $post_ids as $post_id ) {
     51                                $post_del = & get_post($post_id);
    4952
    50                                 if ( -1 == $_GET['_status'] ) {
    51                                         $_GET['post_status'] = null;
    52                                         unset($_GET['_status'], $_GET['post_status']);
     53                                if ( !current_user_can('delete_post', $post_id_del) )
     54                                        wp_die( __('You are not allowed to remove this post from the trash.') );
     55
     56                                if ( !wp_untrash_post($post_id) )
     57                                        wp_die( __('Error in removing from trash...') );
     58                               
     59                                $untrashed++;
     60                        }
     61                        break;
     62                case 'delete':
     63                        $deleted = 0;
     64                        foreach( (array) $post_ids as $post_id_del ) {
     65                                $post_del = & get_post($post_id_del);
     66
     67                                if ( !current_user_can('delete_post', $post_id_del) )
     68                                        wp_die( __('You are not allowed to delete this post.') );
     69
     70                                if ( $post_del->post_type == 'attachment' ) {
     71                                        if ( ! wp_delete_attachment($post_id_del) )
     72                                                wp_die( __('Error in deleting...') );
    5373                                } else {
    54                                         $_GET['post_status'] = $_GET['_status'];
     74                                        if ( !wp_delete_post($post_id_del) )
     75                                                wp_die( __('Error in deleting...') );
    5576                                }
    56 
    57                                 $done = bulk_edit_posts($_GET);
     77                                $deleted++;
    5878                        }
    5979                        break;
     80                case 'edit':
     81                        if ( -1 == $_GET['_status'] ) {
     82                                $_GET['post_status'] = null;
     83                                unset($_GET['_status'], $_GET['post_status']);
     84                        } else {
     85                                $_GET['post_status'] = $_GET['_status'];
     86                        }
     87
     88                        $done = bulk_edit_posts($_GET);
     89                        break;
    6090        }
    6191
    6292        $sendback = wp_get_referer();
     
    6898                $done['locked'] = count( $done['locked'] );
    6999                $sendback = add_query_arg( $done, $sendback );
    70100        }
    71         if ( isset($deleted) )
     101        if (isset($deleted))
    72102                $sendback = add_query_arg('deleted', $deleted, $sendback);
     103        elseif (isset($trashed))
     104                $sendback = add_query_arg('trashed', $trashed, $sendback);
     105        elseif (isset($untrashed))
     106                $sendback = add_query_arg('untrashed', $untrashed, $sendback);
    73107        wp_redirect($sendback);
    74108        exit();
    75109} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
     
    107141<?php $_SERVER['REQUEST_URI'] = remove_query_arg(array('posted'), $_SERVER['REQUEST_URI']);
    108142endif; ?>
    109143
    110 <?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) ) { ?>
     144<?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) ) { ?>
    111145<div id="message" class="updated fade"><p>
    112146<?php if ( isset($_GET['updated']) && (int) $_GET['updated'] ) {
    113147        printf( _n( '%s post updated.', '%s posts updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
     
    123157}
    124158
    125159if ( isset($_GET['deleted']) && (int) $_GET['deleted'] ) {
    126         printf( _n( 'Post deleted.', '%s posts deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
     160        printf( _n( 'Post permanently deleted.', '%s posts permanently deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
    127161        unset($_GET['deleted']);
    128162}
    129163
     164if ( isset($_GET['trashed']) && (int) $_GET['trashed'] ) {
     165        printf( _n( 'Post moved to the trash.', '%s posts moved to the trash.', $_GET['trashed'] ), number_format_i18n( $_GET['trashed'] ) );
     166        unset($_GET['deleted']);
     167}
     168
     169if ( isset($_GET['untrashed']) && (int) $_GET['untrashed'] ) {
     170        printf( _n( 'Post removed from the trash.', '%s posts removed from the trash.', $_GET['untrashed'] ), number_format_i18n( $_GET['untrashed'] ) );
     171        unset($_GET['undeleted']);
     172}
     173
    130174$_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted'), $_SERVER['REQUEST_URI'] );
    131175?>
    132176</p></div>
     
    139183if ( empty($locked_post_status) ) :
    140184$status_links = array();
    141185$num_posts = wp_count_posts( 'post', 'readable' );
    142 $total_posts = array_sum( (array) $num_posts );
     186$total_posts = array_sum( (array) $num_posts ) - $num_posts->trash;
    143187$class = empty( $_GET['post_status'] ) ? ' class="current"' : '';
    144188$status_links[] = "<li><a href='edit.php' $class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
    145189
     
    190234<div class="alignleft actions">
    191235<select name="action">
    192236<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
     237<?php if ($_GET['post_status'] == 'trash') { ?>
     238<option value="untrash"><?php _e('Remove from Trash'); ?></option>
     239<option value="delete"><?php _e('Delete Permanently'); ?></option>
     240<?php } else { ?>
    193241<option value="edit"><?php _e('Edit'); ?></option>
    194 <option value="delete"><?php _e('Delete'); ?></option>
     242<option value="trash"><?php _e('Move to Trash'); ?></option>
     243<?php } ?>
    195244</select>
    196245<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
    197246<?php wp_nonce_field('bulk-posts'); ?>
     
    235284do_action('restrict_manage_posts');
    236285?>
    237286<input type="submit" id="post-query-submit" value="<?php esc_attr_e('Filter'); ?>" class="button-secondary" />
    238 
     287<?php } if ($_GET['post_status'] == 'trash') { ?>
     288<input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
    239289<?php } ?>
    240290</div>
    241291
     
    270320<div class="alignleft actions">
    271321<select name="action2">
    272322<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
     323<?php if ($_GET['post_status'] == 'trash') { ?>
     324<option value="untrash"><?php _e('Remove from Trash'); ?></option>
     325<option value="delete"><?php _e('Delete Permanently'); ?></option>
     326<?php } else { ?>
    273327<option value="edit"><?php _e('Edit'); ?></option>
    274 <option value="delete"><?php _e('Delete'); ?></option>
     328<option value="trash"><?php _e('Move to Trash'); ?></option>
     329<?php } ?>
    275330</select>
    276331<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
     332<?php if ($_GET['post_status'] == 'trash') { ?>
     333<input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
     334<?php } ?>
    277335<br class="clear" />
    278336</div>
    279337<br class="clear" />
  • wp-admin/page.php

     
    8383        $post = get_post_to_edit($page_ID);
    8484
    8585        if ( empty($post->ID) ) wp_die( __('You attempted to edit a page that doesn&#8217;t exist. Perhaps it was deleted?') );
     86        if ( $post->post_status == 'trash' ) wp_die( __('You can&#8217;t edit this page because it is in the Trash. Please move it out of the Trash and try again.') );
    8687
    8788        if ( 'page' != $post->post_type ) {
    8889                wp_redirect( get_edit_post_link( $post_ID, 'url' ) );
     
    140141        exit();
    141142        break;
    142143
     144case 'trash':
     145        $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
     146        check_admin_referer('trash-page_' . $post_id);
     147
     148        $post = & get_post($post_id);
     149
     150        if ( !current_user_can('delete_page', $page_id) )
     151                wp_die( __('You are not allowed to move this page to the trash.') );
     152
     153        if ( !wp_trash_post($post_id) )
     154                wp_die( __('Error in removing from trash...') );
     155
     156        $sendback = wp_get_referer();
     157        if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?trashed=1');
     158        elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
     159        else $sendback = add_query_arg('trashed', 1, $sendback);
     160        wp_redirect($sendback);
     161        exit();
     162        break;
     163
     164case 'untrash':
     165        $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
     166        check_admin_referer('untrash-page_' . $post_id);
     167
     168        $post = & get_post($post_id);
     169
     170        if ( !current_user_can('delete_page', $page_id) )
     171                wp_die( __('You are not allowed to remove this page form the trash.') );
     172
     173        if ( !wp_untrash_post($post_id) )
     174                wp_die( __('Error in removing from trash...') );
     175
     176        $sendback = wp_get_referer();
     177        if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('edit-pages.php?untrashed=1');
     178        elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
     179        else $sendback = add_query_arg('untrashed', 1, $sendback);
     180        wp_redirect($sendback);
     181        exit();
     182        break;
     183
    143184case 'delete':
    144185        $page_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
    145186        check_admin_referer('delete-page_' .  $page_id);
  • wp-admin/edit-pages.php

     
    1010require_once('admin.php');
    1111
    1212// Handle bulk actions
    13 if ( isset($_GET['action']) && ( -1 != $_GET['action'] || -1 != $_GET['action2'] ) ) {
    14         $doaction = ( -1 != $_GET['action'] ) ? $_GET['action'] : $_GET['action2'];
     13if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
     14        check_admin_referer('bulk-pages');
     15       
     16        if (isset($_GET['delete_all']) || isset($_GET['delete_all2'])) {
     17                $post_status = $wpdb->escape($_GET['post_status']);
     18                $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = '$post_status'" );
     19                $doaction = 'delete';
     20        } elseif (($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post'])) {
     21                $post_ids = $_GET['post'];
     22                $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
     23        } else wp_redirect($_SERVER['HTTP_REFERER']);
    1524
    1625        switch ( $doaction ) {
    17                 case 'delete':
    18                         if ( isset($_GET['post']) && ! isset($_GET['bulk_edit']) && (isset($_GET['doaction']) || isset($_GET['doaction2'])) ) {
    19                                 check_admin_referer('bulk-pages');
    20                                 $deleted = 0;
    21                                 foreach( (array) $_GET['post'] as $post_id_del ) {
    22                                         $post_del = & get_post($post_id_del);
     26                case 'trash':
     27                        $trashed = 0;
     28                        foreach( (array) $post_ids as $post_id ) {
     29                                if ( !current_user_can('delete_page', $post_id) )
     30                                        wp_die( __('You are not allowed to move this page to the trash.') );
    2331
    24                                         if ( !current_user_can('delete_page', $post_id_del) )
    25                                                 wp_die( __('You are not allowed to delete this page.') );
     32                                if ( !wp_trash_post($post_id) )
     33                                        wp_die( __('Error in moving to trash...') );
     34                               
     35                                $trashed++;
     36                        }
     37                        break;
     38                case 'untrash':
     39                        $untrashed = 0;
     40                        foreach( (array) $post_ids as $post_id ) {
     41                                if ( !current_user_can('delete_page', $post_id) )
     42                                        wp_die( __('You are not allowed to remove this page from the trash.') );
    2643
    27                                         if ( $post_del->post_type == 'attachment' ) {
    28                                                 if ( ! wp_delete_attachment($post_id_del) )
    29                                                         wp_die( __('Error in deleting...') );
    30                                         } else {
    31                                                 if ( !wp_delete_post($post_id_del) )
    32                                                         wp_die( __('Error in deleting...') );
    33                                         }
    34                                         $deleted++;
    35                                 }
     44                                if ( !wp_untrash_post($post_id) )
     45                                        wp_die( __('Error in removing from trash...') );
     46                               
     47                                $untrashed++;
    3648                        }
    3749                        break;
    38                 case 'edit':
    39                         if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
    40                                 check_admin_referer('bulk-pages');
     50                case 'delete':
     51                        $deleted = 0;
     52                        foreach( (array) $post_ids as $post_id_del ) {
     53                                $post_del = & get_post($post_id_del);
    4154
    42                                 if ( -1 == $_GET['_status'] ) {
    43                                         $_GET['post_status'] = null;
    44                                         unset($_GET['_status'], $_GET['post_status']);
     55                                if ( !current_user_can('delete_page', $post_id_del) )
     56                                        wp_die( __('You are not allowed to delete this page.') );
     57
     58                                if ( $post_del->post_type == 'attachment' ) {
     59                                        if ( ! wp_delete_attachment($post_id_del) )
     60                                                wp_die( __('Error in deleting...') );
    4561                                } else {
    46                                         $_GET['post_status'] = $_GET['_status'];
     62                                        if ( !wp_delete_post($post_id_del) )
     63                                                wp_die( __('Error in deleting...') );
    4764                                }
    48 
    49                                 $done = bulk_edit_posts($_GET);
     65                                $deleted++;
    5066                        }
    5167                        break;
     68                case 'edit':
     69                        if ( -1 == $_GET['_status'] ) {
     70                                $_GET['post_status'] = null;
     71                                unset($_GET['_status'], $_GET['post_status']);
     72                        } else {
     73                                $_GET['post_status'] = $_GET['_status'];
     74                        }
     75
     76                        $done = bulk_edit_posts($_GET);
     77                        break;
    5278        }
    5379
    5480        $sendback = wp_get_referer();
     
    6288        }
    6389        if ( isset($deleted) )
    6490                $sendback = add_query_arg('deleted', $deleted, $sendback);
     91        elseif ( isset($trashed) )
     92                $sendback = add_query_arg('trashed', $trashed, $sendback);
     93        elseif ( isset($untrashed) )
     94                $sendback = add_query_arg('untrashed', $untrashed, $sendback);
    6595        wp_redirect($sendback);
    6696        exit();
    6797} elseif ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) {
     
    79109                'future' => array(_x('Scheduled', 'page'), __('Scheduled pages'), _nx_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>', 'page')),
    80110                'pending' => array(_x('Pending Review', 'page'), __('Pending pages'), _nx_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>', 'page')),
    81111                'draft' => array(_x('Draft', 'page'), _x('Drafts', 'manage posts header'), _nx_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>', 'page')),
    82                 'private' => array(_x('Private', 'page'), __('Private pages'), _nx_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', 'page'))
     112                'private' => array(_x('Private', 'page'), __('Private pages'), _nx_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', 'page')),
     113                'trash' => array(_x('Trash', 'page'), __('Trash pages'), _nx_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', 'page'))
    83114        );
    84115
    85116$post_stati = apply_filters('page_stati', $post_stati);
     
    111142        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( get_search_query() ) ); ?>
    112143</h2>
    113144
    114 <?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) ) { ?>
     145<?php if ( isset($_GET['locked']) || isset($_GET['skipped']) || isset($_GET['updated']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) ) { ?>
    115146<div id="message" class="updated fade"><p>
    116147<?php if ( isset($_GET['updated']) && (int) $_GET['updated'] ) {
    117148        printf( _n( '%s page updated.', '%s pages updated.', $_GET['updated'] ), number_format_i18n( $_GET['updated'] ) );
    118149        unset($_GET['updated']);
    119150}
    120 
    121151if ( isset($_GET['skipped']) && (int) $_GET['skipped'] ) {
    122152        printf( _n( '%s page not updated, invalid parent page specified.', '%s pages not updated, invalid parent page specified.', $_GET['skipped'] ), number_format_i18n( $_GET['skipped'] ) );
    123153        unset($_GET['skipped']);
    124154}
    125 
    126155if ( isset($_GET['locked']) && (int) $_GET['locked'] ) {
    127156        printf( _n( '%s page not updated, somebody is editing it.', '%s pages not updated, somebody is editing them.', $_GET['locked'] ), number_format_i18n( $_GET['skipped'] ) );
    128157        unset($_GET['locked']);
    129158}
    130 
    131159if ( isset($_GET['deleted']) && (int) $_GET['deleted'] ) {
    132         printf( _n( 'Page deleted.', '%s pages deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
     160        printf( _n( 'Page permanently deleted.', '%s pages permanently deleted.', $_GET['deleted'] ), number_format_i18n( $_GET['deleted'] ) );
    133161        unset($_GET['deleted']);
    134162}
    135 $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted'), $_SERVER['REQUEST_URI'] );
     163if ( isset($_GET['trashed']) && (int) $_GET['trashed'] ) {
     164        printf( _n( 'Page moved to the trash.', '%s pages moved to the trash.', $_GET['trashed'] ), number_format_i18n( $_GET['trashed'] ) );
     165        unset($_GET['trashed']);
     166}
     167if ( isset($_GET['untrashed']) && (int) $_GET['untrashed'] ) {
     168        printf( _n( 'Page removed from the trash.', '%s pages removed from the trash.', $_GET['untrashed'] ), number_format_i18n( $_GET['untrashed'] ) );
     169        unset($_GET['untrashed']);
     170}
     171$_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated', 'deleted', 'trashed', 'untrashed'), $_SERVER['REQUEST_URI'] );
    136172?>
    137173</p></div>
    138174<?php } ?>
     
    150186if ( empty($locked_post_status) ) :
    151187$status_links = array();
    152188$num_posts = wp_count_posts('page', 'readable');
    153 $total_posts = array_sum( (array) $num_posts );
     189$total_posts = array_sum( (array) $num_posts ) - $num_posts->trash;
    154190$class = empty($_GET['post_status']) ? ' class="current"' : '';
    155191$status_links[] = "<li><a href='edit-pages.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'pages' ), number_format_i18n( $total_posts ) ) . '</a>';
    156192foreach ( $post_stati as $status => $label ) {
     
    212248<div class="alignleft actions">
    213249<select name="action">
    214250<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
     251<?php if ($_GET['post_status'] == 'trash') { ?>
     252<option value="untrash"><?php _e('Remove from Trash'); ?></option>
     253<option value="delete"><?php _e('Delete Permanently'); ?></option>
     254<?php } else { ?>
    215255<option value="edit"><?php _e('Edit'); ?></option>
    216 <option value="delete"><?php _e('Delete'); ?></option>
     256<option value="trash"><?php _e('Move to Trash'); ?></option>
     257<?php } ?>
    217258</select>
    218259<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
    219260<?php wp_nonce_field('bulk-pages'); ?>
     261<?php if ($_GET['post_status'] == 'trash') { ?>
     262<input type="submit" name="delete_all" id="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
     263<?php } ?>
    220264</div>
    221265
    222266<br class="clear" />
     
    251295<div class="alignleft actions">
    252296<select name="action2">
    253297<option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
     298<?php if ($_GET['post_status'] == 'trash') { ?>
     299<option value="untrash"><?php _e('Remove from Trash'); ?></option>
     300<option value="delete"><?php _e('Delete Permanently'); ?></option>
     301<?php } else { ?>
    254302<option value="edit"><?php _e('Edit'); ?></option>
    255 <option value="delete"><?php _e('Delete'); ?></option>
     303<option value="trash"><?php _e('Move to Trash'); ?></option>
     304<?php } ?>
    256305</select>
    257306<input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
     307<?php if ($_GET['post_status'] == 'trash') { ?>
     308<input type="submit" name="delete_all2" id="delete_all2" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
     309<?php } ?>
    258310</div>
    259311
    260312<br class="clear" />