Make WordPress Core

Changeset 17276


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

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

Location:
trunk/wp-admin
Files:
2 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']) ) );
  • trunk/wp-admin/includes/class-wp-posts-list-table.php

    r17195 r17276  
    10141014<?php
    10151015    }
     1016
     1017    function do_bulk_actions( $doaction = null ) {
     1018        if ( null === $doaction )
     1019            $doaction = $this->current_action();
     1020
     1021        if ( ! $doaction )
     1022            return;
     1023
     1024        check_admin_referer('bulk-posts');
     1025
     1026        $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
     1027        if ( strpos($sendback, 'post.php') !== false )
     1028            $sendback = admin_url($post_new_file);
     1029
     1030        if ( 'delete_all' == $doaction ) {
     1031            $post_status = preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['post_status']);
     1032            if ( get_post_status_object($post_status) ) // Check the post status exists first
     1033                $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type=%s AND post_status = %s", $post_type, $post_status ) );
     1034            $doaction = 'delete';
     1035        } elseif ( isset( $_REQUEST['media'] ) ) {
     1036            $post_ids = $_REQUEST['media'];
     1037        } elseif ( isset( $_REQUEST['ids'] ) ) {
     1038            $post_ids = explode( ',', $_REQUEST['ids'] );
     1039        } elseif ( !empty( $_REQUEST['post'] ) ) {
     1040            $post_ids = array_map('intval', $_REQUEST['post']);
     1041        }
     1042
     1043        if ( !isset( $post_ids ) ) {
     1044            wp_redirect( admin_url("edit.php?post_type=$post_type") );
     1045            exit;
     1046        }
     1047
     1048        switch ( $doaction ) {
     1049            case 'trash':
     1050                $trashed = 0;
     1051                foreach( (array) $post_ids as $post_id ) {
     1052                    if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
     1053                        wp_die( __('You are not allowed to move this item to the Trash.') );
     1054
     1055                    if ( !wp_trash_post($post_id) )
     1056                        wp_die( __('Error in moving to Trash.') );
     1057
     1058                    $trashed++;
     1059                }
     1060                $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids) ), $sendback );
     1061                break;
     1062            case 'untrash':
     1063                $untrashed = 0;
     1064                foreach( (array) $post_ids as $post_id ) {
     1065                    if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
     1066                        wp_die( __('You are not allowed to restore this item from the Trash.') );
     1067
     1068                    if ( !wp_untrash_post($post_id) )
     1069                        wp_die( __('Error in restoring from Trash.') );
     1070
     1071                    $untrashed++;
     1072                }
     1073                $sendback = add_query_arg('untrashed', $untrashed, $sendback);
     1074                break;
     1075            case 'delete':
     1076                $deleted = 0;
     1077                foreach( (array) $post_ids as $post_id ) {
     1078                    $post_del = & get_post($post_id);
     1079
     1080                    if ( !current_user_can($post_type_object->cap->delete_post, $post_id) )
     1081                        wp_die( __('You are not allowed to delete this item.') );
     1082
     1083                    if ( $post_del->post_type == 'attachment' ) {
     1084                        if ( ! wp_delete_attachment($post_id) )
     1085                            wp_die( __('Error in deleting...') );
     1086                    } else {
     1087                        if ( !wp_delete_post($post_id) )
     1088                            wp_die( __('Error in deleting...') );
     1089                    }
     1090                    $deleted++;
     1091                }
     1092                $sendback = add_query_arg('deleted', $deleted, $sendback);
     1093                break;
     1094            case 'edit':
     1095                $done = bulk_edit_posts($_REQUEST);
     1096
     1097                if ( is_array($done) ) {
     1098                    $done['updated'] = count( $done['updated'] );
     1099                    $done['skipped'] = count( $done['skipped'] );
     1100                    $done['locked'] = count( $done['locked'] );
     1101                    $sendback = add_query_arg( $done, $sendback );
     1102                }
     1103                break;
     1104            default :
     1105                $sendback = apply_filters( "bulk_actions-posts-$doaction", $sendback, $doaction );
     1106                break;
     1107        }
     1108
     1109        $sendback = remove_query_arg( array( 'action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view' ), $sendback );
     1110        $sendback = $this->add_query_args( $sendback );
     1111        wp_redirect( $sendback );
     1112        exit();
     1113    }
     1114
    10161115}
    10171116
Note: See TracChangeset for help on using the changeset viewer.