WordPress.org

Make WordPress Core

Ticket #4529: delete-comment.5.diff

File delete-comment.5.diff, 14.9 KB (added by caesarsgrunt, 5 years ago)

With automatic permanent deletion after 30 days

  • wp-includes/comment.php

     
    208208                $approved = "comment_approved = '1'"; 
    209209        elseif ( 'spam' == $status ) 
    210210                $approved = "comment_approved = 'spam'"; 
     211        elseif ( 'deleted' == $status ) 
     212                $approved = "comment_approved = 'deleted'"; 
    211213        else 
    212214                $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 
    213215 
     
    699701        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); 
    700702 
    701703        $total = 0; 
    702         $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam'); 
     704        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'deleted' => 'deleted'); 
    703705        $known_types = array_keys( $approved ); 
    704706        foreach( (array) $count as $row_num => $row ) { 
    705707                $total += $row['num_comments']; 
     
    735737 * @return bool False if delete comment query failure, true on success. 
    736738 */ 
    737739function wp_delete_comment($comment_id) { 
     740        if (wp_get_comment_status($comment_id) != 'deleted') 
     741                return wp_set_comment_status($comment_id, 'delete'); 
     742         
    738743        global $wpdb; 
    739744        do_action('delete_comment', $comment_id); 
     745         
     746        wp_unschedule_event(wp_next_scheduled('wp_cron_delete_comment', array($comment_id)), 'wp_cron_delete_comment', array($comment_id)); 
    740747 
    741748        $comment = get_comment($comment_id); 
    742749 
     
    760767        wp_transition_comment_status('delete', $comment->comment_approved, $comment); 
    761768        return true; 
    762769} 
     770add_action('wp_cron_delete_comment','wp_delete_comment'); 
    763771 
    764772/** 
    765773 * The status of a comment by ID. 
     
    784792                return 'unapproved'; 
    785793        elseif ( $approved == 'spam' ) 
    786794                return 'spam'; 
     795        elseif ( $approved == 'deleted' ) 
     796                return 'deleted'; 
    787797        else 
    788798                return false; 
    789799} 
     
    10291039function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) { 
    10301040        global $wpdb; 
    10311041 
     1042        if (wp_get_comment_status($comment_id) == 'deleted') 
     1043                wp_unschedule_event(wp_next_scheduled('wp_cron_delete_comment', array($comment_id)), 'wp_cron_delete_comment', array($comment_id)); 
     1044         
    10321045        $status = '0'; 
    10331046        switch ( $comment_status ) { 
    10341047                case 'hold': 
     
    10451058                        $status = 'spam'; 
    10461059                        break; 
    10471060                case 'delete': 
    1048                         return wp_delete_comment($comment_id); 
     1061                        if (wp_get_comment_status($comment_id) == 'deleted') 
     1062                                return wp_delete_comment($comment_id); 
     1063                        $status = 'deleted'; 
     1064                        wp_schedule_single_event(time()+(60*60*24*30), 'wp_cron_delete_comment', array($comment_id)); 
    10491065                        break; 
    10501066                default: 
    10511067                        return false; 
  • wp-admin/edit-comments.php

     
    8686$mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']); 
    8787 
    8888$comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all'; 
    89 if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam')) ) 
     89if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'deleted')) ) 
    9090        $comment_status = 'all'; 
    9191 
    9292$comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : ''; 
     
    141141                'all' => _n_noop('All', 'All'), // singular not used 
    142142                'moderated' => _n_noop('Pending (<span class="pending-count">%s</span>)', 'Pending (<span class="pending-count">%s</span>)'), 
    143143                'approved' => _n_noop('Approved', 'Approved'), // singular not used 
    144                 'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)') 
     144                'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)'), 
     145                'deleted' => _n_noop('Deleted (<span class="deleted-count">%s</span>)', 'Deleted (<span class="deleted-count">%s</span>)') 
    145146        ); 
    146147$link = 'edit-comments.php'; 
    147148if ( !empty($comment_type) && 'all' != $comment_type ) 
     
    246247<?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?> 
    247248<option value="unapprove"><?php _e('Unapprove'); ?></option> 
    248249<?php endif; ?> 
    249 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?> 
     250<?php if ( 'approved' != $comment_status ): ?> 
    250251<option value="approve"><?php _e('Approve'); ?></option> 
    251252<?php endif; ?> 
    252253<?php if ( 'spam' != $comment_status ): ?> 
    253254<option value="markspam"><?php _e('Mark as Spam'); ?></option> 
    254255<?php endif; ?> 
     256<?php if ( 'deleted' == $comment_status ): ?> 
     257<option value="delete"><?php _e('Delete Permanently'); ?></option> 
     258<?php else: ?> 
    255259<option value="delete"><?php _e('Delete'); ?></option> 
     260<?php endif; ?> 
    256261</select> 
    257262<input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" /> 
    258263<?php wp_nonce_field('bulk-comments'); ?> 
     
    333338<?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?> 
    334339<option value="unapprove"><?php _e('Unapprove'); ?></option> 
    335340<?php endif; ?> 
    336 <?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?> 
     341<?php if ( 'approved' != $comment_status ): ?> 
    337342<option value="approve"><?php _e('Approve'); ?></option> 
    338343<?php endif; ?> 
    339344<?php if ( 'spam' != $comment_status ): ?> 
    340345<option value="markspam"><?php _e('Mark as Spam'); ?></option> 
    341346<?php endif; ?> 
     347<?php if ( 'deleted' == $comment_status ): ?> 
     348<option value="delete"><?php _e('Delete Permanently'); ?></option> 
     349<?php else: ?> 
    342350<option value="delete"><?php _e('Delete'); ?></option> 
     351<?php endif; ?> 
    343352</select> 
    344353<input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" /> 
    345354 
  • wp-admin/admin-ajax.php

     
    192192                        die( (string) time() ); 
    193193                $r = wp_set_comment_status( $comment->comment_ID, 'spam' ); 
    194194        } else { 
    195                 $r = wp_delete_comment( $comment->comment_ID ); 
     195                $r = wp_set_comment_status( $comment->comment_ID, 'delete' ); 
    196196        } 
    197197        if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts 
    198198                _wp_ajax_delete_comment_response( $comment->comment_ID ); 
     
    336336                die( (string) time() ); 
    337337 
    338338        $r = 0; 
    339         if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) { 
     339        if ( in_array( $current, array( 'unapproved', 'spam', 'deleted' ) ) ) { 
    340340                check_ajax_referer( "approve-comment_$id" ); 
    341341                $result = wp_set_comment_status( $comment->comment_ID, 'approve', true ); 
    342342        } else { 
  • wp-admin/wp-admin.css

     
    444444        display: none; 
    445445} 
    446446 
    447 .unapproved .approve, .spam .approve { 
     447.unapproved .approve, .spam .approve, .deleted .approve { 
    448448        display: inline; 
    449449} 
    450450 
  • wp-admin/includes/template.php

     
    20122012        } elseif ( 'spam' == $status ) { 
    20132013                $approved = "comment_approved = 'spam'"; 
    20142014                $total = $count->spam; 
     2015        } elseif ( 'deleted' == $status ) { 
     2016                $approved = "comment_approved = 'deleted'"; 
     2017                $total = $count->deleted; 
    20152018        } else { 
    20162019                $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 
    20172020                $total = $count->moderated + $count->approved; 
     
    21512154                                        } 
    21522155                                        if ( 'spam' != $the_comment_status ) 
    21532156                                                $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>'; 
    2154                                         $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>'; 
     2157                                        if ( 'deleted' == $the_comment_status ) 
     2158                                                $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::deleted=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>'; 
     2159                                        else 
     2160                                                $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>'; 
    21552161                                        $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>'; 
    21562162                                        $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>'; 
    2157                                         if ( 'spam' != $the_comment_status ) 
     2163                                        if ( 'spam' != $the_comment_status && 'deleted' != $the_comment_status ) 
    21582164                                                $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\');return false;" class="vim-r" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>'; 
    21592165 
    21602166                                        $actions = apply_filters( 'comment_row_actions', $actions, $comment ); 
  • wp-admin/js/edit-comments.dev.js

     
    3838                settings.data._page = pageInput.val(); 
    3939                settings.data._url = document.location.href; 
    4040 
    41                 if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && !settings.data.spam ) 
     41                if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && settings.data.deleted) 
    4242                        return showNotice.warn() ? settings : false; 
    4343 
    4444                return settings; 
     
    101101                        a.html(n); 
    102102                }); 
    103103 
     104                $('span.deleted-count').each( function() { 
     105                        var a = $(this), n; 
     106                        n = a.html().replace(/[ ,.]+/g, ''); 
     107                        n = parseInt(n,10); 
     108                        if ( isNaN(n) ) return; 
     109                        if ( $(settings.target).parents( 'span.delete' ).size() && $('#' + settings.element).is('.deleted') ) { // we destroyed a deleted comment 
     110                                n--; 
     111                        } else if ( $(settings.target).parents( 'span.delete' ).size() ) { // we deleted a comment 
     112                                n++; 
     113                        } else if ( $('#' + settings.element).is('.deleted') ) { // we approved or spammed a deleted comment 
     114                                n--; 
     115                        } 
     116                        if ( n < 0 ) { n = 0; } 
     117                        n = n.toString(); 
     118                        if ( n.length > 3 ) 
     119                                n = n.substr(0, n.length-3)+' '+n.substr(-3); 
     120                        a.html(n); 
     121                }); 
    104122 
     123 
    105124                // XML response 
    106125                if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) { 
    107126                        // Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links) 
  • wp-admin/edit-form-comment.php

     
    3838<div class="submitbox" id="submitcomment"> 
    3939<div id="minor-publishing"> 
    4040 
     41<?php if ($comment->comment_approved == '1') { ?> 
    4142<div id="minor-publishing-actions"> 
    4243<div id="preview-action"> 
    4344<a class="preview button" href="<?php echo get_comment_link(); ?>" target="_blank"><?php _e('View Comment'); ?></a> 
    4445</div> 
    4546<div class="clear"></div> 
    4647</div> 
     48<?php } ?> 
    4749 
    4850<div id="misc-publishing-actions"> 
    4951 
    5052<div class="misc-pub-section" id="comment-status-radio"> 
    5153<label class="approved"><input type="radio"<?php checked( $comment->comment_approved, '1' ); ?> name="comment_status" value="1" /><?php /* translators: comment type radio button */ echo _x('Approved', 'adjective') ?></label><br /> 
    5254<label class="waiting"><input type="radio"<?php checked( $comment->comment_approved, '0' ); ?> name="comment_status" value="0" /><?php /* translators: comment type radio button */ echo _x('Pending', 'adjective') ?></label><br /> 
    53 <label class="spam"><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php /* translators: comment type radio button */ echo _x('Spam', 'adjective'); ?></label> 
     55<label class="spam"><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php /* translators: comment type radio button */ echo _x('Spam', 'adjective'); ?></label><br /> 
     56<?php if ($comment->comment_approved == 'deleted') { ?> 
     57<label class="deleted"><input type="radio"<?php checked( $comment->comment_approved, 'deleted' ); ?> name="comment_status" value="deleted" /><?php /* translators: comment type radio button */ echo _x('Deleted', 'adjective'); ?></label> 
     58<?php } ?> 
    5459</div> 
    5560 
    5661<div class="misc-pub-section curtime misc-pub-section-last"> 
     
    6974 
    7075<div id="major-publishing-actions"> 
    7176<div id="delete-action"> 
    72 <?php echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "' onclick=\"if ( confirm('" . esc_js(__("You are about to delete this comment. \n  'Cancel' to stop, 'OK' to delete.")) . "') ){return true;}return false;\">" . __('Delete') . "</a>\n"; ?> 
     77<?php 
     78if ($comment->comment_approved == 'deleted') 
     79        echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "' onclick=\"if ( confirm('" . esc_js(__("You are about to delete this comment. \n  'Cancel' to stop, 'OK' to delete.")) . "') ){return true;}return false;\">" . __('Delete Permanently') . "</a>\n"; 
     80else 
     81        echo "<a class='submitdelete deletion' href='" . wp_nonce_url("comment.php?action=deletecomment&amp;c=$comment->comment_ID&amp;_wp_original_http_referer=" . urlencode(wp_get_referer()), 'delete-comment_' . $comment->comment_ID) . "'>" . __('Delete') . "</a>\n"; 
     82?> 
    7383</div> 
    7484<div id="publishing-action"> 
    7585<input type="submit" name="save" value="<?php esc_attr_e('Update Comment'); ?>" tabindex="4" class="button-primary" /> 
  • wp-admin/css/colors-fresh.css

     
    5858        border-color: #ccc; 
    5959} 
    6060 
    61 #poststuff .inside label.spam { 
     61#poststuff .inside label.spam, 
     62#poststuff .inside label.deleted { 
    6263        color: red; 
    6364} 
    6465 
  • wp-admin/css/colors-classic.css

     
    5858        border-color: #ccc; 
    5959} 
    6060 
    61 #poststuff .inside label.spam { 
     61#poststuff .inside label.spam, 
     62#poststuff .inside label.deleted { 
    6263        color: red; 
    6364} 
    6465