WordPress.org

Make WordPress Core

Ticket #4529: delete-comment.diff

File delete-comment.diff, 7.0 KB (added by caesarsgrunt, 6 years ago)

Temporary deletion of comments, first attempt.

  • wp-admin/edit-comments.php

     
    100100$stati = array( 
    101101                'moderated' => sprintf(__ngettext('Awaiting Moderation (%s)', 'Awaiting Moderation (%s)', number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"), 
    102102                'approved' => _c('Approved|plural'), 
    103                 'spam' => sprintf(__ngettext('Spam (%s)', 'Spam (%s)', number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>") 
     103                'spam' => sprintf(__ngettext('Spam (%s)', 'Spam (%s)', number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>"), 
     104                'deleted' => sprintf(__ngettext('Deleted (%s)', 'Deleted (%s)', number_format_i18n($num_comments->deleted) ), "<span class='deleted-comment-count'>" . number_format_i18n($num_comments->deleted) . "</span>") 
    104105        ); 
    105106$class = ( '' === $comment_status ) ? ' class="current"' : ''; 
    106107$status_links[] = "<li><a href=\"edit-comments.php\"$class>".__('Show All Comments')."</a>"; 
     
    183184<?php if ( 'spam' != $comment_status ): ?> 
    184185<option value="markspam"><?php _e('Mark as Spam'); ?></option> 
    185186<?php endif; ?> 
     187<?php if ( 'deleted' != $comment_status ): ?> 
    186188<option value="delete"><?php _e('Delete'); ?></option> 
     189<?php else : ?> 
     190<option value="delete"><?php _e('Delete Permenantly'); ?></option> 
     191<?php endif; ?> 
    187192</select> 
    188193<input type="submit" name="doaction" value="Apply" class="button-secondary apply" /> 
    189194<?php do_action('manage_comments_nav', $comment_status); ?> 
  • wp-admin/admin-ajax.php

     
    182182        if ( $_POST['new'] == $current ) 
    183183                die('1'); 
    184184 
    185         if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { 
     185        if ( in_array( $current, array( 'unapproved', 'spam', 'deleted' ) ) ) { 
    186186                check_ajax_referer( "approve-comment_$id" ); 
    187187                if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) ) 
    188188                        die('1'); 
  • wp-admin/wp-admin.css

     
    249249        display: none; 
    250250} 
    251251 
    252 .unapproved .approve, .spam .approve { 
     252.unapproved .approve, .spam .approve, .deleted .approve { 
    253253        display: inline; 
    254254} 
    255255 
  • wp-admin/includes/template.php

     
    948948                $approved = "comment_approved = '1'"; 
    949949        elseif ( 'spam' == $status ) 
    950950                $approved = "comment_approved = 'spam'"; 
     951        elseif ( 'deleted' == $status ) 
     952                $approved = "comment_approved = 'deleted'"; 
    951953        else 
    952954                $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 
    953955 
     
    10211023                $actions['edit']      = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a> | '; 
    10221024                if ( 'spam' != $the_comment_status ) 
    10231025                        $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' ) . "'>" . __( 'Spam' ) . '</a> | '; 
    1024                 $actions['delete']    = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>'; 
     1026                if ( 'deleted' == $the_comment_status ) 
     1027                        $actions['delete']    = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>'; 
     1028                else 
     1029                        $actions['delete']    = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>'; 
    10251030 
    10261031                if ( $comment_status ) { // not looking at all comments 
    10271032                        if ( 'approved' == $the_comment_status ) { 
     
    10331038                        } 
    10341039                } 
    10351040 
    1036                 if ( 'spam' != $the_comment_status ) 
     1041                if ( 'spam' != $the_comment_status && 'deleted' != $the_comment_status ) 
    10371042                        $actions['reply'] = '<span class="hide-if-no-js"> | <a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\',this);return false;" class="vim-r" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a></span>'; 
    10381043 
    10391044                $actions = apply_filters( 'comment_row_actions', $actions, $comment ); 
  • wp-admin/js/edit-comments.js

     
    6767                        if ( n < 0 ) { n = 0; } 
    6868                        a.html( n.toString() ); 
    6969                }); 
     70                $('li span.deleted-comment-count' ).each( function() { 
     71                        var a = $(this); 
     72                        var n = parseInt(a.html(),10); 
     73                        if ( $(settings.target).parents( 'span.delete' ).size() && !$('#' + settings.element).is('.deleted') ) { // we deleted a comment 
     74                                n = n + 1; 
     75                        } else if ( $('#' + settings.element).is('.deleted') ) { // we approved or deleted a deleted comment 
     76                                n = n - 1; 
     77                        } 
     78                        if ( n < 0 ) { n = 0; } 
     79                        a.html( n.toString() ); 
     80                }); 
    7081         
    7182                if ( theExtraList.size() == 0 || theExtraList.children().size() == 0 ) { 
    7283                        return; 
  • wp-includes/comment.php

     
    540540 
    541541        $total = 0; 
    542542        $stats = array( ); 
    543         $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam'); 
     543        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'deleted' => 'deleted'); 
    544544        foreach( (array) $count as $row_num => $row ) { 
    545545                $total += $row['num_comments']; 
    546546                $stats[$approved[$row['comment_approved']]] = $row['num_comments']; 
     
    578578 
    579579        $comment = get_comment($comment_id); 
    580580 
    581         if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) 
    582                 return false; 
     581        if ($comment->comment_approved == 'deleted') 
     582                return $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ); 
     583        else 
     584                return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='deleted' WHERE comment_ID = %d LIMIT 1", $comment_id) ); 
     585//      if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) 
     586//      if ( ! $wpdb->query( $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='deleted' WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) 
     587//              return false; 
    583588 
    584589        $post_id = $comment->comment_post_ID; 
    585590        if ( $post_id && $comment->comment_approved == 1 ) 
     
    614619                return 'unapproved'; 
    615620        elseif ( $approved == 'spam' ) 
    616621                return 'spam'; 
     622        elseif ( $approved == 'deleted' ) 
     623                return 'deleted'; 
    617624        else 
    618625                return false; 
    619626}