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-pages.php

    r11779 r11807  
    1414
    1515// Handle bulk actions
    16 if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
     16if ( isset($_GET['doaction']) || isset($_GET['doaction2']) || isset($_GET['delete_all']) || isset($_GET['delete_all2']) || isset($_GET['bulk_edit']) ) {
    1717        check_admin_referer('bulk-pages');
    18        
    19         if (isset($_GET['delete_all']) || isset($_GET['delete_all2'])) {
    20                 $post_status = $wpdb->escape($_GET['post_status']);
    21                 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = '$post_status'" );
     18        $sendback = wp_get_referer();
     19
     20        if ( strpos($sendback, 'page.php') !== false )
     21                $sendback = admin_url('page-new.php');
     22
     23        if ( isset($_GET['delete_all']) || isset($_GET['delete_all2']) ) {
     24                $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_GET['post_status']);
     25                $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = %s", $post_status ) );
    2226                $doaction = 'delete';
    23         } elseif (($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post'])) {
    24                 $post_ids = $_GET['post'];
     27        } elseif ( ($_GET['action'] != -1 || $_GET['action2'] != -1) && isset($_GET['post']) ) {
     28                $post_ids = array_map( 'intval', (array) $_GET['post'] );
    2529                $doaction = ($_GET['action'] != -1) ? $_GET['action'] : $_GET['action2'];
    26         } else wp_redirect($_SERVER['HTTP_REFERER']);
     30        } else {
     31                wp_redirect( admin_url('edit-pages.php') );
     32        }
    2733
    2834        switch ( $doaction ) {
    … …  
    3844                                $trashed++;
    3945                        }
     46                        $sendback = add_query_arg('trashed', $trashed, $sendback);
    4047                        break;
    4148                case 'untrash':
    … …  
    4350                        foreach( (array) $post_ids as $post_id ) {
    4451                                if ( !current_user_can('delete_page', $post_id) )
    45                                         wp_die( __('You are not allowed to remove this page from the trash.') );
     52                                        wp_die( __('You are not allowed to restore this page from the trash.') );
    4653
    4754                                if ( !wp_untrash_post($post_id) )
    48                                         wp_die( __('Error in removing from trash...') );
     55                                        wp_die( __('Error in restoring from trash...') );
    4956                               
    5057                                $untrashed++;
    5158                        }
     59                        $sendback = add_query_arg('untrashed', $untrashed, $sendback);
    5260                        break;
    5361                case 'delete':
    5462                        $deleted = 0;
    55                         foreach( (array) $post_ids as $post_id_del ) {
    56                                 $post_del = & get_post($post_id_del);
    57 
    58                                 if ( !current_user_can('delete_page', $post_id_del) )
     63                        foreach( (array) $post_ids as $post_id ) {
     64                                $post_del = & get_post($post_id);
     65
     66                                if ( !current_user_can('delete_page', $post_id) )
    5967                                        wp_die( __('You are not allowed to delete this page.') );
    6068
    6169                                if ( $post_del->post_type == 'attachment' ) {
    62                                         if ( ! wp_delete_attachment($post_id_del) )
     70                                        if ( ! wp_delete_attachment($post_id) )
    6371                                                wp_die( __('Error in deleting...') );
    6472                                } else {
    65                                         if ( !wp_delete_post($post_id_del) )
     73                                        if ( !wp_delete_post($post_id) )
    6674                                                wp_die( __('Error in deleting...') );
    6775                                }
    6876                                $deleted++;
    6977                        }
     78                        $sendback = add_query_arg('deleted', $deleted, $sendback);
    7079                        break;
    7180                case 'edit':
    72                         if ( -1 == $_GET['_status'] ) {
    73                                 $_GET['post_status'] = null;
    74                                 unset($_GET['_status'], $_GET['post_status']);
    75                         } else {
    76                                 $_GET['post_status'] = $_GET['_status'];
     81                        $_GET['post_type'] = 'page';
     82                        $done = bulk_edit_posts($_GET);
     83
     84                        if ( is_array($done) ) {
     85                                $done['updated'] = count( $done['updated'] );
     86                                $done['skipped'] = count( $done['skipped'] );
     87                                $done['locked'] = count( $done['locked'] );
     88                                $sendback = add_query_arg( $done, $sendback );
    7789                        }
    78 
    79                         $done = bulk_edit_posts($_GET);
    8090                        break;
    8191        }
    8292
    83         $sendback = wp_get_referer();
    84         if (strpos($sendback, 'page.php') !== false) $sendback = admin_url('page-new.php');
    85         elseif (strpos($sendback, 'attachments.php') !== false) $sendback = admin_url('attachments.php');
    86         if ( isset($done) ) {
    87                 $done['updated'] = count( $done['updated'] );
    88                 $done['skipped'] = count( $done['skipped'] );
    89                 $done['locked'] = count( $done['locked'] );
    90                 $sendback = add_query_arg( $done, $sendback );
    91         }
    92         if ( isset($deleted) )
    93                 $sendback = add_query_arg('deleted', $deleted, $sendback);
    94         elseif ( isset($trashed) )
    95                 $sendback = add_query_arg('trashed', $trashed, $sendback);
    96         elseif ( isset($untrashed) )
    97                 $sendback = add_query_arg('untrashed', $untrashed, $sendback);
     93        if ( isset($_GET['action']) )
     94                $sendback = remove_query_arg( array('action', 'action2', 'post_parent', 'page_template', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view', 'post_type'), $sendback );
     95
    9896        wp_redirect($sendback);
    9997        exit();
    … …  
    182180endif; ?>
    183181
    184 <form id="posts-filter" action="" method="get">
     182<form id="posts-filter" action="<?php echo admin_url('edit-pages.php'); ?>" method="get">
    185183<ul class="subsubsub">
    186184<?php
Note: See TracChangeset for help on using the changeset viewer.