Make WordPress Core


Ignore:
Timestamp:
08/12/2009 10:57:15 AM (17 years ago)
Author:
azaozz
Message:

Fix bulk edit, some cleanup and message fixes for moving in/out of the trash, see #4529

File:
1 edited

Legend:

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

    r11779 r11807  
    2222
    2323// Handle bulk actions
    24 if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
     24if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
    2525    check_admin_referer('bulk-posts');
    26    
     26    $sendback = wp_get_referer();
     27
     28    if ( strpos($sendback, 'post.php') !== false )
     29        $sendback = admin_url('post-new.php');
     30
    2731    if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
    28         $post_status = $wpdb->escape($_GET['post_status']);
    29         $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = '$post_status'" );
     32        $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
     33        $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='post' AND post_status = %s", $post_status ) );
    3034        $doaction = 'delete';
    31     } elseif (($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post'])) {
    32         $post_ids = $_GET['post'];
     35    } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post']) ) {
     36        $post_ids = array_map( 'intval', (array) $_GET['post'] );
    3337        $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
    34     } else wp_redirect($_SERVER['HTTP_REFERER']);
    35    
     38    } else {
     39        wp_redirect( admin_url('edit.php') );
     40    }
     41
    3642    switch ( $doaction ) {
    3743        case 'trash':
    3844            $trashed = 0;
    3945            foreach( (array) $post_ids as $post_id ) {
    40                 $post_del = & get_post($post_id);
    41 
    42                 if ( !current_user_can('delete_post', $post_id_del) )
     46                if ( !current_user_can('delete_post', $post_id) )
    4347                    wp_die( __('You are not allowed to move this post to the trash.') );
    4448
     
    4852                $trashed++;
    4953            }
     54            $sendback = add_query_arg('trashed', $trashed, $sendback);
    5055            break;
    5156        case 'untrash':
    5257            $untrashed = 0;
    5358            foreach( (array) $post_ids as $post_id ) {
    54                 $post_del = & get_post($post_id);
    55 
    56                 if ( !current_user_can('delete_post', $post_id_del) )
    57                     wp_die( __('You are not allowed to remove this post from the trash.') );
     59                if ( !current_user_can('delete_post', $post_id) )
     60                    wp_die( __('You are not allowed to restore this post from the trash.') );
    5861
    5962                if ( !wp_untrash_post($post_id) )
    60                     wp_die( __('Error in removing from trash...') );
     63                    wp_die( __('Error in restoring from trash...') );
    6164               
    6265                $untrashed++;
    6366            }
     67            $sendback = add_query_arg('untrashed', $untrashed, $sendback);
    6468            break;
    6569        case 'delete':
    6670            $deleted = 0;
    67             foreach( (array) $post_ids as $post_id_del ) {
    68                 $post_del = & get_post($post_id_del);
    69 
    70                 if ( !current_user_can('delete_post', $post_id_del) )
     71            foreach( (array) $post_ids as $post_id ) {
     72                $post_del = & get_post($post_id);
     73
     74                if ( !current_user_can('delete_post', $post_id) )
    7175                    wp_die( __('You are not allowed to delete this post.') );
    7276
    7377                if ( $post_del->post_type == 'attachment' ) {
    74                     if ( ! wp_delete_attachment($post_id_del) )
     78                    if ( ! wp_delete_attachment($post_id) )
    7579                        wp_die( __('Error in deleting...') );
    7680                } else {
    77                     if ( !wp_delete_post($post_id_del) )
     81                    if ( !wp_delete_post($post_id) )
    7882                        wp_die( __('Error in deleting...') );
    7983                }
    8084                $deleted++;
    8185            }
     86            $sendback = add_query_arg('deleted', $deleted, $sendback);
    8287            break;
    8388        case 'edit':
    84             if ( -1 == $_GET['_status'] ) {
    85                 $_GET['post_status'] = null;
    86                 unset($_GET['_status'], $_GET['post_status']);
    87             } else {
    88                 $_GET['post_status'] = $_GET['_status'];
     89            $done = bulk_edit_posts($_GET);
     90
     91            if ( is_array($done) ) {
     92                $done['updated'] = count( $done['updated'] );
     93                $done['skipped'] = count( $done['skipped'] );
     94                $done['locked'] = count( $done['locked'] );
     95                $sendback = add_query_arg( $done, $sendback );
    8996            }
    90 
    91             $done = bulk_edit_posts($_GET);
    9297            break;
    9398    }
    9499
    95     $sendback = wp_get_referer();
    96     if ( strpos($sendback, 'post.php') !== false ) $sendback = admin_url('post-new.php');
    97     elseif ( strpos($sendback, 'attachments.php') !== false ) $sendback = admin_url('attachments.php');
    98     if ( isset($done) ) {
    99         $done['updated'] = count( $done['updated'] );
    100         $done['skipped'] = count( $done['skipped'] );
    101         $done['locked'] = count( $done['locked'] );
    102         $sendback = add_query_arg( $done, $sendback );
    103     }
    104     if ( isset($deleted) )
    105         $sendback = add_query_arg('deleted', $deleted, $sendback);
    106     elseif ( isset($trashed) )
    107         $sendback = add_query_arg('trashed', $trashed, $sendback);
    108     elseif ( isset($untrashed) )
    109         $sendback = add_query_arg('untrashed', $untrashed, $sendback);
     100    if ( isset($_GET['action']) )
     101        $sendback = remove_query_arg( array('action', 'action2', 'cat', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view', 'post_type'), $sendback );
     102
    110103    wp_redirect($sendback);
    111104    exit();
     
    180173<?php } ?>
    181174
    182 <form id="posts-filter" action="" method="get">
     175<form id="posts-filter" action="<?php echo admin_url('edit.php'); ?>" method="get">
    183176
    184177<ul class="subsubsub">
Note: See TracChangeset for help on using the changeset viewer.