Make WordPress Core

Ticket #11260: 11260.diff

File 11260.diff, 28.2 KB (added by caesarsgrunt, 15 years ago)

Full implementation of undo for spam.

  • wp-includes/post.php

     
    11831183
    11841184        do_action('delete_post', $postid);
    11851185
    1186         delete_post_meta($postid,'_wp_trash_meta_status');
     1186        delete_post_meta($postid,'_wp_previous_status');
    11871187        delete_post_meta($postid,'_wp_trash_meta_time');
    11881188
    11891189        /** @todo delete for pluggable post taxonomies too */
     
    12811281
    12821282        do_action('trash_post', $post_id);
    12831283
    1284         add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']);
     1284        add_post_meta($post_id,'_wp_previous_status', $post['post_status']);
    12851285        add_post_meta($post_id,'_wp_trash_meta_time', time());
    12861286
    12871287        $post['post_status'] = 'trash';
     
    13131313
    13141314        do_action('untrash_post', $post_id);
    13151315
    1316         $post_status = get_post_meta($post_id, '_wp_trash_meta_status', true);
     1316        $post_status = get_post_meta($post_id, '_wp_previous_status', true);
    13171317
    13181318        $post['post_status'] = $post_status;
    13191319
    1320         delete_post_meta($post_id, '_wp_trash_meta_status');
     1320        delete_post_meta($post_id, '_wp_previous_status');
    13211321        delete_post_meta($post_id, '_wp_trash_meta_time');
    13221322
    13231323        wp_insert_post($post);
     
    28402840        if ( !$force_delete && 'trash' != $post->post_status )
    28412841                return wp_trash_post( $post_id );
    28422842
    2843         delete_post_meta($post_id, '_wp_trash_meta_status');
     2843        delete_post_meta($post_id, '_wp_previous_status');
    28442844        delete_post_meta($post_id, '_wp_trash_meta_time');
    28452845
    28462846        $meta = wp_get_attachment_metadata( $post_id );
  • wp-includes/comment.php

     
    823823
    824824        do_action('delete_comment', $comment_id);
    825825
    826         delete_comment_meta($comment_id,'_wp_trash_meta_status');
     826        delete_comment_meta($comment_id,'_wp_previous_status');
    827827        delete_comment_meta($comment_id,'_wp_trash_meta_time');
    828828
    829829        if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) )
     
    866866
    867867        do_action('trash_comment', $comment_id);
    868868
    869         add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved);
     869        add_comment_meta($comment_id, '_wp_previous_status', $comment->comment_approved);
    870870        add_comment_meta($comment_id, '_wp_trash_meta_time', time() );
    871871
    872872        wp_set_comment_status($comment_id, 'trash');
     
    880880 * Removes a comment from the Trash
    881881 *
    882882 * @since 2.9.0
    883  * @uses do_action() on 'untrash_comment' before undeletion
    884  * @uses do_action() on 'untrashed_comment' after undeletion
     883 * @uses do_action() on 'untrash_comment' before untrashing
     884 * @uses do_action() on 'untrashed_comment' after untrashing
    885885 *
    886886 * @param int $comment_id Comment ID.
    887887 * @return mixed False on failure
     
    894894
    895895        $comment = array('comment_ID'=>$comment_id);
    896896
    897         $status = get_comment_meta($comment_id, '_wp_trash_meta_status', true);
     897        $status = get_comment_meta($comment_id, '_wp_previous_status', true);
    898898        if ( empty($status) )
    899899                $status = '0';
    900900
    901901        $comment['comment_approved'] = $status;
    902902
    903903        delete_comment_meta($comment_id, '_wp_trash_meta_time');
    904         delete_comment_meta($comment_id, '_wp_trash_meta_status');
     904        delete_comment_meta($comment_id, '_wp_previous_status');
    905905
    906906        wp_update_comment($comment);
    907907
     
    911911}
    912912
    913913/**
     914 * Marks a comment as Spam
     915 *
     916 * @since 2.9.0
     917 * @uses do_action() on 'spam_comment' before spamming
     918 * @uses do_action() on 'spammed_comment' after spamming
     919 *
     920 * @param int $comment_id Comment ID.
     921 * @return mixed False on failure
     922 */
     923function wp_spam_comment($comment_id) {
     924        if ( !$comment = get_comment($comment_id) )
     925                return false;
     926
     927        do_action('spam_comment', $comment_id);
     928
     929        add_comment_meta($comment_id, '_wp_previous_status', $comment->comment_approved);
     930        wp_set_comment_status($comment_id, 'spam');
     931
     932        do_action('spammed_comment', $comment_id);
     933
     934        return true;
     935}
     936
     937/**
     938 * Removes a comment from the Spam
     939 *
     940 * @since 2.9.0
     941 * @uses do_action() on 'unspam_comment' before unspamming
     942 * @uses do_action() on 'unspammed_comment' after unspamming
     943 *
     944 * @param int $comment_id Comment ID.
     945 * @return mixed False on failure
     946 */
     947function wp_unspam_comment($comment_id) {
     948        if ( ! (int)$comment_id )
     949                return false;
     950
     951        do_action('unspam_comment', $comment_id);
     952
     953        $comment = array('comment_ID'=>$comment_id);
     954
     955        $status = get_comment_meta($comment_id, '_wp_previous_status', true);
     956        if ( empty($status) )
     957                $status = '0';
     958
     959        $comment['comment_approved'] = $status;
     960
     961        delete_comment_meta($comment_id, '_wp_previous_status');
     962
     963        wp_update_comment($comment);
     964
     965        do_action('unspammed_comment', $comment_id);
     966
     967        return true;
     968}
     969
     970/**
    914971 * The status of a comment by ID.
    915972 *
    916973 * @since 1.0.0
  • wp-includes/capabilities.php

     
    795795                        if ( 'publish' == $post->post_status ) {
    796796                                $caps[] = 'delete_published_posts';
    797797                        } elseif ( 'trash' == $post->post_status ) {
    798                                 if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
     798                                if ('publish' == get_post_meta($post->ID, '_wp_previous_status', true) )
    799799                                        $caps[] = 'delete_published_posts';
    800800                        } else {
    801801                                // If the post is draft...
     
    823823                        if ( $page->post_status == 'publish' ) {
    824824                                $caps[] = 'delete_published_pages';
    825825                        } elseif ( 'trash' == $page->post_status ) {
    826                                 if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
     826                                if ('publish' == get_post_meta($page->ID, '_wp_previous_status', true) )
    827827                                        $caps[] = 'delete_published_pages';
    828828                        } else {
    829829                                // If the page is draft...
     
    857857                        if ( 'publish' == $post->post_status ) {
    858858                                $caps[] = 'edit_published_posts';
    859859                        } elseif ( 'trash' == $post->post_status ) {
    860                                 if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
     860                                if ('publish' == get_post_meta($post->ID, '_wp_previous_status', true) )
    861861                                        $caps[] = 'edit_published_posts';
    862862                        } else {
    863863                                // If the post is draft...
     
    885885                        if ( 'publish' == $page->post_status ) {
    886886                                $caps[] = 'edit_published_pages';
    887887                        } elseif ( 'trash' == $page->post_status ) {
    888                                 if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
     888                                if ('publish' == get_post_meta($page->ID, '_wp_previous_status', true) )
    889889                                        $caps[] = 'edit_published_pages';
    890890                        } else {
    891891                                // If the page is draft...
  • wp-admin/edit-comments.php

     
    2828        } 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'])) {
     31        } elseif ($_REQUEST['doaction'] == 'undo' && isset($_REQUEST['ids'])) {
    3232                $comment_ids = explode(',', $_REQUEST['ids']);
    33                 $doaction = 'untrash';
     33                $doaction = $_REQUEST['action'];
    3434        } else wp_redirect($_SERVER['HTTP_REFERER']);
    3535
    36         $approved = $unapproved = $spammed = $trashed = $untrashed = $deleted = 0;
     36        $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
    3737
    3838        foreach ($comment_ids as $comment_id) { // Check the permissions on each
    3939                $_post_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = %d", $comment_id) );
     
    5050                                wp_set_comment_status($comment_id, 'hold');
    5151                                $unapproved++;
    5252                                break;
    53                         case 'markspam' :
    54                                 wp_set_comment_status($comment_id, 'spam');
     53                        case 'spam' :
     54                                wp_spam_comment($comment_id);
    5555                                $spammed++;
    5656                                break;
     57                        case 'unspam' :
     58                                wp_unspam_comment($comment_id);
     59                                $unspammed++;
     60                                break;
    5761                        case 'trash' :
    5862                                wp_trash_comment($comment_id);
    5963                                $trashed++;
     
    6872                                break;
    6973                }
    7074        }
     75       
     76        $redirect_to = 'edit-comments.php';
     77       
     78        if ( $approved )   $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
     79        if ( $unapproved ) $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
     80        if ( $spammed )    $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
     81        if ( $unspammed )  $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
     82        if ( $trashed )    $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
     83        if ( $untrashed )  $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
     84        if ( $deleted )    $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
     85       
     86        if ( $trashed || $spammed ) $redirect_to = add_query_arg( 'ids', join(',', $comment_ids), $redirect_to );
    7187
    72         $redirect_to = 'edit-comments.php?approved=' . $approved . '&unapproved=' . $unapproved . '&spam=' . $spammed . '&trashed=' . $trashed . '&untrashed=' . $untrashed . '&deleted=' . $deleted . '&ids=' . join(',', $comment_ids);
    7388        if ( $post_id )
    7489                $redirect_to = add_query_arg( 'p', absint( $post_id ), $redirect_to );
    7590        if ( isset($_REQUEST['apage']) )
     
    112127</h2>
    113128
    114129<?php
    115 if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spam']) ) {
     130if ( isset($_GET['approved']) || isset($_GET['deleted']) || isset($_GET['trashed']) || isset($_GET['untrashed']) || isset($_GET['spammed']) || isset($_GET['unspammed']) ) {
    116131        $approved = isset($_GET['approved']) ? (int) $_GET['approved'] : 0;
    117132        $deleted = isset($_GET['deleted']) ? (int) $_GET['deleted'] : 0;
    118133        $trashed = isset($_GET['trashed']) ? (int) $_GET['trashed'] : 0;
    119134        $untrashed = isset($_GET['untrashed']) ? (int) $_GET['untrashed'] : 0;
    120         $spam = isset($_GET['spam']) ? (int) $_GET['spam'] : 0;
     135        $spammed = isset($_GET['spammed']) ? (int) $_GET['spammed'] : 0;
     136        $unspammed = isset($_GET['unspammed']) ? (int) $_GET['unspammed'] : 0;
    121137
    122         if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spam > 0 ) {
     138        if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 ) {
    123139                echo '<div id="moderated" class="updated fade"><p>';
    124140
    125141                if ( $approved > 0 ) {
    126142                        printf( _n( '%s comment approved', '%s comments approved', $approved ), $approved );
    127143                        echo '<br />';
    128144                }
    129                 if ( $spam > 0 ) {
    130                         printf( _n( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam );
     145                if ( $spammed > 0 ) {
     146                        printf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed );
     147                        $ids = isset($_GET['ids']) ? $_GET['ids'] : 0;
     148                        echo ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo?') . '</a><br />';
     149                }
     150                if ( $unspammed > 0 ) {
     151                        printf( _n( '%s comment restored from the spam', '%s comments restored from the spam', $unspammed ), $unspammed );
    131152                        echo '<br />';
    132153                }
    133154                if ( $trashed > 0 ) {
     
    275296<option value="approve"><?php _e('Approve'); ?></option>
    276297<?php endif; ?>
    277298<?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
    278 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
     299<option value="spam"><?php _e('Mark as Spam'); ?></option>
    279300<?php endif; ?>
    280301<?php if ( 'trash' == $comment_status ): ?>
    281302<option value="untrash"><?php _e('Restore'); ?></option>
     303<?php elseif ( 'spam' == $comment_status ): ?>
     304<option value="unspam"><?php _e('Not Spam'); ?></option>
    282305<?php endif; ?>
    283306<?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
    284307<option value="delete"><?php _e('Delete Permanently'); ?></option>
     
    371394<option value="approve"><?php _e('Approve'); ?></option>
    372395<?php endif; ?>
    373396<?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
    374 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
     397<option value="spam"><?php _e('Mark as Spam'); ?></option>
    375398<?php endif; ?>
    376399<?php if ( 'trash' == $comment_status ): ?>
    377400<option value="untrash"><?php _e('Restore'); ?></option>
    378401<?php endif; ?>
    379402<?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
    380403<option value="delete"><?php _e('Delete Permanently'); ?></option>
     404<?php elseif ( 'spam' == $comment_status ): ?>
     405<option value="unspam"><?php _e('Not Spam'); ?></option>
    381406<?php else: ?>
    382407<option value="trash"><?php _e('Move to Trash'); ?></option>
    383408<?php endif; ?>
  • wp-admin/admin-ajax.php

     
    209209        $status = wp_get_comment_status( $comment->comment_ID );
    210210
    211211        if ( isset($_POST['trash']) && 1 == $_POST['trash'] ) {
    212                 if ( 'trash' == $status )
    213                         die( (string) time() );
     212                if ( 'trash' == $status ) die( (string) time() );
    214213                $r = wp_trash_comment( $comment->comment_ID );
    215214        } elseif ( isset($_POST['untrash']) && 1 == $_POST['untrash'] ) {
    216                 if ( 'trash' != $status )
    217                         die( (string) time() );
     215                if ( 'trash' != $status ) die( (string) time() );
    218216                $r = wp_untrash_comment( $comment->comment_ID );
    219217        } elseif ( isset($_POST['spam']) && 1 == $_POST['spam'] ) {
    220                 if ( 'spam' == $status )
    221                         die( (string) time() );
    222                 $r = wp_set_comment_status( $comment->comment_ID, 'spam' );
     218                if ( 'spam' == $status ) die( (string) time() );
     219                $r = wp_spam_comment( $comment->comment_ID );
     220        } elseif ( isset($_POST['unspam']) && 1 == $_POST['unspam'] ) {
     221                if ( 'spam' != $status ) die( (string) time() );
     222                $r = wp_unspam_comment( $comment->comment_ID );
    223223        } elseif ( isset($_POST['delete']) && 1 == $_POST['delete'] ) {
    224224                $r = wp_delete_comment( $comment->comment_ID );
    225225        } else {
  • wp-admin/includes/template.php

     
    21142114                $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
    21152115                $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
    21162116
    2117                 $delete_url = esc_url( "comment.php?action=deletecomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
    21182117                $approve_url = esc_url( "comment.php?action=approvecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
    21192118                $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$post->ID&c=$comment->comment_ID&$approve_nonce" );
    2120                 $spam_url = esc_url( "comment.php?action=deletecomment&dt=spam&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
     2119                $spam_url = esc_url( "comment.php?action=spamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
     2120                $unspam_url = esc_url( "comment.php?action=unspamcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
    21212121                $trash_url = esc_url( "comment.php?action=trashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
    21222122                $untrash_url = esc_url( "comment.php?action=untrashcomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
     2123                $delete_url = esc_url( "comment.php?action=deletecomment&p=$post->ID&c=$comment->comment_ID&$del_nonce" );
    21232124        }
    21242125
    21252126        echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
     
    21602161                                $actions = array();
    21612162
    21622163                                if ( $user_can ) {
    2163                                         if ( 'trash' == $the_comment_status ) {
     2164                                        if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
     2165                                                if ( 'approved' == $the_comment_status )
     2166                                                        $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
     2167                                                else if ( 'unapproved' == $the_comment_status )
     2168                                                        $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
     2169                                        } else {
     2170                                                $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
     2171                                                $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
     2172                                        }
     2173                                       
     2174                                        if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
     2175                                                $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
     2176                                        } elseif ( 'spam' == $the_comment_status ) {
     2177                                                $actions['unspam'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:ABF888:unspam=1 vim-z vim-destructive'>" . __( 'Not Spam' ) . '</a>';
     2178                                        } elseif ( 'trash' == $the_comment_status ) {
    21642179                                                $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:ABF888:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
     2180                                        }
     2181                                       
     2182                                        if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
    21652183                                                $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
    21662184                                        } else {
    2167                                                 $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
    2168                                                 $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
    2169 
    2170                                                 if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
    2171                                                         if ( 'approved' == $the_comment_status ) {
    2172                                                                 $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved vim-u vim-destructive' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
    2173                                                                 unset($actions['approve']);
    2174                                                         } else {
    2175                                                                 $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved vim-a vim-destructive' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
    2176                                                                 unset($actions['unapprove']);
    2177                                                         }
    2178                                                 }
    2179 
    2180                                                 if ( 'spam' != $the_comment_status ) {
    2181                                                         $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
    2182                                                 }
    2183                                                 if ( 'spam' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
    2184                                                         $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
    2185                                                 } else {
    2186                                                         $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . __( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
    2187                                                 }
    2188 
     2185                                                $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . __( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
     2186                                        }
     2187                                       
     2188                                        if ( 'trash' != $the_comment_status ) {
    21892189                                                $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
    21902190                                                $actions['quickedit'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\');return false;" class="vim-q" title="'.__('Quick Edit').'" href="#">' . __('Quick&nbsp;Edit') . '</a>';
    2191 
    21922191                                                if ( 'spam' != $the_comment_status )
    21932192                                                        $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\');return false;" class="vim-r" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
    21942193                                        }
     
    22042203                                                // Reply and quickedit need a hide-if-no-js span when not added with ajax
    22052204                                                if ( ('reply' == $action || 'quickedit' == $action) && ! $from_ajax )
    22062205                                                        $action .= ' hide-if-no-js';
    2207                                                 elseif ($action == 'untrash' && $the_comment_status == 'trash') {
    2208                                                         if ('1' == get_comment_meta($comment_id, '_wp_trash_meta_status', true))
     2206                                                elseif (($action == 'untrash' && $the_comment_status == 'trash') || ($action == 'unspam' && $the_comment_status == 'spam')) {
     2207                                                        if ('1' == get_comment_meta($comment_id, '_wp_previous_status', true))
    22092208                                                                $action .= ' approve';
    22102209                                                        else
    22112210                                                                $action .= ' unapprove';
     
    23712370 */
    23722371function wp_comment_trashnotice() {
    23732372?>
    2374 <div class="hidden" id="undo-holder">
    2375 <div class="trash-undo-inside"><?php _e('Comment by'); ?> <strong></strong> <?php _e('moved to the trash.'); ?> <span class="untrash"><a class="undo-trash" href="#"><?php _e('Undo'); ?></a></span></div>
     2373<div class="hidden" id="trash-undo-holder">
     2374        <div class="trash-undo-inside"><?php printf(__('Comment by %s moved to the trash.'), '<strong></strong>'); ?> <span class="undo untrash"><a href="#"><?php _e('Undo'); ?></a></span></div>
    23762375</div>
     2376<div class="hidden" id="spam-undo-holder">
     2377        <div class="spam-undo-inside"><?php printf(__('Comment by %s marked as spam.'), '<strong></strong>'); ?> <span class="undo unspam"><a href="#"><?php _e('Undo'); ?></a></span></div>
     2378</div>
    23772379<?php
    23782380}
    23792381
  • wp-admin/js/edit-comments.dev.js

     
    3838                settings.data._per_page = perPageInput.val() || 0;
    3939                settings.data._page = pageInput.val() || 0;
    4040                settings.data._url = document.location.href;
     41               
     42                var action;
     43                if ( cl.indexOf(':trash=1') != -1 )
     44                        action = 'trash';
     45                else if ( cl.indexOf(':spam=1') != -1 )
     46                        action = 'spam';
    4147
    42                 if ( cl.indexOf(':trash=1') != -1 ) {
     48                if ( action == 'trash' || action == 'spam' ) {
    4349                        id = cl.replace(/.*?comment-([0-9]+).*/, '$1');
    4450                        el = $('#comment-' + id);
    45                         note = $('#undo-holder').html();
     51                        note = $('#'+action+'-undo-holder').html();
    4652
    4753                        if ( el.siblings('#replyrow').length && commentReply.cid == id )
    4854                                commentReply.close();
     
    5056                        if ( el.is('tr') ) {
    5157                                n = el.children(':visible').length;
    5258                                author = $('.author strong', el).text();
    53                                 h = $('<tr id="trashundo-' + id + '" class="trash-undo" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
     59                                h = $('<tr id="undo-' + id + '" class="undo un' + action + '" style="display:none;"><td colspan="' + n + '">' + note + '</td></tr>');
    5460                        } else {
    5561                                author = $('.comment-author', el).text();
    56                                 h = $('<div id="trashundo-' + id + '" style="display:none;" class="trash-undo">' + note + '</div>');
     62                                h = $('<div id="undo-' + id + '" style="display:none;" class="undo un' + action + '">' + note + '</div>');
    5763                        }
    5864
    5965                        el.before(h);
    6066
    61                         $('strong', '#trashundo-' + id).text(author + ' ');
    62                         a = $('a.undo-trash', '#trashundo-' + id);
    63                         a.attr('href', 'comment.php?action=untrashcomment&c=' + id + '&_ajax_nonce=' + settings.data._ajax_nonce);
    64                         a.attr('className', 'delete:the-comment-list:comment-' + id + '::untrash=1 vim-z vim-destructive');
    65                         $('.avatar', el).clone().prependTo('#trashundo-' + id + ' .trash-undo-inside');
     67                        $('strong', '#undo-' + id).text(author + ' ');
     68                        a = $('.undo a', '#undo-' + id);
     69                        a.attr('href', 'comment.php?action=un' + action + 'comment&c=' + id + '&_wpnonce=' + settings.data._ajax_nonce);
     70                        a.attr('className', 'delete:the-comment-list:comment-' + id + '::un' + action + '=1 vim-z vim-destructive');
     71                        $('.avatar', el).clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
    6672
    6773                        a.click(function(){
    6874                                list.wpList.del(this);
    69                                 $('#trashundo-' + id).fadeOut(300, function(){
     75                                $('#undo-' + id).fadeOut(300, function(){
    7076                                        $(this).remove();
    7177                                        $('#comment-' + id).css('backgroundColor', '').fadeIn(300, function(){ $(this).show() });
    7278                                });
     
    135141
    136142        // In admin-ajax.php, we send back the unix time stamp instead of 1 on success
    137143        delAfter = function( r, settings ) {
    138                 var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), spam, trash;
     144                var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), unspam = $(settings.target).parent().is('span.unspam'), spam, trash;
    139145
    140146                function getUpdate(s) {
    141147                        if ( $(settings.target).parent().is('span.' + s) )
     
    150156
    151157                if ( untrash )
    152158                        trash = -1;
     159                if ( unspam )
     160                        spam = -1;
    153161
    154162                $('span.pending-count').each( function() {
    155163                        var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved');
    156164
    157                         if ( $(settings.target).parent().is('span.unapprove') || ( untrash && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
     165                        if ( $(settings.target).parent().is('span.unapprove') || ( (untrash||unspam) && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
    158166                                n = n + 1;
    159167                        } else if ( unapproved ) { // we deleted a formerly unapproved comment
    160168                                n = n - 1;
     
    212220                .bind('wpListDelEnd', function(e, s){
    213221                        var id = s.element.replace(/[^0-9]+/g, '');
    214222
    215                         if ( s.target.className.indexOf(':trash=1') != -1 )
    216                                 $('#trashundo-' + id).fadeIn(300, function(){ $(this).show() });
     223                        if ( s.target.className.indexOf(':trash=1') != -1 || s.target.className.indexOf(':spam=1') != -1 )
     224                                $('#undo-' + id).fadeIn(300, function(){ $(this).show() });
    217225                });
    218226};
    219227
  • wp-admin/comment.php

     
    168168
    169169case 'trashcomment' :
    170170case 'untrashcomment' :
     171case 'spamcomment' :
     172case 'unspamcomment' :
    171173        $comment_id = absint( $_REQUEST['c'] );
    172174        $noredir = isset($_REQUEST['noredir']);
    173175
     
    185187        else
    186188                $redir = admin_url('edit-comments.php');
    187189
    188         $redir = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), $redir );
     190        $redir = remove_query_arg( array('spammed', 'unspammed', 'trashed', 'untrashed', 'deleted', 'ids'), $redir );
    189191
    190         if ( $action == 'trashcomment' ) {
    191                 wp_trash_comment($comment_id);
    192                 $redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
    193         } else {
    194                 wp_untrash_comment($comment_id);
    195                 $redir = add_query_arg( array('untrashed' => '1'), $redir );
     192        switch ( $action ) {
     193                case 'trashcomment' :
     194                        wp_trash_comment($comment_id);
     195                        $redir = add_query_arg( array('trashed' => '1', 'ids' => $comment_id), $redir );
     196                        break;
     197                case 'untrashcomment' :
     198                        wp_untrash_comment($comment_id);
     199                        $redir = add_query_arg( array('untrashed' => '1'), $redir );
     200                        break;
     201                case 'spamcomment' :
     202                        wp_spam_comment($comment_id);
     203                        $redir = add_query_arg( array('spammed' => '1', 'ids' => $comment_id), $redir );
     204                        break;
     205                case 'unspamcomment' :
     206                        wp_unspam_comment($comment_id);
     207                        $redir = add_query_arg( array('unspammed' => '1'), $redir );
     208                        break;
    196209        }
    197210
    198211        wp_redirect( $redir );
  • wp-admin/wp-admin.dev.css

     
    35243524        font-size: 11px;
    35253525}
    35263526
    3527 .trash-undo-inside {
     3527.trash-undo-inside,
     3528.spam-undo-inside {
    35283529        margin: 1px 8px 1px 0;
    35293530        line-height: 16px;
    35303531}
    35313532
     3533.spam-undo-inside .avatar,
    35323534.trash-undo-inside .avatar {
    35333535        height: 20px;
    35343536        width: 20px;