Make WordPress Core


Ignore:
Timestamp:
07/30/2009 01:39:34 PM (17 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-pages.php

    r11743 r11749  
    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 ) {
     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.') );
     31
     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.') );
     43
     44                if ( !wp_untrash_post($post_id) )
     45                    wp_die( __('Error in removing from trash...') );
     46               
     47                $untrashed++;
     48            }
     49            break;
    1750        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);
    23 
    24                     if ( !current_user_can('delete_page', $post_id_del) )
    25                         wp_die( __('You are not allowed to delete this page.') );
    26 
    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++;
     51            $deleted = 0;
     52            foreach( (array) $post_ids as $post_id_del ) {
     53                $post_del = & get_post($post_id_del);
     54
     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...') );
     61                } else {
     62                    if ( !wp_delete_post($post_id_del) )
     63                        wp_die( __('Error in deleting...') );
    3564                }
     65                $deleted++;
    3666            }
    3767            break;
    3868        case 'edit':
    39             if ( isset($_GET['post']) && isset($_GET['bulk_edit']) ) {
    40                 check_admin_referer('bulk-pages');
    41 
    42                 if ( -1 == $_GET['_status'] ) {
    43                     $_GET['post_status'] = null;
    44                     unset($_GET['_status'], $_GET['post_status']);
    45                 } else {
    46                     $_GET['post_status'] = $_GET['_status'];
    47                 }
    48 
    49                 $done = bulk_edit_posts($_GET);
     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'];
    5074            }
     75
     76            $done = bulk_edit_posts($_GET);
    5177            break;
    5278    }
     
    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();
     
    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
     
    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'] ) {
     
    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>
     
    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>';
     
    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('Restore'); ?></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
     
    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('Restore'); ?></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
Note: See TracChangeset for help on using the changeset viewer.