Ticket #4529: delete-comment.5.diff

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

With automatic permanent deletion after 30 days

Line 
1Index: wp-includes/comment.php
2===================================================================
3--- wp-includes/comment.php     (revision 11707)
4+++ wp-includes/comment.php     (working copy)
5@@ -208,6 +208,8 @@
6                $approved = "comment_approved = '1'";
7        elseif ( 'spam' == $status )
8                $approved = "comment_approved = 'spam'";
9+       elseif ( 'deleted' == $status )
10+               $approved = "comment_approved = 'deleted'";
11        else
12                $approved = "( comment_approved = '0' OR comment_approved = '1' )";
13 
14@@ -699,7 +701,7 @@
15        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
16 
17        $total = 0;
18-       $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam');
19+       $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'deleted' => 'deleted');
20        $known_types = array_keys( $approved );
21        foreach( (array) $count as $row_num => $row ) {
22                $total += $row['num_comments'];
23@@ -735,8 +737,13 @@
24  * @return bool False if delete comment query failure, true on success.
25  */
26 function wp_delete_comment($comment_id) {
27+       if (wp_get_comment_status($comment_id) != 'deleted')
28+               return wp_set_comment_status($comment_id, 'delete');
29+       
30        global $wpdb;
31        do_action('delete_comment', $comment_id);
32+       
33+       wp_unschedule_event(wp_next_scheduled('wp_cron_delete_comment', array($comment_id)), 'wp_cron_delete_comment', array($comment_id));
34 
35        $comment = get_comment($comment_id);
36 
37@@ -760,6 +767,7 @@
38        wp_transition_comment_status('delete', $comment->comment_approved, $comment);
39        return true;
40 }
41+add_action('wp_cron_delete_comment','wp_delete_comment');
42 
43 /**
44  * The status of a comment by ID.
45@@ -784,6 +792,8 @@
46                return 'unapproved';
47        elseif ( $approved == 'spam' )
48                return 'spam';
49+       elseif ( $approved == 'deleted' )
50+               return 'deleted';
51        else
52                return false;
53 }
54@@ -1029,6 +1039,9 @@
55 function wp_set_comment_status($comment_id, $comment_status, $wp_error = false) {
56        global $wpdb;
57 
58+       if (wp_get_comment_status($comment_id) == 'deleted')
59+               wp_unschedule_event(wp_next_scheduled('wp_cron_delete_comment', array($comment_id)), 'wp_cron_delete_comment', array($comment_id));
60+       
61        $status = '0';
62        switch ( $comment_status ) {
63                case 'hold':
64@@ -1045,7 +1058,10 @@
65                        $status = 'spam';
66                        break;
67                case 'delete':
68-                       return wp_delete_comment($comment_id);
69+                       if (wp_get_comment_status($comment_id) == 'deleted')
70+                               return wp_delete_comment($comment_id);
71+                       $status = 'deleted';
72+                       wp_schedule_single_event(time()+(60*60*24*30), 'wp_cron_delete_comment', array($comment_id));
73                        break;
74                default:
75                        return false;
76Index: wp-admin/edit-comments.php
77===================================================================
78--- wp-admin/edit-comments.php  (revision 11707)
79+++ wp-admin/edit-comments.php  (working copy)
80@@ -86,7 +86,7 @@
81 $mode = ( ! isset($_GET['mode']) || empty($_GET['mode']) ) ? 'detail' : esc_attr($_GET['mode']);
82 
83 $comment_status = isset($_REQUEST['comment_status']) ? $_REQUEST['comment_status'] : 'all';
84-if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam')) )
85+if ( !in_array($comment_status, array('all', 'moderated', 'approved', 'spam', 'deleted')) )
86        $comment_status = 'all';
87 
88 $comment_type = !empty($_GET['comment_type']) ? esc_attr($_GET['comment_type']) : '';
89@@ -141,7 +141,8 @@
90                'all' => _n_noop('All', 'All'), // singular not used
91                'moderated' => _n_noop('Pending (<span class="pending-count">%s</span>)', 'Pending (<span class="pending-count">%s</span>)'),
92                'approved' => _n_noop('Approved', 'Approved'), // singular not used
93-               'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)')
94+               'spam' => _n_noop('Spam (<span class="spam-count">%s</span>)', 'Spam (<span class="spam-count">%s</span>)'),
95+               'deleted' => _n_noop('Deleted (<span class="deleted-count">%s</span>)', 'Deleted (<span class="deleted-count">%s</span>)')
96        );
97 $link = 'edit-comments.php';
98 if ( !empty($comment_type) && 'all' != $comment_type )
99@@ -246,13 +247,17 @@
100 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
101 <option value="unapprove"><?php _e('Unapprove'); ?></option>
102 <?php endif; ?>
103-<?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
104+<?php if ( 'approved' != $comment_status ): ?>
105 <option value="approve"><?php _e('Approve'); ?></option>
106 <?php endif; ?>
107 <?php if ( 'spam' != $comment_status ): ?>
108 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
109 <?php endif; ?>
110+<?php if ( 'deleted' == $comment_status ): ?>
111+<option value="delete"><?php _e('Delete Permanently'); ?></option>
112+<?php else: ?>
113 <option value="delete"><?php _e('Delete'); ?></option>
114+<?php endif; ?>
115 </select>
116 <input type="submit" name="doaction" id="doaction" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
117 <?php wp_nonce_field('bulk-comments'); ?>
118@@ -333,13 +338,17 @@
119 <?php if ( 'all' == $comment_status || 'approved' == $comment_status ): ?>
120 <option value="unapprove"><?php _e('Unapprove'); ?></option>
121 <?php endif; ?>
122-<?php if ( 'all' == $comment_status || 'moderated' == $comment_status || 'spam' == $comment_status ): ?>
123+<?php if ( 'approved' != $comment_status ): ?>
124 <option value="approve"><?php _e('Approve'); ?></option>
125 <?php endif; ?>
126 <?php if ( 'spam' != $comment_status ): ?>
127 <option value="markspam"><?php _e('Mark as Spam'); ?></option>
128 <?php endif; ?>
129+<?php if ( 'deleted' == $comment_status ): ?>
130+<option value="delete"><?php _e('Delete Permanently'); ?></option>
131+<?php else: ?>
132 <option value="delete"><?php _e('Delete'); ?></option>
133+<?php endif; ?>
134 </select>
135 <input type="submit" name="doaction2" id="doaction2" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
136 
137Index: wp-admin/admin-ajax.php
138===================================================================
139--- wp-admin/admin-ajax.php     (revision 11707)
140+++ wp-admin/admin-ajax.php     (working copy)
141@@ -192,7 +192,7 @@
142                        die( (string) time() );
143                $r = wp_set_comment_status( $comment->comment_ID, 'spam' );
144        } else {
145-               $r = wp_delete_comment( $comment->comment_ID );
146+               $r = wp_set_comment_status( $comment->comment_ID, 'delete' );
147        }
148        if ( $r ) // Decide if we need to send back '1' or a more complicated response including page links and comment counts
149                _wp_ajax_delete_comment_response( $comment->comment_ID );
150@@ -336,7 +336,7 @@
151                die( (string) time() );
152 
153        $r = 0;
154-       if ( in_array( $current, array( 'unapproved', 'spam' ) ) ) {
155+       if ( in_array( $current, array( 'unapproved', 'spam', 'deleted' ) ) ) {
156                check_ajax_referer( "approve-comment_$id" );
157                $result = wp_set_comment_status( $comment->comment_ID, 'approve', true );
158        } else {
159Index: wp-admin/wp-admin.css
160===================================================================
161--- wp-admin/wp-admin.css       (revision 11707)
162+++ wp-admin/wp-admin.css       (working copy)
163@@ -444,7 +444,7 @@
164        display: none;
165 }
166 
167-.unapproved .approve, .spam .approve {
168+.unapproved .approve, .spam .approve, .deleted .approve {
169        display: inline;
170 }
171 
172Index: wp-admin/includes/template.php
173===================================================================
174--- wp-admin/includes/template.php      (revision 11707)
175+++ wp-admin/includes/template.php      (working copy)
176@@ -2012,6 +2012,9 @@
177        } elseif ( 'spam' == $status ) {
178                $approved = "comment_approved = 'spam'";
179                $total = $count->spam;
180+       } elseif ( 'deleted' == $status ) {
181+               $approved = "comment_approved = 'deleted'";
182+               $total = $count->deleted;
183        } else {
184                $approved = "( comment_approved = '0' OR comment_approved = '1' )";
185                $total = $count->moderated + $count->approved;
186@@ -2151,10 +2154,13 @@
187                                        }
188                                        if ( 'spam' != $the_comment_status )
189                                                $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>';
190-                                       $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
191+                                       if ( 'deleted' == $the_comment_status )
192+                                               $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>';
193+                                       else
194+                                               $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete vim-d vim-destructive'>" . __('Delete') . '</a>';
195                                        $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
196                                        $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>';
197-                                       if ( 'spam' != $the_comment_status )
198+                                       if ( 'spam' != $the_comment_status && 'deleted' != $the_comment_status )
199                                                $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$post->ID.'\');return false;" class="vim-r" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
200 
201                                        $actions = apply_filters( 'comment_row_actions', $actions, $comment );
202Index: wp-admin/js/edit-comments.dev.js
203===================================================================
204--- wp-admin/js/edit-comments.dev.js    (revision 11707)
205+++ wp-admin/js/edit-comments.dev.js    (working copy)
206@@ -38,7 +38,7 @@
207                settings.data._page = pageInput.val();
208                settings.data._url = document.location.href;
209 
210-               if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && !settings.data.spam )
211+               if ( 'undefined' != showNotice && settings.data.action && settings.data.action == 'delete-comment' && settings.data.deleted)
212                        return showNotice.warn() ? settings : false;
213 
214                return settings;
215@@ -101,7 +101,26 @@
216                        a.html(n);
217                });
218 
219+               $('span.deleted-count').each( function() {
220+                       var a = $(this), n;
221+                       n = a.html().replace(/[ ,.]+/g, '');
222+                       n = parseInt(n,10);
223+                       if ( isNaN(n) ) return;
224+                       if ( $(settings.target).parents( 'span.delete' ).size() && $('#' + settings.element).is('.deleted') ) { // we destroyed a deleted comment
225+                               n--;
226+                       } else if ( $(settings.target).parents( 'span.delete' ).size() ) { // we deleted a comment
227+                               n++;
228+                       } else if ( $('#' + settings.element).is('.deleted') ) { // we approved or spammed a deleted comment
229+                               n--;
230+                       }
231+                       if ( n < 0 ) { n = 0; }
232+                       n = n.toString();
233+                       if ( n.length > 3 )
234+                               n = n.substr(0, n.length-3)+' '+n.substr(-3);
235+                       a.html(n);
236+               });
237 
238+
239                // XML response
240                if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
241                        // 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)
242Index: wp-admin/edit-form-comment.php
243===================================================================
244--- wp-admin/edit-form-comment.php      (revision 11707)
245+++ wp-admin/edit-form-comment.php      (working copy)
246@@ -38,19 +38,24 @@
247 <div class="submitbox" id="submitcomment">
248 <div id="minor-publishing">
249 
250+<?php if ($comment->comment_approved == '1') { ?>
251 <div id="minor-publishing-actions">
252 <div id="preview-action">
253 <a class="preview button" href="<?php echo get_comment_link(); ?>" target="_blank"><?php _e('View Comment'); ?></a>
254 </div>
255 <div class="clear"></div>
256 </div>
257+<?php } ?>
258 
259 <div id="misc-publishing-actions">
260 
261 <div class="misc-pub-section" id="comment-status-radio">
262 <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 />
263 <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 />
264-<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>
265+<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 />
266+<?php if ($comment->comment_approved == 'deleted') { ?>
267+<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>
268+<?php } ?>
269 </div>
270 
271 <div class="misc-pub-section curtime misc-pub-section-last">
272@@ -69,7 +74,12 @@
273 
274 <div id="major-publishing-actions">
275 <div id="delete-action">
276-<?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"; ?>
277+<?php
278+if ($comment->comment_approved == 'deleted')
279+       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";
280+else
281+       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";
282+?>
283 </div>
284 <div id="publishing-action">
285 <input type="submit" name="save" value="<?php esc_attr_e('Update Comment'); ?>" tabindex="4" class="button-primary" />
286Index: wp-admin/css/colors-fresh.css
287===================================================================
288--- wp-admin/css/colors-fresh.css       (revision 11707)
289+++ wp-admin/css/colors-fresh.css       (working copy)
290@@ -58,7 +58,8 @@
291        border-color: #ccc;
292 }
293 
294-#poststuff .inside label.spam {
295+#poststuff .inside label.spam,
296+#poststuff .inside label.deleted {
297        color: red;
298 }
299 
300Index: wp-admin/css/colors-classic.css
301===================================================================
302--- wp-admin/css/colors-classic.css     (revision 11707)
303+++ wp-admin/css/colors-classic.css     (working copy)
304@@ -58,7 +58,8 @@
305        border-color: #ccc;
306 }
307 
308-#poststuff .inside label.spam {
309+#poststuff .inside label.spam,
310+#poststuff .inside label.deleted {
311        color: red;
312 }
313