Make WordPress Core


Ignore:
Timestamp:
01/13/2011 12:34:18 AM (13 years ago)
Author:
nacin
Message:

Move edit.php bulk actions code to a handler in the list table class. see #16166.

File:
1 edited

Legend:

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

    r17270 r17276  
    3939
    4040if ( $doaction ) {
    41     check_admin_referer('bulk-posts');
    42 
    43     $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
    44     $sendback = $wp_list_table->add_query_args( $sendback );
    45     if ( strpos($sendback, 'post.php') !== false )
    46         $sendback = admin_url($post_new_file);
    47 
    48     if ( 'delete_all' == $doaction ) {
    49         $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
    50         if ( get_post_status_object($post_status) ) // Check the post status exists first
    51             $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
    52         $doaction = 'delete';
    53     } elseif ( isset( $_REQUEST['media'] ) ) {
    54         $post_ids = $_REQUEST['media'];
    55     } elseif ( isset( $_REQUEST['ids'] ) ) {
    56         $post_ids = explode( ',', $_REQUEST['ids'] );
    57     } elseif ( !empty( $_REQUEST['post'] ) ) {
    58         $post_ids = array_map('intval', $_REQUEST['post']);
    59     }
    60 
    61     if ( !isset( $post_ids ) ) {
    62         wp_redirect( admin_url("edit.php?post_type=$post_type") );
    63         exit;
    64     }
    65 
    66     switch ( $doaction ) {
    67         case 'trash':
    68             $trashed = 0;
    69             foreach( (array) $post_ids as $post_id ) {
    70                 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    71                     wp_die( __('You are not allowed to move this item to the Trash.') );
    72 
    73                 if ( !wp_trash_post($post_id) )
    74                     wp_die( __('Error in moving to Trash.') );
    75 
    76                 $trashed++;
    77             }
    78             $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids) ), $sendback );
    79             break;
    80         case 'untrash':
    81             $untrashed = 0;
    82             foreach( (array) $post_ids as $post_id ) {
    83                 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    84                     wp_die( __('You are not allowed to restore this item from the Trash.') );
    85 
    86                 if ( !wp_untrash_post($post_id) )
    87                     wp_die( __('Error in restoring from Trash.') );
    88 
    89                 $untrashed++;
    90             }
    91             $sendback = add_query_arg('untrashed', $untrashed, $sendback);
    92             break;
    93         case 'delete':
    94             $deleted = 0;
    95             foreach( (array) $post_ids as $post_id ) {
    96                 $post_del = & get_post($post_id);
    97 
    98                 if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
    99                     wp_die( __('You are not allowed to delete this item.') );
    100 
    101                 if ( $post_del->post_type == 'attachment' ) {
    102                     if ( ! wp_delete_attachment($post_id) )
    103                         wp_die( __('Error in deleting...') );
    104                 } else {
    105                     if ( !wp_delete_post($post_id) )
    106                         wp_die( __('Error in deleting...') );
    107                 }
    108                 $deleted++;
    109             }
    110             $sendback = add_query_arg('deleted', $deleted, $sendback);
    111             break;
    112         case 'edit':
    113             $done = bulk_edit_posts($_REQUEST);
    114 
    115             if ( is_array($done) ) {
    116                 $done['updated'] = count( $done['updated'] );
    117                 $done['skipped'] = count( $done['skipped'] );
    118                 $done['locked'] = count( $done['locked'] );
    119                 $sendback = add_query_arg( $done, $sendback );
    120             }
    121             break;
    122     }
    123 
    124     $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view'), $sendback );
    125 
    126     wp_redirect($sendback);
    127     exit();
     41    $wp_list_table->do_bulk_actions( $doaction );
    12842} elseif ( ! empty($_REQUEST['_wp_http_referer']) ) {
    12943     wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
Note: See TracChangeset for help on using the changeset viewer.