Make WordPress Core


Ignore:
Timestamp:
11/27/2009 10:34:09 AM (16 years ago)
Author:
azaozz
Message:

Undo for setting a comment as spam, props caesarsgrunt, fixes #11260, see #4529

File:
1 edited

Legend:

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

    r12162 r12286  
    2121    check_admin_referer('bulk-comments');
    2222
    23     if ((isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) && !empty($_REQUEST['pagegen_timestamp'])) {
     23    if ( (isset($_REQUEST['delete_all']) || isset($_REQUEST['delete_all2'])) && !empty($_REQUEST['pagegen_timestamp']) ) {
    2424        $comment_status = $wpdb->escape($_REQUEST['comment_status']);
    2525        $delete_time = $wpdb->escape($_REQUEST['pagegen_timestamp']);
    2626        $comment_ids = $wpdb->get_col( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = '$comment_status' AND '$delete_time' > comment_date_gmt" );
    2727        $doaction = 'delete';
    28     } elseif (($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments'])) {
     28    } elseif ( ($_REQUEST['action'] != -1 || $_REQUEST['action2'] != -1) && isset($_REQUEST['delete_comments']) ) {
    2929        $comment_ids = $_REQUEST['delete_comments'];
    3030        $doaction = ($_REQUEST['action'] != -1) ? $_REQUEST['action'] : $_REQUEST['action2'];
    31     } elseif ($_REQUEST['action'] == 'untrash' && isset($_REQUEST['ids'])) {
    32         $comment_ids = explode(',', $_REQUEST['ids']);
    33         $doaction = 'untrash';
    34     } else wp_redirect($_SERVER['HTTP_REFERER']);
    35 
    36     $approved = $unapproved = $spammed = $trashed = $untrashed = $deleted = 0;
     31    } elseif ( $_REQUEST['doaction'] == 'undo' && isset($_REQUEST['ids']) ) {
     32        $comment_ids = array_map( 'absint', explode(',', $_REQUEST['ids']) );
     33        $doaction = $_REQUEST['action'];
     34    } else {
     35        wp_redirect($_SERVER['HTTP_REFERER']);
     36    }
     37
     38    $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
    3739
    3840    foreach ($comment_ids as $comment_id) { // Check the permissions on each
     
    5153                $unapproved++;
    5254                break;
    53             case 'markspam' :
    54                 wp_set_comment_status($comment_id, 'spam');
     55            case 'spam' :
     56                wp_spam_comment($comment_id);
    5557                $spammed++;
     58                break;
     59            case 'unspam' :
     60                wp_unspam_comment($comment_id);
     61                $unspammed++;
    5662                break;
    5763            case 'trash' :
     
    7076    }
    7177
    72     $redirect_to = 'edit-comments.php?approved=' . $approved . '&unapproved=' . $unapproved . '&spam=' . $spammed . '&trashed=' . $trashed . '&untrashed=' . $untrashed . '&deleted=' . $deleted . '&ids=' . join(',', $comment_ids);
     78    $redirect_to = 'edit-comments.php';
     79
     80    if ( $approved )
     81        $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
     82    if ( $unapproved )
     83        $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
     84    if ( $spammed )
     85        $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
     86    if ( $unspammed )
     87        $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
     88    if ( $trashed )
     89        $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
     90    if ( $untrashed )
     91        $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
     92    if ( $deleted )
     93        $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
     94    if ( $trashed || $spammed )
     95        $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to );
     96
    7397    if ( $post_id )
    7498        $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
     
    113137
    114138<?php
    115 if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spam']) ) {
     139if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spammed']) || isset($_GET['unspammed']) ) {
    116140    $approved = isset($_GET['approved']) ? (int) $_GET['approved'] : 0;
    117141    $deleted = isset($_GET['deleted']) ? (int) $_GET['deleted'] : 0;
    118142    $trashed = isset($_GET['trashed']) ? (int) $_GET['trashed'] : 0;
    119143    $untrashed = isset($_GET['untrashed']) ? (int) $_GET['untrashed'] : 0;
    120     $spam = isset($_GET['spam']) ? (int) $_GET['spam'] : 0;
    121 
    122     if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spam > 0 ) {
     144    $spammed = isset($_GET['spammed']) ? (int) $_GET['spammed'] : 0;
     145    $unspammed = isset($_GET['unspammed']) ? (int) $_GET['unspammed'] : 0;
     146
     147    if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 ) {
    123148        echo '<div id="moderated" class="updated fade"><p>';
    124149
     
    127152            echo '<br />';
    128153        }
    129         if ( $spam > 0 ) {
    130             printf( _n( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
     154        if ( $spammed > 0 ) {
     155            printf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed );
     156            $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
     157            echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo?') . '</a><br />';
     158        }
     159        if ( $unspammed > 0 ) {
     160            printf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
    131161            echo '<br />';
    132162        }
     
    276306<?php endif; ?>
    277307<?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
    278 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
     308<option value="spam"><?php _e('Mark as Spam'); ?></option>
    279309<?php endif; ?>
    280310<?php if ( 'trash' == $comment_status ): ?>
    281311<option value="untrash"><?php _e('Restore'); ?></option>
     312<?php elseif ( 'spam' == $comment_status ): ?>
     313<option value="unspam"><?php _e('Not Spam'); ?></option>
    282314<?php endif; ?>
    283315<?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
     
    372404<?php endif; ?>
    373405<?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
    374 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
     406<option value="spam"><?php _e('Mark as Spam'); ?></option>
    375407<?php endif; ?>
    376408<?php if ( 'trash' == $comment_status ): ?>
     
    379411<?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
    380412<option value="delete"><?php _e('Delete Permanently'); ?></option>
     413<?php elseif ( 'spam' == $comment_status ): ?>
     414<option value="unspam"><?php _e('Not Spam'); ?></option>
    381415<?php else: ?>
    382416<option value="trash"><?php _e('Move to Trash'); ?></option>
Note: See TracChangeset for help on using the changeset viewer.