WordPress.org

WordPRess GSoC Trac

Changeset 757


Ignore:
Timestamp:
07/20/10 07:53:03 (4 years ago)
Author:
scribu
Message:

move comment bulk action handling

Location:
2010/scribu/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 2010/scribu/wp-admin/edit-comments.php

    r562 r757  
    1515wp_enqueue_script('admin-comments'); 
    1616enqueue_comment_hotkeys_js(); 
    17  
    18 if ( isset($_REQUEST['doaction']) ||  isset($_REQUEST['doaction2']) || isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) ) { 
    19     check_admin_referer('bulk-comments'); 
    20  
    21     if ( (isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) && !empty($_REQUEST['pagegen_timestamp']) ) { 
    22         $comment_status = $wpdb->escape($_REQUEST['comment_status']); 
    23         $delete_time = $wpdb->escape($_REQUEST['pagegen_timestamp']); 
    24         $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" ); 
    25         $doaction = 'delete'; 
    26     } elseif ( ($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments']) ) { 
    27         $comment_ids = $_REQUEST['delete_comments']; 
    28         $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2']; 
    29     } elseif ( $_REQUEST['doaction'] == 'undo' && isset($_REQUEST['ids']) ) { 
    30         $comment_ids = array_map( 'absint', explode(',', $_REQUEST['ids']) ); 
    31         $doaction = $_REQUEST['action']; 
    32     } else { 
    33         wp_redirect( wp_get_referer() ); 
    34     } 
    35  
    36     $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0; 
    37     $redirect_to = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids'), wp_get_referer() ); 
    38  
    39     foreach ($comment_ids as $comment_id) { // Check the permissions on each 
    40         $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) ); 
    41  
    42         if ( !current_user_can('edit_post', $_post_id) ) 
    43             continue; 
    44  
    45         switch( $doaction ) { 
    46             case 'approve' : 
    47                 wp_set_comment_status($comment_id, 'approve'); 
    48                 $approved++; 
    49                 break; 
    50             case 'unapprove' : 
    51                 wp_set_comment_status($comment_id, 'hold'); 
    52                 $unapproved++; 
    53                 break; 
    54             case 'spam' : 
    55                 wp_spam_comment($comment_id); 
    56                 $spammed++; 
    57                 break; 
    58             case 'unspam' : 
    59                 wp_unspam_comment($comment_id); 
    60                 $unspammed++; 
    61                 break; 
    62             case 'trash' : 
    63                 wp_trash_comment($comment_id); 
    64                 $trashed++; 
    65                 break; 
    66             case 'untrash' : 
    67                 wp_untrash_comment($comment_id); 
    68                 $untrashed++; 
    69                 break; 
    70             case 'delete' : 
    71                 wp_delete_comment($comment_id); 
    72                 $deleted++; 
    73                 break; 
    74         } 
    75     } 
    76  
    77     if ( $approved ) 
    78         $redirect_to = add_query_arg( 'approved', $approved, $redirect_to ); 
    79     if ( $unapproved ) 
    80         $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to ); 
    81     if ( $spammed ) 
    82         $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to ); 
    83     if ( $unspammed ) 
    84         $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to ); 
    85     if ( $trashed ) 
    86         $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to ); 
    87     if ( $untrashed ) 
    88         $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to ); 
    89     if ( $deleted ) 
    90         $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to ); 
    91     if ( $trashed || $spammed ) 
    92         $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to ); 
    93  
    94     wp_redirect( $redirect_to ); 
    95     exit; 
    96 } elseif ( ! empty($_GET['_wp_http_referer']) ) { 
    97      wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); 
    98      exit; 
    99 } 
    10017 
    10118require_once( './includes/list-tables.php' ); 
  • 2010/scribu/wp-admin/includes/list-tables.php

    r756 r757  
    19911991            return; 
    19921992        } 
     1993         
     1994        $this->handle_bulk_actions(); 
    19931995 
    19941996        $post_id = isset( $_REQUEST['post_ID'] ) ? absint( $_REQUEST['post_ID'] ) : 0; 
     
    20512053            'plural' => 'comments' 
    20522054        ) ); 
     2055    } 
     2056 
     2057    function handle_bulk_actions() { 
     2058        global $wpdb; 
     2059     
     2060        if ( isset($_REQUEST['doaction']) ||  isset($_REQUEST['doaction2']) || isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2']) ) { 
     2061            check_admin_referer('bulk-comments'); 
     2062 
     2063            if ( (isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) && !empty($_REQUEST['pagegen_timestamp']) ) { 
     2064                $comment_status = $wpdb->escape($_REQUEST['comment_status']); 
     2065                $delete_time = $wpdb->escape($_REQUEST['pagegen_timestamp']); 
     2066                $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" ); 
     2067                $doaction = 'delete'; 
     2068            } elseif ( ($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments']) ) { 
     2069                $comment_ids = $_REQUEST['delete_comments']; 
     2070                $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2']; 
     2071            } elseif ( $_REQUEST['doaction'] == 'undo' && isset($_REQUEST['ids']) ) { 
     2072                $comment_ids = array_map( 'absint', explode(',', $_REQUEST['ids']) ); 
     2073                $doaction = $_REQUEST['action']; 
     2074            } else { 
     2075                wp_redirect( wp_get_referer() ); 
     2076            } 
     2077 
     2078            $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0; 
     2079            $redirect_to = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids'), wp_get_referer() ); 
     2080 
     2081            foreach ($comment_ids as $comment_id) { // Check the permissions on each 
     2082                $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) ); 
     2083 
     2084                if ( !current_user_can('edit_post', $_post_id) ) 
     2085                    continue; 
     2086 
     2087                switch( $doaction ) { 
     2088                    case 'approve' : 
     2089                        wp_set_comment_status($comment_id, 'approve'); 
     2090                        $approved++; 
     2091                        break; 
     2092                    case 'unapprove' : 
     2093                        wp_set_comment_status($comment_id, 'hold'); 
     2094                        $unapproved++; 
     2095                        break; 
     2096                    case 'spam' : 
     2097                        wp_spam_comment($comment_id); 
     2098                        $spammed++; 
     2099                        break; 
     2100                    case 'unspam' : 
     2101                        wp_unspam_comment($comment_id); 
     2102                        $unspammed++; 
     2103                        break; 
     2104                    case 'trash' : 
     2105                        wp_trash_comment($comment_id); 
     2106                        $trashed++; 
     2107                        break; 
     2108                    case 'untrash' : 
     2109                        wp_untrash_comment($comment_id); 
     2110                        $untrashed++; 
     2111                        break; 
     2112                    case 'delete' : 
     2113                        wp_delete_comment($comment_id); 
     2114                        $deleted++; 
     2115                        break; 
     2116                } 
     2117            } 
     2118 
     2119            if ( $approved ) 
     2120                $redirect_to = add_query_arg( 'approved', $approved, $redirect_to ); 
     2121            if ( $unapproved ) 
     2122                $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to ); 
     2123            if ( $spammed ) 
     2124                $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to ); 
     2125            if ( $unspammed ) 
     2126                $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to ); 
     2127            if ( $trashed ) 
     2128                $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to ); 
     2129            if ( $untrashed ) 
     2130                $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to ); 
     2131            if ( $deleted ) 
     2132                $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to ); 
     2133            if ( $trashed || $spammed ) 
     2134                $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to ); 
     2135 
     2136            wp_redirect( $redirect_to ); 
     2137            exit; 
     2138        } elseif ( ! empty($_GET['_wp_http_referer']) ) { 
     2139             wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); 
     2140             exit; 
     2141        }    
    20532142    } 
    20542143 
Note: See TracChangeset for help on using the changeset viewer.