WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/30/2009 01:39:34 PM (12 years ago)
Author:
azaozz
Message:

Trash status updates for posts, pages, comments and attachments, props caesarsgrunt, see #4529

File:
1 edited

Legend:

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

    r11743 r11749  
    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 ) {
     34        case 'trash':
     35            $trashed = 0;
     36            foreach( (array) $post_ids as $post_id ) {
     37                $post_del = & get_post($post_id);
     38
     39                if ( !current_user_can('delete_post', $post_id_del) )
     40                    wp_die( __('You are not allowed to move this post to the trash.') );
     41
     42                if ( !wp_trash_post($post_id) )
     43                    wp_die( __('Error in moving to trash...') );
     44               
     45                $trashed++;
     46            }
     47            break;
     48        case 'untrash':
     49            $untrashed = 0;
     50            foreach( (array) $post_ids as $post_id ) {
     51                $post_del = & get_post($post_id);
     52
     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;
    2562        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);
    31 
    32                     if ( !current_user_can('delete_post', $post_id_del) )
    33                         wp_die( __('You are not allowed to delete this post.') );
    34 
    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++;
     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...') );
     73                } else {
     74                    if ( !wp_delete_post($post_id_del) )
     75                        wp_die( __('Error in deleting...') );
    4376                }
     77                $deleted++;
    4478            }
    4579            break;
    4680        case 'edit':
    47             if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
    48                 check_admin_referer('bulk-posts');
    49 
    50                 if ( -1 == $_GET['_status'] ) {
    51                     $_GET['post_status'] = null;
    52                     unset($_GET['_status'], $_GET['post_status']);
    53                 } else {
    54                     $_GET['post_status'] = $_GET['_status'];
    55                 }
    56 
    57                 $done = bulk_edit_posts($_GET);
     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'];
    5886            }
     87
     88            $done = bulk_edit_posts($_GET);
    5989            break;
    6090    }
     
    71101    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();
     
    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'] ) {
     
    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']);
     162}
     163
     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']);
    128172}
    129173
     
    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>';
     
    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('Restore'); ?></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" />
     
    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>
     
    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('Restore'); ?></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>
Note: See TracChangeset for help on using the changeset viewer.