WordPress.org

Make WordPress Core

Ticket #4529: delete-comment.3.diff

File delete-comment.3.diff, 8.1 KB (added by caesarsgrunt, 7 years ago)

Updated patch, due to major changes in the WP core...

  • wp-admin/edit-comments.php

     
    122122$stati = array( 
    123123                '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>"), 
    124124                'approved' => _c('Approved|plural'), 
    125                 '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>") 
     125                '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>"), 
     126                '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>") 
    126127        ); 
    127128$class = ( '' === $comment_status ) ? ' class="current"' : ''; 
    128129$status_links[] = "<li><a href=\"edit-comments.php\"$class>".__('Show All Comments')."</a>"; 
     
    184185<?php if ( empty($comment_status) || 'approved' == $comment_status ): ?> 
    185186<option value="unapprove"><?php _e('Unapprove'); ?></option> 
    186187<?php endif; ?> 
    187 <?php if ( empty($comment_status) || 'moderated' == $comment_status ): ?> 
     188<?php if ( empty($comment_status) || 'approved' != $comment_status ): ?> 
    188189<option value="approve"><?php _e('Approve'); ?></option> 
    189190<?php endif; ?> 
    190 <?php if ( 'spam' != $comment_status ): ?> 
     191<?php if ( 'spam' != $comment_status && 'deleted' != $comment_status ): ?> 
    191192<option value="markspam"><?php _e('Mark as Spam'); ?></option> 
    192193<?php endif; ?> 
     194<?php if ( 'deleted' != $comment_status ): ?> 
    193195<option value="delete"><?php _e('Delete'); ?></option> 
     196<?php else : ?> 
     197<option value="delete"><?php _e('Delete Permenantly'); ?></option> 
     198<?php endif; ?> 
    194199</select> 
    195200<input type="submit" name="doaction" id="doaction" value="<?php _e('Apply'); ?>" class="button-secondary apply" /> 
    196201<?php wp_nonce_field('bulk-comments'); ?> 
  • wp-admin/admin-ajax.php

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

     
    258258        display: none; 
    259259} 
    260260 
    261 .unapproved .approve, .spam .approve { 
     261.unapproved .approve, .spam .approve, .deleted .approve { 
    262262        display: inline; 
    263263} 
    264264 
  • wp-admin/includes/template.php

     
    15421542                $approved = "comment_approved = '1'"; 
    15431543        elseif ( 'spam' == $status ) 
    15441544                $approved = "comment_approved = 'spam'"; 
     1545        elseif ( 'deleted' == $status ) 
     1546                $approved = "comment_approved = 'deleted'"; 
    15451547        else 
    15461548                $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 
    15471549 
     
    16421644                                        } 
    16431645                                        if ( 'spam' != $the_comment_status ) 
    16441646                                                $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>'; 
    1645                                         $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>'; 
     1647                                        if ( 'deleted' == $the_comment_status ) 
     1648                                                $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>'; 
     1649                                        else 
     1650                                                $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>'; 
    16461651                                        $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>'; 
    16471652                                        if ( 'spam' != $the_comment_status ) 
    16481653                                                $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\',this);return false;" class="vim-r" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>'; 
  • 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

     
    568568 
    569569        $total = 0; 
    570570        $stats = array( ); 
    571         $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam'); 
     571        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'deleted' => 'deleted'); 
    572572        foreach( (array) $count as $row_num => $row ) { 
    573573                $total += $row['num_comments']; 
    574574                $stats[$approved[$row['comment_approved']]] = $row['num_comments']; 
     
    605605        do_action('delete_comment', $comment_id); 
    606606 
    607607        $comment = get_comment($comment_id); 
     608         
     609        if ($comment->comment_approved == 'deleted' && $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id))) { 
     610                return true; 
     611        } 
     612        else if ($wpdb->query($wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='deleted' WHERE comment_ID = %d LIMIT 1", $comment_id))) { 
     613                wp_schedule_single_event(time()+(60*60*24*30), 'wp_delete_comment', array($comment_id)); 
     614                return true; 
     615        } 
     616        else return false; 
    608617 
    609         if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) ) 
    610                 return false; 
    611  
    612618        $post_id = $comment->comment_post_ID; 
    613619        if ( $post_id && $comment->comment_approved == 1 ) 
    614620                wp_update_comment_count($post_id); 
     
    618624        do_action('wp_set_comment_status', $comment_id, 'delete'); 
    619625        return true; 
    620626} 
     627add_action('wp_delete_comment','wp_delete_comment');    // Needed for scheduled deletion using wp_cron. 
    621628 
    622629/** 
    623630 * The status of a comment by ID. 
     
    642649                return 'unapproved'; 
    643650        elseif ( $approved == 'spam' ) 
    644651                return 'spam'; 
     652        elseif ( $approved == 'deleted' ) 
     653                return 'deleted'; 
    645654        else 
    646655                return false; 
    647656} 
     
    839848 */ 
    840849function wp_set_comment_status($comment_id, $comment_status) { 
    841850        global $wpdb; 
    842  
     851         
    843852        switch ( $comment_status ) { 
    844853                case 'hold': 
    845854                        $query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID = %d LIMIT 1", $comment_id); 
     
    850859                                $comment = get_comment($comment_id); 
    851860                                wp_notify_postauthor($comment_id, $comment->comment_type); 
    852861                        } 
     862                        wp_unschedule_event(wp_next_scheduled('wp_delete_comment', array($comment_id)), 'wp_delete_comment', array($comment_id));       // Unschedule comment for deletion, if scheduled 
    853863                        break; 
    854864                case 'spam': 
    855865                        $query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID = %d LIMIT 1", $comment_id);