WP-Sweep - Version 1.0.10

Version Description

  • FIXED: Invalid plugin head 'This plugin has an invalid header.'
Download this release

Release Info

Developer GamerZ
Plugin Icon WP-Sweep
Version 1.0.10
Comparing to
See all releases

Code changes from version 1.0.7 to 1.0.10

Files changed (7) hide show
  1. admin.php +524 -518
  2. class-command.php +106 -0
  3. index.php +1 -1
  4. js/wp-sweep.js +79 -79
  5. readme.txt +19 -6
  6. uninstall.php +11 -6
  7. wp-sweep.php +919 -863
admin.php CHANGED
@@ -1,19 +1,22 @@
1
  <?php
2
- ### Exit if accessed directly
3
- if ( ! defined( 'ABSPATH' ) ) exit;
4
 
5
- ### Variables
 
 
 
 
 
6
  $current_page = admin_url( 'tools.php?page=' . plugin_basename( 'wp-sweep/admin.php' ) );
7
  $message = '';
8
 
9
- ### Sweeping
10
- if( ! empty( $_GET['sweep'] ) ) {
11
- if ( check_admin_referer( 'wp_sweep_' . $_GET['sweep'] ) ) {
12
- $message = WPSweep::get_instance()->sweep( $_GET['sweep'] );
13
- }
14
  }
15
 
16
- ### Database Table Status
17
  $total_posts = WPSweep::get_instance()->total_count( 'posts' );
18
  $total_postmeta = WPSweep::get_instance()->total_count( 'postmeta' );
19
  $total_comments = WPSweep::get_instance()->total_count( 'comments' );
@@ -27,7 +30,7 @@ $total_termmeta = WPSweep::get_instance()->total_count( 'termmeta' )
27
  $total_options = WPSweep::get_instance()->total_count( 'options' );
28
  $total_tables = WPSweep::get_instance()->total_count( 'tables' );
29
 
30
- ### Count
31
  $revisions = WPSweep::get_instance()->count( 'revisions' );
32
  $auto_drafts = WPSweep::get_instance()->count( 'auto_drafts' );
33
  $deleted_posts = WPSweep::get_instance()->count( 'deleted_posts' );
@@ -37,7 +40,7 @@ $oembed_postmeta = WPSweep::get_instance()->count( 'oembed_postmeta'
37
 
38
  $unapproved_comments = WPSweep::get_instance()->count( 'unapproved_comments' );
39
  $spam_comments = WPSweep::get_instance()->count( 'spam_comments' );
40
- $deleted_comments = WPSweep::get_instance()->count( 'deleted_comments' ) ;
41
  $orphan_commentmeta = WPSweep::get_instance()->count( 'orphan_commentmeta' );
42
  $duplicated_commentmeta = WPSweep::get_instance()->count( 'duplicated_commentmeta' );
43
 
@@ -50,514 +53,517 @@ $orphan_termmeta = WPSweep::get_instance()->count( 'orphan_termmeta'
50
  $duplicated_termmeta = WPSweep::get_instance()->count( 'duplicated_termmeta' );
51
 
52
  $transient_options = WPSweep::get_instance()->count( 'transient_options' );
 
53
  ?>
54
  <style type="text/css">
55
- .table-sweep thead th {
56
- width: 12%;
57
- }
58
- .table-sweep thead th.col-sweep-details {
59
- width: 56%;
60
- }
61
- .table-sweep thead th.col-sweep-action {
62
- width: 20%;
63
- }
64
  </style>
65
  <div class="wrap">
66
- <h2><?php _e( 'WP-Sweep', 'wp-sweep' ); ?></h2>
67
- <div class="update-nag">
68
- <?php printf( __( 'Before you do any sweep, please <a href="%s" target="%s">backup your database</a> first because any sweep done is irreversible.', 'wp-sweep' ), 'https://wordpress.org/plugins/wp-dbmanager/', '_blank' ); ?>
69
- </div>
70
- <p>
71
- <?php printf( __( 'For performance reasons, only %s items will be shown if you click Details', 'wp-sweep' ), number_format_i18n( WPSweep::get_instance()->limit_details ) ); ?>
72
- </p>
73
- <h3><?php _e( 'Post Sweep', 'wp-sweep' ); ?></h3>
74
- <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-posts">%s</span> Posts</strong> and <strong class="attention"><span class="sweep-count-type-postmeta">%s</span> Post Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_posts ), number_format_i18n( $total_postmeta ) ); ?></p>
75
- <div class="sweep-message"></div>
76
- <table class="widefat table-sweep">
77
- <thead>
78
- <tr>
79
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
80
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
81
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
82
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
83
- </tr>
84
- </thead>
85
- <tbody>
86
- <tr>
87
- <td>
88
- <strong><?php _e( 'Revisions', 'wp-sweep' ); ?></strong>
89
- <p class="sweep-details" style="display: none;"></p>
90
- </td>
91
- <td>
92
- <span class="sweep-count"><?php echo number_format_i18n( $revisions ); ?></span>
93
- </td>
94
- <td>
95
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $revisions, $total_posts ); ?></span>
96
- </td>
97
- <td>
98
- <?php if( ! empty( $revisions ) ): ?>
99
- <button data-action="sweep" data-sweep_name="revisions" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_revisions' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
100
- <button data-action="sweep_details" data-sweep_name="revisions" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_revisions' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
101
- <?php else: ?>
102
- <?php _e( 'N/A', 'wp-sweep' ); ?>
103
- <?php endif; ?>
104
- </td>
105
- </tr>
106
- <tr class="alternate">
107
- <td>
108
- <strong><?php _e( 'Auto Drafts', 'wp-sweep' ); ?></strong>
109
- <p class="sweep-details" style="display: none;"></p>
110
- </td>
111
- <td>
112
- <span class="sweep-count"><?php echo number_format_i18n( $auto_drafts ); ?></span>
113
- </td>
114
- <td>
115
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $auto_drafts, $total_posts ); ?></span>
116
- </td>
117
- <td>
118
- <?php if( ! empty( $auto_drafts ) ): ?>
119
- <button data-action="sweep" data-sweep_name="auto_drafts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_auto_drafts' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
120
- <button data-action="sweep_details" data-sweep_name="auto_drafts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_auto_drafts' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
121
- <?php else: ?>
122
- <?php _e( 'N/A', 'wp-sweep' ); ?>
123
- <?php endif; ?>
124
- </td>
125
- </tr>
126
- <tr>
127
- <td>
128
- <strong><?php _e( 'Deleted Posts', 'wp-sweep' ); ?></strong>
129
- <p class="sweep-details" style="display: none;"></p>
130
- </td>
131
- <td>
132
- <span class="sweep-count"><?php echo number_format_i18n( $deleted_posts ); ?></span>
133
- </td>
134
- <td>
135
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $deleted_posts, $total_posts ); ?></span>
136
- </td>
137
- <td>
138
- <?php if( ! empty( $deleted_posts ) ): ?>
139
- <button data-action="sweep" data-sweep_name="deleted_posts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_deleted_posts' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
140
- <button data-action="sweep_details" data-sweep_name="deleted_posts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_deleted_posts' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
141
- <?php else: ?>
142
- <?php _e( 'N/A', 'wp-sweep' ); ?>
143
- <?php endif; ?>
144
- </td>
145
- </tr>
146
- <tr class="alternate">
147
- <td>
148
- <strong><?php _e( 'Orphaned Post Meta', 'wp-sweep' ); ?></strong>
149
- <p class="sweep-details" style="display: none;"></p>
150
- </td>
151
- <td>
152
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_postmeta ); ?></span>
153
- </td>
154
- <td>
155
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_postmeta, $total_postmeta ); ?></span>
156
- </td>
157
- <td>
158
- <?php if( ! empty( $orphan_postmeta ) ): ?>
159
- <button data-action="sweep" data-sweep_name="orphan_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_postmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
160
- <button data-action="sweep_details" data-sweep_name="orphan_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_postmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
161
- <?php else: ?>
162
- <?php _e( 'N/A', 'wp-sweep' ); ?>
163
- <?php endif; ?>
164
- </td>
165
- </tr>
166
- <tr>
167
- <td>
168
- <strong><?php _e( 'Duplicated Post Meta', 'wp-sweep' ); ?></strong>
169
- <p class="sweep-details" style="display: none;"></p>
170
- </td>
171
- <td>
172
- <span class="sweep-count"><?php echo number_format_i18n( $duplicated_postmeta ); ?></span>
173
- </td>
174
- <td>
175
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_postmeta, $total_postmeta ); ?></span>
176
- </td>
177
- <td>
178
- <?php if( ! empty( $duplicated_postmeta ) ): ?>
179
- <button data-action="sweep" data-sweep_name="duplicated_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_postmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
180
- <button data-action="sweep_details" data-sweep_name="duplicated_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_postmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
181
- <?php else: ?>
182
- <?php _e( 'N/A', 'wp-sweep' ); ?>
183
- <?php endif; ?>
184
- </td>
185
- </tr>
186
- <tr class="alternate">
187
- <td>
188
- <strong><?php _e( 'oEmbed Caches In Post Meta', 'wp-sweep' ); ?></strong>
189
- <p class="sweep-details" style="display: none;"></p>
190
- </td>
191
- <td>
192
- <span class="sweep-count"><?php echo number_format_i18n( $oembed_postmeta ); ?></span>
193
- </td>
194
- <td>
195
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $oembed_postmeta, $total_postmeta ); ?></span>
196
- </td>
197
- <td>
198
- <?php if( ! empty( $oembed_postmeta ) ): ?>
199
- <button data-action="sweep" data-sweep_name="oembed_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_oembed_postmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
200
- <button data-action="sweep_details" data-sweep_name="oembed_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_oembed_postmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
201
- <?php else: ?>
202
- <?php _e( 'N/A', 'wp-sweep' ); ?>
203
- <?php endif; ?>
204
- </td>
205
- </tr>
206
- </tbody>
207
- </table>
208
- <?php do_action( 'wp_sweep_admin_post_sweep' ); ?>
209
- <p>&nbsp;</p>
210
- <h3><?php _e( 'Comment Sweep', 'wp-sweep' ); ?></h3>
211
- <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-comments">%s</span> Comments</strong> and <strong class="attention"><span class="sweep-count-type-commentmeta">%s</span> Comment Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_comments ), number_format_i18n( $total_commentmeta ) ); ?></p>
212
- <div class="sweep-message"></div>
213
- <table class="widefat table-sweep">
214
- <thead>
215
- <tr>
216
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
217
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
218
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
219
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
220
- </tr>
221
- </thead>
222
- <tbody>
223
- <tr>
224
- <td>
225
- <strong><?php _e( 'Unapproved Comments', 'wp-sweep' ); ?></strong>
226
- <p class="sweep-details" style="display: none;"></p>
227
- </td>
228
- <td>
229
- <span class="sweep-count"><?php echo number_format_i18n( $unapproved_comments ); ?></span>
230
- </td>
231
- <td>
232
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $unapproved_comments, $total_comments ); ?></span>
233
- </td>
234
- <td>
235
- <?php if( ! empty( $unapproved_comments ) ): ?>
236
- <button data-action="sweep" data-sweep_name="unapproved_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_unapproved_comments' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
237
- <button data-action="sweep_details" data-sweep_name="unapproved_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_unapproved_comments' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
238
- <?php else: ?>
239
- <?php _e( 'N/A', 'wp-sweep' ); ?>
240
- <?php endif; ?>
241
- </td>
242
- </tr>
243
- <tr class="alternate">
244
- <td>
245
- <strong><?php _e( 'Spammed Comments', 'wp-sweep' ); ?></strong>
246
- <p class="sweep-details" style="display: none;"></p>
247
- </td>
248
- <td>
249
- <span class="sweep-count"><?php echo number_format_i18n( $spam_comments ); ?></span>
250
- </td>
251
- <td>
252
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $spam_comments, $total_comments ); ?></span>
253
- </td>
254
- <td>
255
- <?php if( ! empty( $spam_comments ) ): ?>
256
- <button data-action="sweep" data-sweep_name="spam_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_spam_comments' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
257
- <button data-action="sweep_details" data-sweep_name="spam_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_spam_comments' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
258
- <?php else: ?>
259
- <?php _e( 'N/A', 'wp-sweep' ); ?>
260
- <?php endif; ?>
261
- </td>
262
- </tr>
263
- <tr>
264
- <td>
265
- <strong><?php _e( 'Deleted Comments', 'wp-sweep' ); ?></strong>
266
- <p class="sweep-details" style="display: none;"></p>
267
- </td>
268
- <td>
269
- <span class="sweep-count"><?php echo number_format_i18n( $deleted_comments ); ?></span>
270
- </td>
271
- <td>
272
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $deleted_comments, $total_comments ); ?></span>
273
- </td>
274
- <td>
275
- <?php if( ! empty( $deleted_comments ) ): ?>
276
- <button data-action="sweep" data-sweep_name="deleted_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_deleted_comments' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
277
- <button data-action="sweep_details" data-sweep_name="deleted_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_deleted_comments' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
278
- <?php else: ?>
279
- <?php _e( 'N/A', 'wp-sweep' ); ?>
280
- <?php endif; ?>
281
- </td>
282
- </tr>
283
- <tr class="alternate">
284
- <td>
285
- <strong><?php _e( 'Orphaned Comment Meta', 'wp-sweep' ); ?></strong>
286
- <p class="sweep-details" style="display: none;"></p>
287
- </td>
288
- <td>
289
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_commentmeta ); ?></span>
290
- </td>
291
- <td>
292
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_commentmeta, $total_commentmeta ); ?></span>
293
- </td>
294
- <td>
295
- <?php if( ! empty( $orphan_commentmeta ) ): ?>
296
- <button data-action="sweep" data-sweep_name="orphan_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_commentmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
297
- <button data-action="sweep_details" data-sweep_name="orphan_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_commentmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
298
- <?php else: ?>
299
- <?php _e( 'N/A', 'wp-sweep' ); ?>
300
- <?php endif; ?>
301
- </td>
302
- </tr>
303
- <tr>
304
- <td>
305
- <strong><?php _e( 'Duplicated Comment Meta', 'wp-sweep' ); ?></strong>
306
- <p class="sweep-details" style="display: none;"></p>
307
- </td>
308
- <td>
309
- <span class="sweep-count"><?php echo number_format_i18n( $duplicated_commentmeta ); ?></span>
310
- </td>
311
- <td>
312
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_commentmeta, $total_commentmeta ); ?></span>
313
- </td>
314
- <td>
315
- <?php if( ! empty( $duplicated_commentmeta ) ): ?>
316
- <button data-action="sweep" data-sweep_name="duplicated_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_commentmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
317
- <button data-action="sweep_details" data-sweep_name="duplicated_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_commentmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
318
- <?php else: ?>
319
- <?php _e( 'N/A', 'wp-sweep' ); ?>
320
- <?php endif; ?>
321
- </td>
322
- </tr>
323
- </tbody>
324
- </table>
325
- <?php do_action( 'wp_sweep_admin_comment_sweep' ); ?>
326
- <p>&nbsp;</p>
327
- <h3><?php _e( 'User Sweep', 'wp-sweep' ); ?></h3>
328
- <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-users">%s</span> Users</strong> and <strong class="attention"><span class="sweep-count-type-usermeta">%s</span> User Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_users ), number_format_i18n( $total_usermeta ) ); ?></p>
329
- <div class="sweep-message"></div>
330
- <table class="widefat table-sweep">
331
- <thead>
332
- <tr>
333
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
334
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
335
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
336
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
337
- </tr>
338
- </thead>
339
- <tbody>
340
- <tr>
341
- <td>
342
- <strong><?php _e( 'Orphaned User Meta', 'wp-sweep' ); ?></strong>
343
- <p class="sweep-details" style="display: none;"></p>
344
- </td>
345
- <td>
346
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_usermeta ); ?></span>
347
- </td>
348
- <td>
349
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_usermeta, $total_usermeta ); ?></span>
350
- </td>
351
- <td>
352
- <?php if( ! empty( $orphan_usermeta ) ): ?>
353
- <button data-action="sweep" data-sweep_name="orphan_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_usermeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
354
- <button data-action="sweep_details" data-sweep_name="orphan_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_usermeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
355
- <?php else: ?>
356
- <?php _e( 'N/A', 'wp-sweep' ); ?>
357
- <?php endif; ?>
358
- </td>
359
- </tr>
360
- <tr class="alternate">
361
- <td>
362
- <strong><?php _e( 'Duplicated User Meta', 'wp-sweep' ); ?></strong>
363
- <p class="sweep-details" style="display: none;"></p>
364
- </td>
365
- <td>
366
- <span class="sweep-count"><?php echo number_format_i18n( $duplicated_usermeta ); ?></span>
367
- </td>
368
- <td>
369
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_usermeta, $total_usermeta ); ?></span>
370
- </td>
371
- <td>
372
- <?php if( ! empty( $duplicated_usermeta ) ): ?>
373
- <button data-action="sweep" data-sweep_name="duplicated_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_usermeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
374
- <button data-action="sweep_details" data-sweep_name="duplicated_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_usermeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
375
- <?php else: ?>
376
- <?php _e( 'N/A', 'wp-sweep' ); ?>
377
- <?php endif; ?>
378
- </td>
379
- </tr>
380
- </tbody>
381
- </table>
382
- <?php do_action( 'wp_sweep_admin_user_sweep' ); ?>
383
- <p>&nbsp;</p>
384
- <h3><?php _e( 'Term Sweep', 'wp-sweep' ); ?></h3>
385
- <p><?php printf( __( 'There are a total of <strong class="attention "><span class="sweep-count-type-terms">%s</span> Terms</strong>, <strong class="attention "><span class="sweep-count-type-termmeta">%s</span> Term Meta</strong>, <strong class="attention"><span class="sweep-count-type-term_taxonomy">%s</span> Term Taxonomy</strong> and <strong class="attention"><span class="sweep-count-type-term_relationships">%s</span> Term Relationships</strong>.', 'wp-sweep' ), number_format_i18n( $total_terms ), number_format_i18n( $total_termmeta ), number_format_i18n( $total_term_taxonomy ), number_format_i18n( $total_term_relationships ) ); ?></p>
386
- <div class="sweep-message"></div>
387
- <table class="widefat table-sweep">
388
- <thead>
389
- <tr>
390
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
391
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
392
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
393
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
394
- </tr>
395
- </thead>
396
- <tbody>
397
- <tr>
398
- <td>
399
- <strong><?php _e( 'Orphaned Term Meta', 'wp-sweep' ); ?></strong>
400
- <p class="sweep-details" style="display: none;"></p>
401
- </td>
402
- <td>
403
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_termmeta ); ?></span>
404
- </td>
405
- <td>
406
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_termmeta, $total_termmeta ); ?></span>
407
- </td>
408
- <td>
409
- <?php if( ! empty( $orphan_termmeta ) ): ?>
410
- <button data-action="sweep" data-sweep_name="orphan_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_termmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
411
- <button data-action="sweep_details" data-sweep_name="orphan_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_termmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
412
- <?php else: ?>
413
- <?php _e( 'N/A', 'wp-sweep' ); ?>
414
- <?php endif; ?>
415
- </td>
416
- </tr>
417
- <tr class="alternate">
418
- <td>
419
- <strong><?php _e( 'Duplicated Term Meta', 'wp-sweep' ); ?></strong>
420
- <p class="sweep-details" style="display: none;"></p>
421
- </td>
422
- <td>
423
- <span class="sweep-count"><?php echo number_format_i18n( $duplicated_termmeta ); ?></span>
424
- </td>
425
- <td>
426
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_termmeta, $total_termmeta ); ?></span>
427
- </td>
428
- <td>
429
- <?php if( ! empty( $duplicated_termmeta ) ): ?>
430
- <button data-action="sweep" data-sweep_name="duplicated_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_termmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
431
- <button data-action="sweep_details" data-sweep_name="duplicated_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_termmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
432
- <?php else: ?>
433
- <?php _e( 'N/A', 'wp-sweep' ); ?>
434
- <?php endif; ?>
435
- </td>
436
- </tr>
437
- <tr>
438
- <td>
439
- <strong><?php _e( 'Orphaned Term Relationship', 'wp-sweep' ); ?></strong>
440
- <p class="sweep-details" style="display: none;"></p>
441
- </td>
442
- <td>
443
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_term_relationships ); ?></span>
444
- </td>
445
- <td>
446
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_term_relationships, $total_term_relationships ); ?></span>
447
- </td>
448
- <td>
449
- <?php if( ! empty( $orphan_term_relationships ) ): ?>
450
- <button data-action="sweep" data-sweep_name="orphan_term_relationships" data-sweep_type="term_relationships" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_term_relationships' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
451
- <button data-action="sweep_details" data-sweep_name="orphan_term_relationships" data-sweep_type="term_relationships" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_term_relationships' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
452
- <?php else: ?>
453
- <?php _e( 'N/A', 'wp-sweep' ); ?>
454
- <?php endif; ?>
455
- </td>
456
- </tr>
457
- <tr class="alternate">
458
- <td>
459
- <strong><?php _e( 'Unused Terms', 'wp-sweep' ); ?></strong>
460
- <p><?php _e( 'Note that some unused terms might belong to draft posts that have not been published yet. Only sweep this when you do not have any draft posts.', 'wp-sweep' ); ?></p>
461
- <p class="sweep-details" style="display: none;"></p>
462
- </td>
463
- <td>
464
- <span class="sweep-count"><?php echo number_format_i18n( $unused_terms ); ?></span>
465
- </td>
466
- <td>
467
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $unused_terms, $total_terms ); ?></span>
468
- </td>
469
- <td>
470
- <?php if( ! empty( $unused_terms ) ): ?>
471
- <button data-action="sweep" data-sweep_name="unused_terms" data-sweep_type="terms" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_unused_terms' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
472
- <button data-action="sweep_details" data-sweep_name="unused_terms" data-sweep_type="terms" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_unused_terms' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
473
- <?php else: ?>
474
- <?php _e( 'N/A', 'wp-sweep' ); ?>
475
- <?php endif; ?>
476
- </td>
477
- </tr>
478
- </tbody>
479
- </table>
480
- <?php do_action( 'wp_sweep_admin_term_sweep' ); ?>
481
- <p>&nbsp;</p>
482
- <h3><?php _e( 'Option Sweep', 'wp-sweep' ); ?></h3>
483
- <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-options">%s</span> Options</strong>.', 'wp-sweep' ), number_format_i18n( $total_options ) ); ?></p>
484
- <div class="sweep-message"></div>
485
- <table class="widefat table-sweep">
486
- <thead>
487
- <tr>
488
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
489
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
490
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
491
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
492
- </tr>
493
- </thead>
494
- <tbody>
495
- <tr>
496
- <td>
497
- <strong><?php _e( 'Transient Options', 'wp-sweep' ); ?></strong>
498
- <p class="sweep-details" style="display: none;"></p>
499
- </td>
500
- <td>
501
- <span class="sweep-count"><?php echo number_format_i18n( $transient_options ); ?></span>
502
- </td>
503
- <td>
504
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $transient_options, $total_options ); ?></span>
505
- </td>
506
- <td>
507
- <?php if( ! empty( $transient_options ) ): ?>
508
- <button data-action="sweep" data-sweep_name="transient_options" data-sweep_type="options" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_transient_options' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
509
- <button data-action="sweep_details" data-sweep_name="transient_options" data-sweep_type="options" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_transient_options' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
510
- <?php else: ?>
511
- <?php _e( 'N/A', 'wp-sweep' ); ?>
512
- <?php endif; ?>
513
- </td>
514
- </tr>
515
- </tbody>
516
- </table>
517
- <?php do_action( 'wp_sweep_admin_option_sweep' ); ?>
518
- <p>&nbsp;</p>
519
- <h3><?php _e( 'Database Sweep', 'wp-sweep' ); ?></h3>
520
- <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-tables">%s</span> Tables</strong>.', 'wp-sweep' ), number_format_i18n( $total_tables ) ); ?></p>
521
- <div class="sweep-message"></div>
522
- <table class="widefat table-sweep">
523
- <thead>
524
- <tr>
525
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
526
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
527
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
528
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
529
- </tr>
530
- </thead>
531
- <tbody>
532
- <tr>
533
- <td>
534
- <strong><?php _e( 'Optimize Tables', 'wp-sweep' ); ?></strong>
535
- <p class="sweep-details" style="display: none;"></p>
536
- </td>
537
- <td>
538
- <span class="sweep-count"><?php echo number_format_i18n( $total_tables ); ?></span>
539
- </td>
540
- <td>
541
- <?php _e( 'N/A', 'wp-sweep' ); ?>
542
- </td>
543
- <td>
544
- <?php if( ! empty( $total_tables ) ): ?>
545
- <button data-action="sweep" data-sweep_name="optimize_database" data-sweep_type="tables" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_optimize_database' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
546
- <button data-action="sweep_details" data-sweep_name="optimize_database" data-sweep_type="tables" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_optimize_database' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
547
- <?php else: ?>
548
- <?php _e( 'N/A', 'wp-sweep' ); ?>
549
- <?php endif; ?>
550
- </td>
551
- </tr>
552
- </tbody>
553
- </table>
554
- <?php do_action( 'wp_sweep_admin_database_sweep' ); ?>
555
- <p>&nbsp;</p>
556
- <h3><?php _e( 'Sweep All', 'wp-sweep' ); ?></h3>
557
- <p><?php _e( 'Note that some unused terms might belong to draft posts that have not been published yet. Only sweep all when you do not have any draft posts.', 'wp-sweep' ); ?></p>
558
- <div class="sweep-all">
559
- <p style="text-align: center;">
560
- <button class="button button-primary btn-sweep-all"><?php _e( 'Sweep All', 'wp-sweep' ); ?></button>
561
- </p>
562
- </div>
563
- </div>
 
 
1
  <?php
 
 
2
 
3
+ // Exit if accessed directly
4
+ if ( ! defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ // Variables
9
  $current_page = admin_url( 'tools.php?page=' . plugin_basename( 'wp-sweep/admin.php' ) );
10
  $message = '';
11
 
12
+ // Sweeping
13
+ if ( ! empty( $_GET['sweep'] ) ) {
14
+ if ( check_admin_referer( 'wp_sweep_' . $_GET['sweep'] ) ) {
15
+ $message = WPSweep::get_instance()->sweep( $_GET['sweep'] );
16
+ }
17
  }
18
 
19
+ // Database Table Status
20
  $total_posts = WPSweep::get_instance()->total_count( 'posts' );
21
  $total_postmeta = WPSweep::get_instance()->total_count( 'postmeta' );
22
  $total_comments = WPSweep::get_instance()->total_count( 'comments' );
30
  $total_options = WPSweep::get_instance()->total_count( 'options' );
31
  $total_tables = WPSweep::get_instance()->total_count( 'tables' );
32
 
33
+ // Count
34
  $revisions = WPSweep::get_instance()->count( 'revisions' );
35
  $auto_drafts = WPSweep::get_instance()->count( 'auto_drafts' );
36
  $deleted_posts = WPSweep::get_instance()->count( 'deleted_posts' );
40
 
41
  $unapproved_comments = WPSweep::get_instance()->count( 'unapproved_comments' );
42
  $spam_comments = WPSweep::get_instance()->count( 'spam_comments' );
43
+ $deleted_comments = WPSweep::get_instance()->count( 'deleted_comments' );
44
  $orphan_commentmeta = WPSweep::get_instance()->count( 'orphan_commentmeta' );
45
  $duplicated_commentmeta = WPSweep::get_instance()->count( 'duplicated_commentmeta' );
46
 
53
  $duplicated_termmeta = WPSweep::get_instance()->count( 'duplicated_termmeta' );
54
 
55
  $transient_options = WPSweep::get_instance()->count( 'transient_options' );
56
+
57
  ?>
58
  <style type="text/css">
59
+ .table-sweep thead th {
60
+ width: 12%;
61
+ }
62
+ .table-sweep thead th.col-sweep-details {
63
+ width: 56%;
64
+ }
65
+ .table-sweep thead th.col-sweep-action {
66
+ width: 20%;
67
+ }
68
  </style>
69
  <div class="wrap">
70
+ <h2><?php _e( 'WP-Sweep', 'wp-sweep' ); ?></h2>
71
+ <div class="notice notice-warning">
72
+ <p>
73
+ <?php printf( __( 'Before you do any sweep, please <a href="%1$s" target="%2$s">backup your database</a> first because any sweep done is irreversible.', 'wp-sweep' ), 'https://wordpress.org/plugins/wp-dbmanager/', '_blank' ); ?>
74
+ </p>
75
+ </div>
76
+ <p>
77
+ <?php printf( __( 'For performance reasons, only %s items will be shown if you click Details', 'wp-sweep' ), number_format_i18n( WPSweep::get_instance()->limit_details ) ); ?>
78
+ </p>
79
+ <h3><?php _e( 'Post Sweep', 'wp-sweep' ); ?></h3>
80
+ <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-posts">%1$s</span> Posts</strong> and <strong class="attention"><span class="sweep-count-type-postmeta">%2$s</span> Post Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_posts ), number_format_i18n( $total_postmeta ) ); ?></p>
81
+ <div class="sweep-message"></div>
82
+ <table class="widefat table-sweep">
83
+ <thead>
84
+ <tr>
85
+ <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
86
+ <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
87
+ <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
88
+ <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
89
+ </tr>
90
+ </thead>
91
+ <tbody>
92
+ <tr>
93
+ <td>
94
+ <strong><?php _e( 'Revisions', 'wp-sweep' ); ?></strong>
95
+ <p class="sweep-details" style="display: none;"></p>
96
+ </td>
97
+ <td>
98
+ <span class="sweep-count"><?php echo number_format_i18n( $revisions ); ?></span>
99
+ </td>
100
+ <td>
101
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $revisions, $total_posts ); ?></span>
102
+ </td>
103
+ <td>
104
+ <?php if ( ! empty( $revisions ) ) : ?>
105
+ <button data-action="sweep" data-sweep_name="revisions" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_revisions' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
106
+ <button data-action="sweep_details" data-sweep_name="revisions" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_revisions' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
107
+ <?php else : ?>
108
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
109
+ <?php endif; ?>
110
+ </td>
111
+ </tr>
112
+ <tr class="alternate">
113
+ <td>
114
+ <strong><?php _e( 'Auto Drafts', 'wp-sweep' ); ?></strong>
115
+ <p class="sweep-details" style="display: none;"></p>
116
+ </td>
117
+ <td>
118
+ <span class="sweep-count"><?php echo number_format_i18n( $auto_drafts ); ?></span>
119
+ </td>
120
+ <td>
121
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $auto_drafts, $total_posts ); ?></span>
122
+ </td>
123
+ <td>
124
+ <?php if ( ! empty( $auto_drafts ) ) : ?>
125
+ <button data-action="sweep" data-sweep_name="auto_drafts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_auto_drafts' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
126
+ <button data-action="sweep_details" data-sweep_name="auto_drafts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_auto_drafts' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
127
+ <?php else : ?>
128
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
129
+ <?php endif; ?>
130
+ </td>
131
+ </tr>
132
+ <tr>
133
+ <td>
134
+ <strong><?php _e( 'Deleted Posts', 'wp-sweep' ); ?></strong>
135
+ <p class="sweep-details" style="display: none;"></p>
136
+ </td>
137
+ <td>
138
+ <span class="sweep-count"><?php echo number_format_i18n( $deleted_posts ); ?></span>
139
+ </td>
140
+ <td>
141
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $deleted_posts, $total_posts ); ?></span>
142
+ </td>
143
+ <td>
144
+ <?php if ( ! empty( $deleted_posts ) ) : ?>
145
+ <button data-action="sweep" data-sweep_name="deleted_posts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_deleted_posts' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
146
+ <button data-action="sweep_details" data-sweep_name="deleted_posts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_deleted_posts' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
147
+ <?php else : ?>
148
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
149
+ <?php endif; ?>
150
+ </td>
151
+ </tr>
152
+ <tr class="alternate">
153
+ <td>
154
+ <strong><?php _e( 'Orphaned Post Meta', 'wp-sweep' ); ?></strong>
155
+ <p class="sweep-details" style="display: none;"></p>
156
+ </td>
157
+ <td>
158
+ <span class="sweep-count"><?php echo number_format_i18n( $orphan_postmeta ); ?></span>
159
+ </td>
160
+ <td>
161
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_postmeta, $total_postmeta ); ?></span>
162
+ </td>
163
+ <td>
164
+ <?php if ( ! empty( $orphan_postmeta ) ) : ?>
165
+ <button data-action="sweep" data-sweep_name="orphan_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_postmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
166
+ <button data-action="sweep_details" data-sweep_name="orphan_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_postmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
167
+ <?php else : ?>
168
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
169
+ <?php endif; ?>
170
+ </td>
171
+ </tr>
172
+ <tr>
173
+ <td>
174
+ <strong><?php _e( 'Duplicated Post Meta', 'wp-sweep' ); ?></strong>
175
+ <p class="sweep-details" style="display: none;"></p>
176
+ </td>
177
+ <td>
178
+ <span class="sweep-count"><?php echo number_format_i18n( $duplicated_postmeta ); ?></span>
179
+ </td>
180
+ <td>
181
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_postmeta, $total_postmeta ); ?></span>
182
+ </td>
183
+ <td>
184
+ <?php if ( ! empty( $duplicated_postmeta ) ) : ?>
185
+ <button data-action="sweep" data-sweep_name="duplicated_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_postmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
186
+ <button data-action="sweep_details" data-sweep_name="duplicated_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_postmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
187
+ <?php else : ?>
188
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
189
+ <?php endif; ?>
190
+ </td>
191
+ </tr>
192
+ <tr class="alternate">
193
+ <td>
194
+ <strong><?php _e( 'oEmbed Caches In Post Meta', 'wp-sweep' ); ?></strong>
195
+ <p class="sweep-details" style="display: none;"></p>
196
+ </td>
197
+ <td>
198
+ <span class="sweep-count"><?php echo number_format_i18n( $oembed_postmeta ); ?></span>
199
+ </td>
200
+ <td>
201
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $oembed_postmeta, $total_postmeta ); ?></span>
202
+ </td>
203
+ <td>
204
+ <?php if ( ! empty( $oembed_postmeta ) ) : ?>
205
+ <button data-action="sweep" data-sweep_name="oembed_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_oembed_postmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
206
+ <button data-action="sweep_details" data-sweep_name="oembed_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_oembed_postmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
207
+ <?php else : ?>
208
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
209
+ <?php endif; ?>
210
+ </td>
211
+ </tr>
212
+ </tbody>
213
+ </table>
214
+ <?php do_action( 'wp_sweep_admin_post_sweep' ); ?>
215
+ <p>&nbsp;</p>
216
+ <h3><?php _e( 'Comment Sweep', 'wp-sweep' ); ?></h3>
217
+ <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-comments">%1$s</span> Comments</strong> and <strong class="attention"><span class="sweep-count-type-commentmeta">%2$s</span> Comment Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_comments ), number_format_i18n( $total_commentmeta ) ); ?></p>
218
+ <div class="sweep-message"></div>
219
+ <table class="widefat table-sweep">
220
+ <thead>
221
+ <tr>
222
+ <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
223
+ <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
224
+ <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
225
+ <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
226
+ </tr>
227
+ </thead>
228
+ <tbody>
229
+ <tr>
230
+ <td>
231
+ <strong><?php _e( 'Unapproved Comments', 'wp-sweep' ); ?></strong>
232
+ <p class="sweep-details" style="display: none;"></p>
233
+ </td>
234
+ <td>
235
+ <span class="sweep-count"><?php echo number_format_i18n( $unapproved_comments ); ?></span>
236
+ </td>
237
+ <td>
238
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $unapproved_comments, $total_comments ); ?></span>
239
+ </td>
240
+ <td>
241
+ <?php if ( ! empty( $unapproved_comments ) ) : ?>
242
+ <button data-action="sweep" data-sweep_name="unapproved_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_unapproved_comments' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
243
+ <button data-action="sweep_details" data-sweep_name="unapproved_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_unapproved_comments' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
244
+ <?php else : ?>
245
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
246
+ <?php endif; ?>
247
+ </td>
248
+ </tr>
249
+ <tr class="alternate">
250
+ <td>
251
+ <strong><?php _e( 'Spammed Comments', 'wp-sweep' ); ?></strong>
252
+ <p class="sweep-details" style="display: none;"></p>
253
+ </td>
254
+ <td>
255
+ <span class="sweep-count"><?php echo number_format_i18n( $spam_comments ); ?></span>
256
+ </td>
257
+ <td>
258
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $spam_comments, $total_comments ); ?></span>
259
+ </td>
260
+ <td>
261
+ <?php if ( ! empty( $spam_comments ) ) : ?>
262
+ <button data-action="sweep" data-sweep_name="spam_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_spam_comments' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
263
+ <button data-action="sweep_details" data-sweep_name="spam_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_spam_comments' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
264
+ <?php else : ?>
265
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
266
+ <?php endif; ?>
267
+ </td>
268
+ </tr>
269
+ <tr>
270
+ <td>
271
+ <strong><?php _e( 'Deleted Comments', 'wp-sweep' ); ?></strong>
272
+ <p class="sweep-details" style="display: none;"></p>
273
+ </td>
274
+ <td>
275
+ <span class="sweep-count"><?php echo number_format_i18n( $deleted_comments ); ?></span>
276
+ </td>
277
+ <td>
278
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $deleted_comments, $total_comments ); ?></span>
279
+ </td>
280
+ <td>
281
+ <?php if ( ! empty( $deleted_comments ) ) : ?>
282
+ <button data-action="sweep" data-sweep_name="deleted_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_deleted_comments' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
283
+ <button data-action="sweep_details" data-sweep_name="deleted_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_deleted_comments' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
284
+ <?php else : ?>
285
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
286
+ <?php endif; ?>
287
+ </td>
288
+ </tr>
289
+ <tr class="alternate">
290
+ <td>
291
+ <strong><?php _e( 'Orphaned Comment Meta', 'wp-sweep' ); ?></strong>
292
+ <p class="sweep-details" style="display: none;"></p>
293
+ </td>
294
+ <td>
295
+ <span class="sweep-count"><?php echo number_format_i18n( $orphan_commentmeta ); ?></span>
296
+ </td>
297
+ <td>
298
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_commentmeta, $total_commentmeta ); ?></span>
299
+ </td>
300
+ <td>
301
+ <?php if ( ! empty( $orphan_commentmeta ) ) : ?>
302
+ <button data-action="sweep" data-sweep_name="orphan_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_commentmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
303
+ <button data-action="sweep_details" data-sweep_name="orphan_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_commentmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
304
+ <?php else : ?>
305
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
306
+ <?php endif; ?>
307
+ </td>
308
+ </tr>
309
+ <tr>
310
+ <td>
311
+ <strong><?php _e( 'Duplicated Comment Meta', 'wp-sweep' ); ?></strong>
312
+ <p class="sweep-details" style="display: none;"></p>
313
+ </td>
314
+ <td>
315
+ <span class="sweep-count"><?php echo number_format_i18n( $duplicated_commentmeta ); ?></span>
316
+ </td>
317
+ <td>
318
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_commentmeta, $total_commentmeta ); ?></span>
319
+ </td>
320
+ <td>
321
+ <?php if ( ! empty( $duplicated_commentmeta ) ) : ?>
322
+ <button data-action="sweep" data-sweep_name="duplicated_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_commentmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
323
+ <button data-action="sweep_details" data-sweep_name="duplicated_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_commentmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
324
+ <?php else : ?>
325
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
326
+ <?php endif; ?>
327
+ </td>
328
+ </tr>
329
+ </tbody>
330
+ </table>
331
+ <?php do_action( 'wp_sweep_admin_comment_sweep' ); ?>
332
+ <p>&nbsp;</p>
333
+ <h3><?php _e( 'User Sweep', 'wp-sweep' ); ?></h3>
334
+ <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-users">%1$s</span> Users</strong> and <strong class="attention"><span class="sweep-count-type-usermeta">%2$s</span> User Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_users ), number_format_i18n( $total_usermeta ) ); ?></p>
335
+ <div class="sweep-message"></div>
336
+ <table class="widefat table-sweep">
337
+ <thead>
338
+ <tr>
339
+ <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
340
+ <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
341
+ <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
342
+ <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
343
+ </tr>
344
+ </thead>
345
+ <tbody>
346
+ <tr>
347
+ <td>
348
+ <strong><?php _e( 'Orphaned User Meta', 'wp-sweep' ); ?></strong>
349
+ <p class="sweep-details" style="display: none;"></p>
350
+ </td>
351
+ <td>
352
+ <span class="sweep-count"><?php echo number_format_i18n( $orphan_usermeta ); ?></span>
353
+ </td>
354
+ <td>
355
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_usermeta, $total_usermeta ); ?></span>
356
+ </td>
357
+ <td>
358
+ <?php if ( ! empty( $orphan_usermeta ) ) : ?>
359
+ <button data-action="sweep" data-sweep_name="orphan_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_usermeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
360
+ <button data-action="sweep_details" data-sweep_name="orphan_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_usermeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
361
+ <?php else : ?>
362
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
363
+ <?php endif; ?>
364
+ </td>
365
+ </tr>
366
+ <tr class="alternate">
367
+ <td>
368
+ <strong><?php _e( 'Duplicated User Meta', 'wp-sweep' ); ?></strong>
369
+ <p class="sweep-details" style="display: none;"></p>
370
+ </td>
371
+ <td>
372
+ <span class="sweep-count"><?php echo number_format_i18n( $duplicated_usermeta ); ?></span>
373
+ </td>
374
+ <td>
375
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_usermeta, $total_usermeta ); ?></span>
376
+ </td>
377
+ <td>
378
+ <?php if ( ! empty( $duplicated_usermeta ) ) : ?>
379
+ <button data-action="sweep" data-sweep_name="duplicated_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_usermeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
380
+ <button data-action="sweep_details" data-sweep_name="duplicated_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_usermeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
381
+ <?php else : ?>
382
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
383
+ <?php endif; ?>
384
+ </td>
385
+ </tr>
386
+ </tbody>
387
+ </table>
388
+ <?php do_action( 'wp_sweep_admin_user_sweep' ); ?>
389
+ <p>&nbsp;</p>
390
+ <h3><?php _e( 'Term Sweep', 'wp-sweep' ); ?></h3>
391
+ <p><?php printf( __( 'There are a total of <strong class="attention "><span class="sweep-count-type-terms">%1$s</span> Terms</strong>, <strong class="attention "><span class="sweep-count-type-termmeta">%2$s</span> Term Meta</strong>, <strong class="attention"><span class="sweep-count-type-term_taxonomy">%3$s</span> Term Taxonomy</strong> and <strong class="attention"><span class="sweep-count-type-term_relationships">%4$s</span> Term Relationships</strong>.', 'wp-sweep' ), number_format_i18n( $total_terms ), number_format_i18n( $total_termmeta ), number_format_i18n( $total_term_taxonomy ), number_format_i18n( $total_term_relationships ) ); ?></p>
392
+ <div class="sweep-message"></div>
393
+ <table class="widefat table-sweep">
394
+ <thead>
395
+ <tr>
396
+ <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
397
+ <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
398
+ <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
399
+ <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
400
+ </tr>
401
+ </thead>
402
+ <tbody>
403
+ <tr>
404
+ <td>
405
+ <strong><?php _e( 'Orphaned Term Meta', 'wp-sweep' ); ?></strong>
406
+ <p class="sweep-details" style="display: none;"></p>
407
+ </td>
408
+ <td>
409
+ <span class="sweep-count"><?php echo number_format_i18n( $orphan_termmeta ); ?></span>
410
+ </td>
411
+ <td>
412
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_termmeta, $total_termmeta ); ?></span>
413
+ </td>
414
+ <td>
415
+ <?php if ( ! empty( $orphan_termmeta ) ) : ?>
416
+ <button data-action="sweep" data-sweep_name="orphan_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_termmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
417
+ <button data-action="sweep_details" data-sweep_name="orphan_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_termmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
418
+ <?php else : ?>
419
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
420
+ <?php endif; ?>
421
+ </td>
422
+ </tr>
423
+ <tr class="alternate">
424
+ <td>
425
+ <strong><?php _e( 'Duplicated Term Meta', 'wp-sweep' ); ?></strong>
426
+ <p class="sweep-details" style="display: none;"></p>
427
+ </td>
428
+ <td>
429
+ <span class="sweep-count"><?php echo number_format_i18n( $duplicated_termmeta ); ?></span>
430
+ </td>
431
+ <td>
432
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_termmeta, $total_termmeta ); ?></span>
433
+ </td>
434
+ <td>
435
+ <?php if ( ! empty( $duplicated_termmeta ) ) : ?>
436
+ <button data-action="sweep" data-sweep_name="duplicated_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_termmeta' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
437
+ <button data-action="sweep_details" data-sweep_name="duplicated_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_termmeta' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
438
+ <?php else : ?>
439
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
440
+ <?php endif; ?>
441
+ </td>
442
+ </tr>
443
+ <tr>
444
+ <td>
445
+ <strong><?php _e( 'Orphaned Term Relationship', 'wp-sweep' ); ?></strong>
446
+ <p class="sweep-details" style="display: none;"></p>
447
+ </td>
448
+ <td>
449
+ <span class="sweep-count"><?php echo number_format_i18n( $orphan_term_relationships ); ?></span>
450
+ </td>
451
+ <td>
452
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_term_relationships, $total_term_relationships ); ?></span>
453
+ </td>
454
+ <td>
455
+ <?php if ( ! empty( $orphan_term_relationships ) ) : ?>
456
+ <button data-action="sweep" data-sweep_name="orphan_term_relationships" data-sweep_type="term_relationships" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_term_relationships' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
457
+ <button data-action="sweep_details" data-sweep_name="orphan_term_relationships" data-sweep_type="term_relationships" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_term_relationships' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
458
+ <?php else : ?>
459
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
460
+ <?php endif; ?>
461
+ </td>
462
+ </tr>
463
+ <tr class="alternate">
464
+ <td>
465
+ <strong><?php _e( 'Unused Terms', 'wp-sweep' ); ?></strong>
466
+ <p><?php _e( 'Note that some unused terms might belong to draft posts that have not been published yet. Only sweep this when you do not have any draft posts.', 'wp-sweep' ); ?></p>
467
+ <p class="sweep-details" style="display: none;"></p>
468
+ </td>
469
+ <td>
470
+ <span class="sweep-count"><?php echo number_format_i18n( $unused_terms ); ?></span>
471
+ </td>
472
+ <td>
473
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $unused_terms, $total_terms ); ?></span>
474
+ </td>
475
+ <td>
476
+ <?php if ( ! empty( $unused_terms ) ) : ?>
477
+ <button data-action="sweep" data-sweep_name="unused_terms" data-sweep_type="terms" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_unused_terms' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
478
+ <button data-action="sweep_details" data-sweep_name="unused_terms" data-sweep_type="terms" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_unused_terms' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
479
+ <?php else : ?>
480
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
481
+ <?php endif; ?>
482
+ </td>
483
+ </tr>
484
+ </tbody>
485
+ </table>
486
+ <?php do_action( 'wp_sweep_admin_term_sweep' ); ?>
487
+ <p>&nbsp;</p>
488
+ <h3><?php _e( 'Option Sweep', 'wp-sweep' ); ?></h3>
489
+ <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-options">%s</span> Options</strong>.', 'wp-sweep' ), number_format_i18n( $total_options ) ); ?></p>
490
+ <div class="sweep-message"></div>
491
+ <table class="widefat table-sweep">
492
+ <thead>
493
+ <tr>
494
+ <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
495
+ <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
496
+ <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
497
+ <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
498
+ </tr>
499
+ </thead>
500
+ <tbody>
501
+ <tr>
502
+ <td>
503
+ <strong><?php _e( 'Transient Options', 'wp-sweep' ); ?></strong>
504
+ <p class="sweep-details" style="display: none;"></p>
505
+ </td>
506
+ <td>
507
+ <span class="sweep-count"><?php echo number_format_i18n( $transient_options ); ?></span>
508
+ </td>
509
+ <td>
510
+ <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $transient_options, $total_options ); ?></span>
511
+ </td>
512
+ <td>
513
+ <?php if ( ! empty( $transient_options ) ) : ?>
514
+ <button data-action="sweep" data-sweep_name="transient_options" data-sweep_type="options" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_transient_options' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
515
+ <button data-action="sweep_details" data-sweep_name="transient_options" data-sweep_type="options" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_transient_options' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
516
+ <?php else : ?>
517
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
518
+ <?php endif; ?>
519
+ </td>
520
+ </tr>
521
+ </tbody>
522
+ </table>
523
+ <?php do_action( 'wp_sweep_admin_option_sweep' ); ?>
524
+ <p>&nbsp;</p>
525
+ <h3><?php _e( 'Database Sweep', 'wp-sweep' ); ?></h3>
526
+ <p><?php printf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-tables">%s</span> Tables</strong>.', 'wp-sweep' ), number_format_i18n( $total_tables ) ); ?></p>
527
+ <div class="sweep-message"></div>
528
+ <table class="widefat table-sweep">
529
+ <thead>
530
+ <tr>
531
+ <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
532
+ <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
533
+ <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
534
+ <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
535
+ </tr>
536
+ </thead>
537
+ <tbody>
538
+ <tr>
539
+ <td>
540
+ <strong><?php _e( 'Optimize Tables', 'wp-sweep' ); ?></strong>
541
+ <p class="sweep-details" style="display: none;"></p>
542
+ </td>
543
+ <td>
544
+ <span class="sweep-count"><?php echo number_format_i18n( $total_tables ); ?></span>
545
+ </td>
546
+ <td>
547
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
548
+ </td>
549
+ <td>
550
+ <?php if ( ! empty( $total_tables ) ) : ?>
551
+ <button data-action="sweep" data-sweep_name="optimize_database" data-sweep_type="tables" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_optimize_database' ); ?>" class="button button-primary btn-sweep"><?php _e( 'Sweep', 'wp-sweep' ); ?></button>
552
+ <button data-action="sweep_details" data-sweep_name="optimize_database" data-sweep_type="tables" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_optimize_database' ); ?>" class="button btn-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></button>
553
+ <?php else : ?>
554
+ <?php _e( 'N/A', 'wp-sweep' ); ?>
555
+ <?php endif; ?>
556
+ </td>
557
+ </tr>
558
+ </tbody>
559
+ </table>
560
+ <?php do_action( 'wp_sweep_admin_database_sweep' ); ?>
561
+ <p>&nbsp;</p>
562
+ <h3><?php _e( 'Sweep All', 'wp-sweep' ); ?></h3>
563
+ <p><?php _e( 'Note that some unused terms might belong to draft posts that have not been published yet. Only sweep all when you do not have any draft posts.', 'wp-sweep' ); ?></p>
564
+ <div class="sweep-all">
565
+ <p style="text-align: center;">
566
+ <button class="button button-primary btn-sweep-all"><?php _e( 'Sweep All', 'wp-sweep' ); ?></button>
567
+ </p>
568
+ </div>
569
+ </div>
class-command.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class WPSweep_Command extends WP_CLI_Command {
4
+ /**
5
+ * Clean up unused, orphaned and duplicated data in your WordPress
6
+ *
7
+ * ## OPTIONS
8
+ *
9
+ * [--all]
10
+ * Sweep all the orphaned data at once.
11
+ *
12
+ * Name of the items selected individually
13
+ * Available Items =
14
+ * revisions
15
+ * auto_drafts
16
+ * deleted_posts
17
+ * unapproved_comments
18
+ * spam_comments
19
+ * deleted_comments
20
+ * transient_options
21
+ * orphan_postmeta
22
+ * orphan_commentmeta
23
+ * orphan_usermeta
24
+ * orphan_termmeta
25
+ * orphan_term_relationships
26
+ * unused_terms
27
+ * duplicated_postmeta
28
+ * duplicated_commentmeta
29
+ * duplicated_usermeta
30
+ * duplicated_termmeta
31
+ * optimize_database
32
+ * oembed_postmet
33
+ *
34
+ * ## EXAMPLES
35
+ *
36
+ * 1. wp sweep --all
37
+ * - Run Sweep for all the items.
38
+ * 2. wp sweep revisions
39
+ * - Sweep only Revision
40
+ * 3. wp sweep revisions auto_drafts deleted_posts unapproved_comments spam_comments deleted_comments transient_options orphan_postmeta orphan_commentmeta orphan_usermeta orphan_termmeta orphan_term_relationships unused_terms duplicated_postmeta duplicated_commentmeta duplicated_usermeta duplicated_termmeta optimize_database oembed_postmet
41
+ * - Sweep the selected items
42
+ *
43
+ *
44
+ */
45
+ public function __invoke( $args, $assoc_args ) {
46
+
47
+ $items = array();
48
+
49
+ $default_items = array(
50
+ '0' => 'revisions',
51
+ '1' => 'auto_drafts',
52
+ '2' => 'deleted_posts',
53
+ '3' => 'unapproved_comments',
54
+ '4' => 'spam_comments',
55
+ '5' => 'deleted_comments',
56
+ '6' => 'transient_options',
57
+ '7' => 'orphan_postmeta',
58
+ '8' => 'orphan_commentmeta',
59
+ '9' => 'orphan_usermeta',
60
+ '10' => 'orphan_termmeta',
61
+ '11' => 'orphan_term_relationships',
62
+ '12' => 'unused_terms',
63
+ '13' => 'duplicated_postmeta',
64
+ '14' => 'duplicated_commentmeta',
65
+ '15' => 'duplicated_usermeta',
66
+ '16' => 'duplicated_termmeta',
67
+ '17' => 'optimize_database',
68
+ '18' => 'oembed_postmeta',
69
+ );
70
+
71
+ if ( isset( $assoc_args['all'] ) && true == $assoc_args['all'] ) {
72
+ $this->run_sweep( $default_items );
73
+ WP_CLI::success( 'Sweep Complete' );
74
+
75
+ return;
76
+ } else {
77
+ foreach ( $default_items as $key => $item ) {
78
+ if ( in_array( $item, $args ) ) {
79
+ array_push( $items, $item );
80
+ }
81
+ }
82
+
83
+ $this->run_sweep( $items );
84
+ WP_CLI::success( 'Sweep Complete!' );
85
+
86
+ return;
87
+ }
88
+
89
+ }
90
+
91
+ public function run_sweep( $items ) {
92
+
93
+ $sweep = new WPSweep();
94
+
95
+ foreach ( $items as $key => $value ) {
96
+ $count = $sweep->count( $value );
97
+ if ( 0 !== $count && '0' !== $count ) {
98
+ $message = $sweep->sweep( $value );
99
+ WP_CLI::success( $message );
100
+ }
101
+ }
102
+
103
+ }
104
+ }
105
+
106
+ WP_CLI::add_command( 'sweep', 'WPSweep_Command' );
index.php CHANGED
@@ -1,2 +1,2 @@
1
  <?php
2
- # Silence is golden.
1
  <?php
2
+ # Silence is golden.
js/wp-sweep.js CHANGED
@@ -1,95 +1,95 @@
1
  (function ($) {
2
- 'use strict';
3
 
4
- $(function () {
5
- var $body = $('body'),
6
- sweep = function($node) {
7
- var $row = $node.parents('tr');
8
 
9
- // Add Active
10
- $body.addClass('sweep-active');
11
- // Add Disabled
12
- $node.prop('disabled', true).text(wp_sweep.text_sweeping);
13
 
14
- return $.get(ajaxurl, { action: $node.data('action'), sweep_name: $node.data('sweep_name'), sweep_type: $node.data('sweep_type'), '_wpnonce': $node.data('nonce') }, function(data) {
15
- if(data.success) {
16
- var count = parseInt(data.data.count, 10);
17
- // Count Col
18
- $('.sweep-count', $row).text(count.toLocaleString());
19
- // % Of Col
20
- $('.sweep-percentage', $row).text(data.data.percentage);
21
- // Action Col
22
- if(count === 0) {
23
- $node.parent('td').html(wp_sweep.text_na);
24
- }
25
- // Stats
26
- $.each(data.data.stats, function(key, value) {
27
- $('.sweep-count-type-' + key).text(parseInt(value, 10).toLocaleString());
28
- });
29
- // Message
30
- $row.parents('.table-sweep').prev('.sweep-message').html('<div class="updated"><p>' + data.data.sweep + '</p></div>');
31
- // Hide Sweep Details
32
- $('.sweep-details', $row).html('').hide();
33
- // Remove Active
34
- $body.removeClass('sweep-active');
35
- // Remove Disabled
36
- $node.prop('disabled', false).text(wp_sweep.text_sweep);
37
- }
38
- });
39
- };
40
 
41
- $('.btn-sweep').click(function(evt) {
42
- evt.preventDefault();
43
- sweep($(this));
44
- });
45
 
46
- $('.btn-sweep-details').click(function(evt) {
47
- evt.preventDefault();
48
- var $node = $(this);
49
 
50
- $.get(ajaxurl, { action: $node.data('action'), sweep_name: $node.data('sweep_name'), sweep_type: $node.data('sweep_type'), '_wpnonce': $node.data('nonce') }, function(data) {
51
- if(data.success) {
52
- if(data.data.length > 0) {
53
- var html = '';
54
- $.each(data.data, function(i, n) {
55
- html += '<li>' + n + '</li>';
56
- });
57
- $('.sweep-details', $node.parents('tr')).html('<ol>' + html + '</ol>').show();
58
- }
59
- }
60
- });
61
- });
62
 
63
- $('.btn-sweep-all').click(function(evt) {
64
- evt.preventDefault();
65
- var $node = $(this), $btn_sweep = $('.btn-sweep'), sweep_all;
66
 
67
- $node.prop('disabled', true).text(wp_sweep.text_sweeping);
68
 
69
- sweep_all = $btn_sweep.toArray().reduce(function(current, next) {
70
- return current.then(function() {
71
- return sweep($(next));
72
- });
73
- }, $().promise());
74
 
75
- sweep_all.done(function() {
76
- // Remove Active
77
- $body.removeClass('sweep-active');
78
- // Remove Disabled
79
- $node.prop('disabled', false).text(wp_sweep.text_sweep_all);
80
- });
81
- });
82
 
83
- /*
84
  Page closing confirmation
85
  https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/beforeunload
86
  */
87
- $(window).on('beforeunload', function (e) {
88
- if ($body.hasClass('sweep-active')) {
89
- (e || window.event).returnValue = wp_sweep.text_close_warning; // Gecko and Trident
90
- return wp_sweep.text_close_warning; // Gecko and WebKit
91
- }
92
- });
93
- });
94
 
95
- })(jQuery);
1
  (function ($) {
2
+ 'use strict';
3
 
4
+ $(function () {
5
+ var $body = $( 'body' ),
6
+ sweep = function($node) {
7
+ var $row = $node.parents( 'tr' );
8
 
9
+ // Add Active
10
+ $body.addClass( 'sweep-active' );
11
+ // Add Disabled
12
+ $node.prop( 'disabled', true ).text( wp_sweep.text_sweeping );
13
 
14
+ return $.get(ajaxurl, { action: $node.data( 'action' ), sweep_name: $node.data( 'sweep_name' ), sweep_type: $node.data( 'sweep_type' ), '_wpnonce': $node.data( 'nonce' ) }, function(data) {
15
+ if (data.success) {
16
+ var count = parseInt( data.data.count, 10 );
17
+ // Count Col
18
+ $( '.sweep-count', $row ).text( count.toLocaleString() );
19
+ // % Of Col
20
+ $( '.sweep-percentage', $row ).text( data.data.percentage );
21
+ // Action Col
22
+ if (count === 0) {
23
+ $node.parent( 'td' ).html( wp_sweep.text_na );
24
+ }
25
+ // Stats
26
+ $.each(data.data.stats, function(key, value) {
27
+ $( '.sweep-count-type-' + key ).text( parseInt( value, 10 ).toLocaleString() );
28
+ });
29
+ // Message
30
+ $row.parents( '.table-sweep' ).prev( '.sweep-message' ).html( '<div class="updated"><p>' + data.data.sweep + '</p></div>' );
31
+ // Hide Sweep Details
32
+ $( '.sweep-details', $row ).html( '' ).hide();
33
+ // Remove Active
34
+ $body.removeClass( 'sweep-active' );
35
+ // Remove Disabled
36
+ $node.prop( 'disabled', false ).text( wp_sweep.text_sweep );
37
+ }
38
+ });
39
+ };
40
 
41
+ $( '.btn-sweep' ).click(function(evt) {
42
+ evt.preventDefault();
43
+ sweep( $( this ) );
44
+ });
45
 
46
+ $( '.btn-sweep-details' ).click(function(evt) {
47
+ evt.preventDefault();
48
+ var $node = $( this );
49
 
50
+ $.get(ajaxurl, { action: $node.data( 'action' ), sweep_name: $node.data( 'sweep_name' ), sweep_type: $node.data( 'sweep_type' ), '_wpnonce': $node.data( 'nonce' ) }, function(data) {
51
+ if (data.success) {
52
+ if (data.data.length > 0) {
53
+ var html = '';
54
+ $.each(data.data, function(i, n) {
55
+ html += '<li>' + n + '</li>';
56
+ });
57
+ $( '.sweep-details', $node.parents( 'tr' ) ).html( '<ol>' + html + '</ol>' ).show();
58
+ }
59
+ }
60
+ });
61
+ });
62
 
63
+ $( '.btn-sweep-all' ).click(function(evt) {
64
+ evt.preventDefault();
65
+ var $node = $( this ), $btn_sweep = $( '.btn-sweep' ), sweep_all;
66
 
67
+ $node.prop( 'disabled', true ).text( wp_sweep.text_sweeping );
68
 
69
+ sweep_all = $btn_sweep.toArray().reduce(function(current, next) {
70
+ return current.then(function() {
71
+ return sweep( $( next ) );
72
+ });
73
+ }, $().promise());
74
 
75
+ sweep_all.done(function() {
76
+ // Remove Active
77
+ $body.removeClass( 'sweep-active' );
78
+ // Remove Disabled
79
+ $node.prop( 'disabled', false ).text( wp_sweep.text_sweep_all );
80
+ });
81
+ });
82
 
83
+ /*
84
  Page closing confirmation
85
  https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/beforeunload
86
  */
87
+ $( window ).on('beforeunload', function (e) {
88
+ if ($body.hasClass( 'sweep-active' )) {
89
+ (e || window.event).returnValue = wp_sweep.text_close_warning; // Gecko and Trident
90
+ return wp_sweep.text_close_warning; // Gecko and WebKit
91
+ }
92
+ });
93
+ });
94
 
95
+ })(jQuery);
readme.txt CHANGED
@@ -1,10 +1,13 @@
1
  === WP-Sweep ===
 
 
 
2
  Contributors: GamerZ
3
- Donate link: http://lesterchan.net/site/donation/
4
  Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term meta, term relationships, revisions, auto drafts, transient, database, tables, oembed
5
  Requires at least: 4.4
6
- Tested up to: 4.5
7
- Stable tag: 1.0.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -49,9 +52,6 @@ Following delete functions are used:
49
  * delete_transient()
50
  * delete_site_transient()
51
 
52
- = Build Status =
53
- [![Build Status](https://travis-ci.org/lesterchan/wp-sweep.svg?branch=master)](https://travis-ci.org/lesterchan/wp-sweep)
54
-
55
  = Development =
56
  * [https://github.com/lesterchan/wp-sweep](https://github.com/lesterchan/wp-sweep "https://github.com/lesterchan/wp-sweep")
57
 
@@ -62,6 +62,19 @@ Following delete functions are used:
62
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
63
 
64
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  = 1.0.7 =
66
  * FIXES: Use custom query to delete Orphaned Term Relationship if wp_remove_object_terms() fails
67
 
1
  === WP-Sweep ===
2
+
3
+ [![Build Status](https://travis-ci.org/lesterchan/wp-sweep.svg?branch=master)](https://travis-ci.org/lesterchan/wp-sweep) [![Code Climate](https://codeclimate.com/github/lesterchan/wp-sweep/badges/gpa.svg)](https://codeclimate.com/github/lesterchan/wp-sweep) [![Issue Count](https://codeclimate.com/github/lesterchan/wp-sweep/badges/issue_count.svg)](https://codeclimate.com/github/lesterchan/wp-sweep)
4
+
5
  Contributors: GamerZ
6
+ Donate link: https://lesterchan.net/site/donation/
7
  Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term meta, term relationships, revisions, auto drafts, transient, database, tables, oembed
8
  Requires at least: 4.4
9
+ Tested up to: 4.7
10
+ Stable tag: 1.0.10
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
52
  * delete_transient()
53
  * delete_site_transient()
54
 
 
 
 
55
  = Development =
56
  * [https://github.com/lesterchan/wp-sweep](https://github.com/lesterchan/wp-sweep "https://github.com/lesterchan/wp-sweep")
57
 
62
  I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
63
 
64
  == Changelog ==
65
+ = 1.0.10 =
66
+ * FIXED: Invalid plugin head 'This plugin has an invalid header.'
67
+
68
+ = 1.0.9 =
69
+ * NEW: Support for Codeclimate
70
+ * FIXES: Uses `get_sites()` on WordPress 4.6. This should fix deprecated notices.
71
+ * FIXES: Fixes translation placeholder count. Props @pedro-mendonca.
72
+ * FIXES: Use `manage_options` capability as it conflicts with Admin Menu Editor on multisite installs. Props @EusebiuOprinoiu.
73
+
74
+ = 1.0.8 =
75
+ * NEW: Added wp_sweep_excluded_taxonomies filter to allow more than just link_category taxonomy
76
+ * NEW: Support for WP-CLI `wp sweep`
77
+
78
  = 1.0.7 =
79
  * FIXES: Use custom query to delete Orphaned Term Relationship if wp_remove_object_terms() fails
80
 
uninstall.php CHANGED
@@ -2,15 +2,19 @@
2
  /*
3
  * Uninstall WP-Sweep
4
  */
5
- if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
6
- exit ();
 
 
 
7
 
8
  if ( is_multisite() ) {
9
- $ms_sites = wp_get_sites();
10
 
11
- if( 0 < sizeof( $ms_sites ) ) {
12
  foreach ( $ms_sites as $ms_site ) {
13
- switch_to_blog( $ms_site['blog_id'] );
 
14
  plugin_uninstalled();
15
  }
16
  }
@@ -26,4 +30,5 @@ if ( is_multisite() ) {
26
  * @access public
27
  * @return void
28
  */
29
- function plugin_uninstalled() {}
 
2
  /*
3
  * Uninstall WP-Sweep
4
  */
5
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
6
+ exit;
7
+ }
8
+
9
+
10
 
11
  if ( is_multisite() ) {
12
+ $ms_sites = function_exists( 'get_sites' ) ? get_sites() : wp_get_sites();
13
 
14
+ if ( 0 < sizeof( $ms_sites ) ) {
15
  foreach ( $ms_sites as $ms_site ) {
16
+ $blog_id = class_exists( 'WP_Site' ) ? $ms_site->blog_id : $ms_site['blog_id'];
17
+ switch_to_blog( $blog_id );
18
  plugin_uninstalled();
19
  }
20
  }
30
  * @access public
31
  * @return void
32
  */
33
+ function plugin_uninstalled() {
34
+ }
wp-sweep.php CHANGED
@@ -1,29 +1,30 @@
1
  <?php
2
  /*
3
  Plugin Name: WP-Sweep
4
- Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
  Description: WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It cleans up revisions, auto drafts, unapproved comments, spam comments, trashed comments, orphan post meta, orphan comment meta, orphan user meta, orphan term relationships, unused terms, duplicated post meta, duplicated comment meta, duplicated user meta and transient options. It also optimizes your database tables.
6
- Version: 1.0.7
7
  Author: Lester 'GaMerZ' Chan
8
- Author URI: http://lesterchan.net
9
  Text Domain: wp-sweep
10
  License: GPL2
11
  */
12
 
13
- /* Copyright 2016 Lester Chan (email : lesterchan@gmail.com)
 
14
 
15
- This program is free software; you can redistribute it and/or modify
16
- it under the terms of the GNU General Public License, version 2, as
17
- published by the Free Software Foundation.
18
 
19
- This program is distributed in the hope that it will be useful,
20
- but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- GNU General Public License for more details.
23
 
24
- You should have received a copy of the GNU General Public License
25
- along with this program; if not, write to the Free Software
26
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
  */
28
 
29
  /**
@@ -31,7 +32,7 @@ License: GPL2
31
  *
32
  * @since 1.0.0
33
  */
34
- define( 'WP_SWEEP_VERSION', '1.0.6' );
35
 
36
  /**
37
  * WP-Sweep class
@@ -39,854 +40,909 @@ define( 'WP_SWEEP_VERSION', '1.0.6' );
39
  * @since 1.0.0
40
  */
41
  class WPSweep {
42
- /**
43
- * Limit the number of items to show for sweep details
44
- *
45
- * @since 1.0.3
46
- *
47
- * @access public
48
- * @var int
49
- */
50
- public $limit_details = 500;
51
-
52
- /**
53
- * Static instance
54
- *
55
- * @since 1.0.0
56
- *
57
- * @access private
58
- * @var $instance
59
- */
60
- private static $instance;
61
-
62
- /**
63
- * Constructor method
64
- *
65
- * @since 1.0.0
66
- *
67
- * @access public
68
- */
69
- public function __construct() {
70
- // Add Plugin Hooks
71
- add_action( 'plugins_loaded', array( $this, 'add_hooks' ) );
72
-
73
- // Load Translation
74
- load_plugin_textdomain( 'wp-sweep' );
75
-
76
- // Plugin Activation/Deactivation
77
- register_activation_hook( __FILE__, array( $this, 'plugin_activation' ) );
78
- register_deactivation_hook( __FILE__, array( $this, 'plugin_deactivation' ) );
79
- }
80
-
81
- /**
82
- * Initializes the plugin object and returns its instance
83
- *
84
- * @since 1.0.0
85
- *
86
- * @access public
87
- * @return object The plugin object instance
88
- */
89
- public static function get_instance() {
90
- if ( ! isset( self::$instance ) ) {
91
- self::$instance = new self();
92
- }
93
- return self::$instance;
94
- }
95
-
96
- /**
97
- * Init this plugin
98
- *
99
- * @since 1.0.0
100
- *
101
- * @access public
102
- * @return void
103
- */
104
- public function init() {}
105
-
106
- /**
107
- * Adds all the plugin hooks
108
- *
109
- * @since 1.0.0
110
- *
111
- * @access public
112
- * @return void
113
- */
114
- public function add_hooks() {
115
- // Actions
116
- add_action( 'init', array( $this, 'init' ) );
117
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
118
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
119
- add_action( 'wp_ajax_sweep_details', array( $this, 'ajax_sweep_details' ) );
120
- add_action( 'wp_ajax_sweep', array( $this, 'ajax_sweep' ) );
121
- }
122
-
123
- /**
124
- * Enqueue JS/CSS files used for admin
125
- *
126
- * @since 1.0.3
127
- *
128
- * @access public
129
- * @param string $hook
130
- * @return void
131
- */
132
- public function admin_enqueue_scripts( $hook ) {
133
- if( 'wp-sweep/admin.php' !== $hook ) {
134
- return;
135
- }
136
-
137
- if( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
138
- wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.js' ), array( 'jquery' ) , WP_SWEEP_VERSION, true );
139
- } else {
140
- wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.min.js' ), array( 'jquery' ) , WP_SWEEP_VERSION, true );
141
- }
142
-
143
- wp_localize_script( 'wp-sweep', 'wp_sweep', array(
144
- 'text_close_warning' => __( 'Sweeping is in progress. If you leave now, the process won\'t be completed.', 'wp-sweep' ),
145
- 'text_sweep' => __( 'Sweep', 'wp-sweep' ),
146
- 'text_sweep_all' => __( 'Sweep All', 'wp-sweep' ),
147
- 'text_sweeping' => __( 'Sweeping ...', 'wp-sweep' ),
148
- 'text_na' => __( 'N/A', 'wp-sweep' )
149
- ) );
150
- }
151
-
152
- /**
153
- * Admin menu
154
- *
155
- * @since 1.0.3
156
- *
157
- * @access public
158
- * @return void
159
- */
160
- public function admin_menu() {
161
- add_management_page( __( 'Sweep', 'wp-sweep' ), __( 'Sweep', 'wp-sweep' ), 'activate_plugins', 'wp-sweep/admin.php' );
162
- }
163
-
164
-
165
- /**
166
- * Sweep Details loaded via AJAX
167
- *
168
- * @since 1.0.3
169
- *
170
- * @access public
171
- * @return void
172
- */
173
- public function ajax_sweep_details() {
174
- if( ! empty( $_GET['action'] ) && $_GET['action'] === 'sweep_details' && ! empty( $_GET['sweep_name'] ) && ! empty( $_GET['sweep_type'] ) ) {
175
- // Verify Referer
176
- if ( ! check_admin_referer( 'wp_sweep_details_' . $_GET['sweep_name'] ) ) {
177
- wp_send_json_error( array(
178
- 'error' => __( 'Failed to verify referrer.', 'wp-sweep' )
179
- ) );
180
- } else {
181
- wp_send_json_success( $this->details( $_GET['sweep_name'] ) );
182
- }
183
- }
184
- }
185
-
186
- /**
187
- * Sweep via AJAX
188
- *
189
- * @since 1.0.3
190
- *
191
- * @access public
192
- * @return void
193
- */
194
- public function ajax_sweep() {
195
- if( ! empty( $_GET['action'] ) && $_GET['action'] === 'sweep' && ! empty( $_GET['sweep_name'] ) && ! empty( $_GET['sweep_type'] ) ) {
196
- // Verify Referer
197
- if ( ! check_admin_referer( 'wp_sweep_' . $_GET['sweep_name'] ) ) {
198
- wp_send_json_error( array(
199
- 'error' => __( 'Failed to verify referrer.', 'wp-sweep' )
200
- ) );
201
- } else {
202
- $sweep = $this->sweep( $_GET['sweep_name'] );
203
- $count = $this->count( $_GET['sweep_name'] );
204
- $total_count = $this->total_count( $_GET['sweep_type'] );
205
- $total_stats = array();
206
- switch( $_GET['sweep_type'] ) {
207
- case 'posts':
208
- case 'postmeta':
209
- $total_stats = array( 'posts' => $this->total_count( 'posts' ), 'postmeta' => $this->total_count( 'postmeta' ) );
210
- break;
211
- case 'comments':
212
- case 'commentmeta':
213
- $total_stats = array( 'comments' => $this->total_count( 'comments' ), 'commentmeta' => $this->total_count( 'commentmeta' ) );
214
- break;
215
- case 'users':
216
- case 'usermeta':
217
- $total_stats = array( 'users' => $this->total_count( 'users' ), 'usermeta' => $this->total_count( 'usermeta' ) );
218
- break;
219
- case 'term_relationships':
220
- case 'term_taxonomy':
221
- case 'terms':
222
- case 'termmeta':
223
- $total_stats = array( 'term_relationships' => $this->total_count( 'term_relationships' ), 'term_taxonomy' => $this->total_count( 'term_taxonomy' ), 'terms' => $this->total_count( 'terms' ), 'termmeta' => $this->total_count( 'termmeta' ) );
224
- break;
225
- case 'options':
226
- $total_stats = array( 'options' => $this->total_count( 'options' ) );
227
- break;
228
- case 'tables':
229
- $total_stats = array( 'tables' => $this->total_count( 'tables' ) );
230
- break;
231
- }
232
-
233
- wp_send_json_success( array(
234
- 'sweep' => $sweep,
235
- 'count' => $count,
236
- 'total' => $total_count,
237
- 'percentage' => $this->format_percentage( $count, $total_count ),
238
- 'stats' => $total_stats
239
- ) );
240
- }
241
- }
242
- }
243
-
244
- /**
245
- * Count the number of total items belonging to each sweep
246
- *
247
- * @since 1.0.0
248
- *
249
- * @access public
250
- * @param string $name
251
- * @return int Number of items belonging to each sweep
252
- */
253
- public function total_count( $name ) {
254
- global $wpdb;
255
-
256
- $count = 0;
257
-
258
- switch( $name ) {
259
- case 'posts':
260
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts" );
261
- break;
262
- case 'postmeta':
263
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta" );
264
- break;
265
- case 'comments':
266
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments" );
267
- break;
268
- case 'commentmeta':
269
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta" );
270
- break;
271
- case 'users':
272
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
273
- break;
274
- case 'usermeta':
275
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->usermeta" );
276
- break;
277
- case 'term_relationships':
278
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_relationships" );
279
- break;
280
- case 'term_taxonomy':
281
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_taxonomy" );
282
- break;
283
- case 'terms':
284
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->terms" );
285
- break;
286
- case 'termmeta':
287
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->termmeta" );
288
- break;
289
- case 'options':
290
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->options" );
291
- break;
292
- case 'tables':
293
- $count = sizeof( $wpdb->get_col( 'SHOW TABLES' ) );
294
- break;
295
- }
296
-
297
- return apply_filters( 'wp_sweep_total_count', $count, $name );
298
- }
299
-
300
- /**
301
- * Count the number of items belonging to each sweep
302
- *
303
- * @since 1.0.0
304
- *
305
- * @access public
306
- * @param string $name
307
- * @return int Number of items belonging to each sweep
308
- */
309
- public function count( $name ) {
310
- global $wpdb;
311
-
312
- $count = 0;
313
-
314
- switch( $name ) {
315
- case 'revisions':
316
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = %s", 'revision' ) );
317
- break;
318
- case 'auto_drafts':
319
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = %s", 'auto-draft' ) );
320
- break;
321
- case 'deleted_posts':
322
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = %s", 'trash' ) );
323
- break;
324
- case 'unapproved_comments':
325
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = %s", '0' ) );
326
- break;
327
- case 'spam_comments':
328
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = %s", 'spam' ) );
329
- break;
330
- case 'deleted_comments':
331
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed' ) );
332
- break;
333
- case 'transient_options':
334
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(option_id) FROM $wpdb->options WHERE option_name LIKE(%s)", '%_transient_%' ) );
335
- break;
336
- case 'orphan_postmeta':
337
- $count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)" );
338
- break;
339
- case 'orphan_commentmeta':
340
- $count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)" );
341
- break;
342
- case 'orphan_usermeta':
343
- $count = $wpdb->get_var( "SELECT COUNT(umeta_id) FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)" );
344
- break;
345
- case 'orphan_termmeta':
346
- $count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
347
- break;
348
- case 'orphan_term_relationships':
349
- $count = $wpdb->get_var( "SELECT COUNT(object_id) FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy != 'link_category' AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" );
350
- break;
351
- case 'unused_terms':
352
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(t.term_id) FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ")", 0 ) );
353
- break;
354
- case 'duplicated_postmeta':
355
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1 ) );
356
- if( is_array( $query ) ) {
357
- $count = array_sum( array_map( 'intval', $query ) );
358
- }
359
- break;
360
- case 'duplicated_commentmeta':
361
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->commentmeta GROUP BY comment_id, meta_key, meta_value HAVING count > %d", 1 ) );
362
- if( is_array( $query ) ) {
363
- $count = array_sum( array_map( 'intval', $query ) );
364
- }
365
- break;
366
- case 'duplicated_usermeta':
367
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(umeta_id) AS count FROM $wpdb->usermeta GROUP BY user_id, meta_key, meta_value HAVING count > %d", 1 ) );
368
- if( is_array( $query ) ) {
369
- $count = array_sum( array_map( 'intval', $query ) );
370
- }
371
- break;
372
- case 'duplicated_termmeta':
373
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->termmeta GROUP BY term_id, meta_key, meta_value HAVING count > %d", 1 ) );
374
- if( is_array( $query ) ) {
375
- $count = array_sum( array_map( 'intval', $query ) );
376
- }
377
- break;
378
- case 'optimize_database':
379
- $count = sizeof( $wpdb->get_col( 'SHOW TABLES' ) );
380
- break;
381
- case 'oembed_postmeta':
382
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_id) FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
383
- break;
384
- }
385
-
386
- return apply_filters( 'wp_sweep_count', $count, $name );
387
- }
388
-
389
- /**
390
- * Return more details about a sweep
391
- *
392
- * @since 1.0.3
393
- *
394
- * @access public
395
- * @param string $name
396
- * @return int Number of items belonging to each sweep
397
- */
398
- public function details( $name ) {
399
- global $wpdb;
400
-
401
- $details = array();
402
-
403
- switch( $name ) {
404
- case 'revisions':
405
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_type = %s LIMIT %d", 'revision', $this->limit_details ) );
406
- break;
407
- case 'auto_drafts':
408
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_status = %s LIMIT %d", 'auto-draft', $this->limit_details ) );
409
- break;
410
- case 'deleted_posts':
411
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_status = %s LIMIT %d", 'trash', $this->limit_details ) );
412
- break;
413
- case 'unapproved_comments':
414
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT comment_author FROM $wpdb->comments WHERE comment_approved = %s LIMIT %d", '0', $this->limit_details ) );
415
- break;
416
- case 'spam_comments':
417
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT comment_author FROM $wpdb->comments WHERE comment_approved = %s LIMIT %d", 'spam', $this->limit_details ) );
418
- break;
419
- case 'deleted_comments':
420
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT comment_author FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s) LIMIT %d", 'trash', 'post-trashed', $this->limit_details ) );
421
- break;
422
- case 'transient_options':
423
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE(%s) LIMIT %d", '%_transient_%', $this->limit_details ) );
424
- break;
425
- case 'orphan_postmeta':
426
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts) LIMIT %d", $this->limit_details ) );
427
- break;
428
- case 'orphan_commentmeta':
429
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments) LIMIT %d", $this->limit_details ) );
430
- break;
431
- case 'orphan_usermeta':
432
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users) LIMIT %d", $this->limit_details ) );
433
- break;
434
- case 'orphan_termmeta':
435
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms) LIMIT %d", $this->limit_details ) );
436
- break;
437
- case 'orphan_term_relationships':
438
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy != 'link_category' AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts) LIMIT %d", $this->limit_details ) );
439
- break;
440
- case 'unused_terms':
441
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ") LIMIT %d", 0, $this->limit_details ) );
442
- break;
443
- case 'duplicated_postmeta':
444
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(meta_id) AS count, meta_key FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
445
- $details = array();
446
- if( $query ) {
447
- foreach( $query as $meta ) {
448
- $details[] = $meta->meta_key;
449
- }
450
- }
451
- break;
452
- case 'duplicated_commentmeta':
453
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(meta_id) AS count, meta_key FROM $wpdb->commentmeta GROUP BY comment_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
454
- $details = array();
455
- if( $query ) {
456
- foreach( $query as $meta ) {
457
- $details[] = $meta->meta_key;
458
- }
459
- }
460
- break;
461
- case 'duplicated_usermeta':
462
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(umeta_id) AS count, meta_key FROM $wpdb->usermeta GROUP BY user_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
463
- $details = array();
464
- if( $query ) {
465
- foreach( $query as $meta ) {
466
- $details[] = $meta->meta_key;
467
- }
468
- }
469
- break;
470
- case 'duplicated_termmeta':
471
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(meta_id) AS count, meta_key FROM $wpdb->termmeta GROUP BY term_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
472
- $details = array();
473
- if( $query ) {
474
- foreach( $query as $meta ) {
475
- $details[] = $meta->meta_key;
476
- }
477
- }
478
- break;
479
- case 'optimize_database':
480
- $details = $wpdb->get_col( 'SHOW TABLES' );
481
- break;
482
- case 'oembed_postmeta':
483
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s) LIMIT %d", '%_oembed_%', $this->limit_details ) );
484
- break;
485
- }
486
-
487
- return apply_filters( 'wp_sweep_details', $details, $name );
488
- }
489
-
490
- /**
491
- * Does the sweeping/cleaning up
492
- *
493
- * @since 1.0.0
494
- *
495
- * @access public
496
- * @param string $name
497
- * @return string Processed message
498
- */
499
- public function sweep( $name ) {
500
- global $wpdb;
501
-
502
- $message = '';
503
-
504
- switch( $name ) {
505
- case 'revisions':
506
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s", 'revision' ) );
507
- if( $query ) {
508
- foreach ( $query as $id ) {
509
- wp_delete_post_revision( intval( $id ) );
510
- }
511
-
512
- $message = sprintf( __( '%s Revisions Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
513
- }
514
- break;
515
- case 'auto_drafts':
516
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s", 'auto-draft' ) );
517
- if( $query ) {
518
- foreach ( $query as $id ) {
519
- wp_delete_post( intval( $id ), true );
520
- }
521
-
522
- $message = sprintf( __( '%s Auto Drafts Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
523
- }
524
- break;
525
- case 'deleted_posts':
526
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s", 'trash' ) );
527
- if( $query ) {
528
- foreach ( $query as $id ) {
529
- wp_delete_post( $id, true );
530
- }
531
-
532
- $message = sprintf( __( '%s Deleted Posts Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
533
- }
534
- break;
535
- case 'unapproved_comments':
536
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", '0' ) );
537
- if( $query ) {
538
- foreach ( $query as $id ) {
539
- wp_delete_comment( intval( $id ), true );
540
- }
541
-
542
- $message = sprintf( __( '%s Unapproved Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
543
- }
544
- break;
545
- case 'spam_comments':
546
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", 'spam' ) );
547
- if( $query ) {
548
- foreach ( $query as $id ) {
549
- wp_delete_comment( intval( $id ), true );
550
- }
551
-
552
- $message = sprintf( __( '%s Spam Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
553
- }
554
- break;
555
- case 'deleted_comments':
556
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed' ) );
557
- if( $query ) {
558
- foreach ( $query as $id ) {
559
- wp_delete_comment( intval( $id ), true );
560
- }
561
-
562
- $message = sprintf( __( '%s Trash Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
563
- }
564
- break;
565
- case 'transient_options':
566
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE(%s)", '%_transient_%' ) );
567
- if( $query ) {
568
- foreach ( $query as $option_name ) {
569
- if( strpos( $option_name, '_site_transient_' ) !== false ) {
570
- delete_site_transient( str_replace( '_site_transient_', '', $option_name ) );
571
- } else {
572
- delete_transient( str_replace( '_transient_', '', $option_name ) );
573
- }
574
- }
575
-
576
- $message = sprintf( __( '%s Transient Options Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
577
- }
578
- break;
579
- case 'orphan_postmeta':
580
- $query = $wpdb->get_results( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)" );
581
- if( $query ) {
582
- foreach ( $query as $meta ) {
583
- $post_id = intval( $meta->post_id );
584
- if( $post_id === 0 ) {
585
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
586
- } else {
587
- delete_post_meta( $post_id, $meta->meta_key );
588
- }
589
- }
590
-
591
- $message = sprintf( __( '%s Orphaned Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
592
- }
593
- break;
594
- case 'orphan_commentmeta':
595
- $query = $wpdb->get_results( "SELECT comment_id, meta_key FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)" );
596
- if( $query ) {
597
- foreach ( $query as $meta ) {
598
- $comment_id = intval( $meta->comment_id );
599
- if( $comment_id === 0 ) {
600
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s", $comment_id, $meta->meta_key ) );
601
- } else {
602
- delete_comment_meta( $comment_id, $meta->meta_key );
603
- }
604
- }
605
-
606
- $message = sprintf( __( '%s Orphaned Comment Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
607
- }
608
- break;
609
- case 'orphan_usermeta':
610
- $query = $wpdb->get_results( "SELECT user_id, meta_key FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)" );
611
- if( $query ) {
612
- foreach ( $query as $meta ) {
613
- $user_id = intval( $meta->user_id );
614
- if( $user_id === 0 ) {
615
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta->meta_key ) );
616
- } else {
617
- delete_user_meta( $user_id, $meta->meta_key );
618
- }
619
- }
620
-
621
- $message = sprintf( __( '%s Orphaned User Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
622
- }
623
- break;
624
- case 'orphan_termmeta':
625
- $query = $wpdb->get_results( "SELECT term_id, meta_key FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
626
- if( $query ) {
627
- foreach ( $query as $meta ) {
628
- $term_id = intval( $meta->term_id );
629
- if( $term_id === 0 ) {
630
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE term_id = %d AND meta_key = %s", $term_id, $meta->meta_key ) );
631
- } else {
632
- delete_term_meta( $term_id, $meta->meta_key );
633
- }
634
- }
635
-
636
- $message = sprintf( __( '%s Orphaned Term Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
637
- }
638
- break;
639
- case 'orphan_term_relationships':
640
- $query = $wpdb->get_results( "SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy != 'link_category' AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" );
641
- if( $query ) {
642
- foreach ( $query as $tax ) {
643
- $wp_remove_object_terms = wp_remove_object_terms( intval( $tax->object_id ), intval( $tax->term_id ), $tax->taxonomy );
644
- if( $wp_remove_object_terms !== true ) {
645
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $tax->object_id, $tax->term_taxonomy_id ) );
646
- }
647
- }
648
-
649
- $message = sprintf( __( '%s Orphaned Term Relationships Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
650
- }
651
- break;
652
- case 'unused_terms':
653
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT tt.term_taxonomy_id, t.term_id, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ")", 0 ) );
654
- if( $query ) {
655
- $check_wp_terms = false;
656
- foreach ( $query as $tax ) {
657
- if( taxonomy_exists( $tax->taxonomy ) ) {
658
- wp_delete_term( intval( $tax->term_id ), $tax->taxonomy );
659
- } else {
660
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", intval( $tax->term_taxonomy_id ) ) );
661
- $check_wp_terms = true;
662
- }
663
- }
664
- // We need this for invalid taxonomies
665
- if( $check_wp_terms ) {
666
- $wpdb->get_results( "DELETE FROM $wpdb->terms WHERE term_id NOT IN (SELECT term_id FROM $wpdb->term_taxonomy)" );
667
- }
668
-
669
- $message = sprintf( __( '%s Unused Terms Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
670
- }
671
- break;
672
- case 'duplicated_postmeta':
673
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, post_id, COUNT(*) AS count FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1 ) );
674
- if( $query ) {
675
- foreach ( $query as $meta ) {
676
- $ids = array_map( 'intval', explode( ',', $meta->ids ) );
677
- array_pop( $ids );
678
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN (" . implode( ',', $ids ) . ") AND post_id = %d", intval( $meta->post_id ) ) );
679
- }
680
-
681
- $message = sprintf( __( '%s Duplicated Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
682
- }
683
- break;
684
- case 'duplicated_commentmeta':
685
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, comment_id, COUNT(*) AS count FROM $wpdb->commentmeta GROUP BY comment_id, meta_key, meta_value HAVING count > %d", 1 ) );
686
- if( $query ) {
687
- foreach ( $query as $meta ) {
688
- $ids = array_map( 'intval', explode( ',', $meta->ids ) );
689
- array_pop( $ids );
690
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN (" . implode( ',', $ids ) . ") AND comment_id = %d", intval( $meta->comment_id ) ) );
691
- }
692
-
693
- $message = sprintf( __( '%s Duplicated Comment Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
694
- }
695
- break;
696
- case 'duplicated_usermeta':
697
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT GROUP_CONCAT(umeta_id ORDER BY umeta_id DESC) AS ids, user_id, COUNT(*) AS count FROM $wpdb->usermeta GROUP BY user_id, meta_key, meta_value HAVING count > %d", 1 ) );
698
- if( $query ) {
699
- foreach ( $query as $meta ) {
700
- $ids = array_map( 'intval', explode( ',', $meta->ids ) );
701
- array_pop( $ids );
702
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE umeta_id IN (" . implode( ',', $ids ) . ") AND user_id = %d", intval( $meta->user_id ) ) );
703
- }
704
-
705
- $message = sprintf( __( '%s Duplicated User Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
706
- }
707
- break;
708
- case 'duplicated_termmeta':
709
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, term_id, COUNT(*) AS count FROM $wpdb->termmeta GROUP BY term_id, meta_key, meta_value HAVING count > %d", 1 ) );
710
- if( $query ) {
711
- foreach ( $query as $meta ) {
712
- $ids = array_map( 'intval', explode( ',', $meta->ids ) );
713
- array_pop( $ids );
714
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_id IN (" . implode( ',', $ids ) . ") AND term_id = %d", intval( $meta->term_id ) ) );
715
- }
716
-
717
- $message = sprintf( __( '%s Duplicated Term Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
718
- }
719
- break;
720
- case 'optimize_database':
721
- $query = $wpdb->get_col( 'SHOW TABLES' );
722
- if( $query ) {
723
- $tables = implode( ',', $query );
724
- $wpdb->query( "OPTIMIZE TABLE $tables" );
725
- $message = sprintf( __( '%s Tables Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
726
- }
727
- break;
728
- case 'oembed_postmeta':
729
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
730
- if( $query ) {
731
- foreach ( $query as $meta ) {
732
- $post_id = intval( $meta->post_id );
733
- if( $post_id === 0 ) {
734
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
735
- } else {
736
- delete_post_meta( $post_id, $meta->meta_key );
737
- }
738
- }
739
-
740
- $message = sprintf( __( '%s oEmbed Caches In Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
741
- }
742
- break;
743
- }
744
-
745
- return apply_filters( 'wp_sweep_sweep', $message, $name );
746
- }
747
-
748
- /**
749
- * Format number to percentage, taking care of division by 0.
750
- * Props @barisunver https://github.com/barisunver
751
- *
752
- * @since 1.0.2
753
- *
754
- * @access public
755
- * @param int $current
756
- * @param int $total
757
- * @return string Number in percentage
758
- */
759
- public function format_percentage( $current, $total ) {
760
- return ( $total > 0 ? round( ( $current / $total ) * 100, 2 ) : 0 ) . '%';
761
- }
762
-
763
- /*
764
- * Get excluded term IDs
765
- *
766
- * @since 1.0.3
767
- *
768
- * @access private
769
- * @return array Excluded term IDs
770
- */
771
- private function get_excluded_termids() {
772
- $default_term_ids = $this->get_default_taxonomy_termids();
773
- if( ! is_array( $default_term_ids ) ) {
774
- $default_term_ids = array();
775
- }
776
- $parent_term_ids = $this->get_parent_termids();
777
- if( ! is_array( $parent_term_ids ) ) {
778
- $parent_term_ids = array();
779
- }
780
- return array_merge( $default_term_ids, $parent_term_ids );
781
- }
782
-
783
- /*
784
- * Get all default taxonomy term IDs
785
- *
786
- * @since 1.0.3
787
- *
788
- * @access private
789
- * @return array Default taxonomy term IDs
790
- */
791
- private function get_default_taxonomy_termids() {
792
- $taxonomies = get_taxonomies();
793
- $default_term_ids = array();
794
- if( $taxonomies ) {
795
- $tax = array_keys( $taxonomies );
796
- if( $tax ) {
797
- foreach( $tax as $t ) {
798
- $term_id = intval( get_option( 'default_' . $t ) );
799
- if( $term_id > 0 ) {
800
- $default_term_ids[] = $term_id;
801
- }
802
- }
803
- }
804
- }
805
- return $default_term_ids;
806
- }
807
-
808
- /*
809
- * Get terms that has a parent term
810
- *
811
- * @since 1.0.3
812
- *
813
- * @access private
814
- * @return array Parent term IDs
815
- */
816
- private function get_parent_termids() {
817
- global $wpdb;
818
- return $wpdb->get_col( $wpdb->prepare( "SELECT tt.parent FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.parent > %d", 0 ) );
819
- }
820
-
821
- /**
822
- * What to do when the plugin is being deactivated
823
- *
824
- * @since 1.0.0
825
- *
826
- * @access public
827
- * @param boolean $network_wide
828
- * @return void
829
- */
830
- public function plugin_activation( $network_wide ) {
831
- if ( is_multisite() && $network_wide ) {
832
- $ms_sites = wp_get_sites();
833
-
834
- if( 0 < sizeof( $ms_sites ) ) {
835
- foreach ( $ms_sites as $ms_site ) {
836
- switch_to_blog( $ms_site['blog_id'] );
837
- $this->plugin_activated();
838
- restore_current_blog();
839
- }
840
- }
841
- } else {
842
- $this->plugin_activated();
843
- }
844
- }
845
-
846
- /**
847
- * Perform plugin activation tasks
848
- *
849
- * @since 1.0.0
850
- *
851
- * @access private
852
- * @return void
853
- */
854
- private function plugin_activated() {}
855
-
856
- /**
857
- * What to do when the plugin is being activated
858
- *
859
- * @since 1.0.0
860
- *
861
- * @access public
862
- * @param boolean $network_wide
863
- * @return void
864
- */
865
- public function plugin_deactivation( $network_wide ) {
866
- if ( is_multisite() && $network_wide ) {
867
- $ms_sites = wp_get_sites();
868
-
869
- if( 0 < sizeof( $ms_sites ) ) {
870
- foreach ( $ms_sites as $ms_site ) {
871
- switch_to_blog( $ms_site['blog_id'] );
872
- $this->plugin_deactivated();
873
- restore_current_blog();
874
- }
875
- }
876
- } else {
877
- $this->plugin_deactivated();
878
- }
879
- }
880
-
881
- /**
882
- * Perform plugin deactivation tasks
883
- *
884
- * @since 1.0.0
885
- *
886
- * @access private
887
- * @return void
888
- */
889
- private function plugin_deactivated() {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890
  }
891
 
892
  /**
1
  <?php
2
  /*
3
  Plugin Name: WP-Sweep
4
+ Plugin URI: https://lesterchan.net/portfolio/programming/php/
5
  Description: WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It cleans up revisions, auto drafts, unapproved comments, spam comments, trashed comments, orphan post meta, orphan comment meta, orphan user meta, orphan term relationships, unused terms, duplicated post meta, duplicated comment meta, duplicated user meta and transient options. It also optimizes your database tables.
6
+ Version: 1.0.10
7
  Author: Lester 'GaMerZ' Chan
8
+ Author URI: https://lesterchan.net
9
  Text Domain: wp-sweep
10
  License: GPL2
11
  */
12
 
13
+ /*
14
+ Copyright 2017 Lester Chan (email : lesterchan@gmail.com)
15
 
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License, version 2, as
18
+ published by the Free Software Foundation.
19
 
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
 
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
  */
29
 
30
  /**
32
  *
33
  * @since 1.0.0
34
  */
35
+ define( 'WP_SWEEP_VERSION', '1.0.10' );
36
 
37
  /**
38
  * WP-Sweep class
40
  * @since 1.0.0
41
  */
42
  class WPSweep {
43
+ /**
44
+ * Limit the number of items to show for sweep details
45
+ *
46
+ * @since 1.0.3
47
+ *
48
+ * @access public
49
+ * @var int
50
+ */
51
+ public $limit_details = 500;
52
+
53
+ /**
54
+ * Static instance
55
+ *
56
+ * @since 1.0.0
57
+ *
58
+ * @access private
59
+ * @var $instance
60
+ */
61
+ private static $instance;
62
+
63
+ /**
64
+ * Constructor method
65
+ *
66
+ * @since 1.0.0
67
+ *
68
+ * @access public
69
+ */
70
+ public function __construct() {
71
+ // Add Plugin Hooks
72
+ add_action( 'plugins_loaded', array( $this, 'add_hooks' ) );
73
+
74
+ // Load Translation
75
+ load_plugin_textdomain( 'wp-sweep' );
76
+
77
+ // Plugin Activation/Deactivation
78
+ register_activation_hook( __FILE__, array( $this, 'plugin_activation' ) );
79
+ register_deactivation_hook( __FILE__, array( $this, 'plugin_deactivation' ) );
80
+ }
81
+
82
+ /**
83
+ * Initializes the plugin object and returns its instance
84
+ *
85
+ * @since 1.0.0
86
+ *
87
+ * @access public
88
+ * @return object The plugin object instance
89
+ */
90
+ public static function get_instance() {
91
+ if ( ! isset( self::$instance ) ) {
92
+ self::$instance = new self();
93
+ }
94
+ return self::$instance;
95
+ }
96
+
97
+ /**
98
+ * Init this plugin
99
+ *
100
+ * @since 1.0.0
101
+ *
102
+ * @access public
103
+ * @return void
104
+ */
105
+ public function init() {
106
+ // include class for WP CLI command
107
+ if ( defined( 'WP_CLI' ) ) {
108
+ require __DIR__ . '/class-command.php';
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Adds all the plugin hooks
114
+ *
115
+ * @since 1.0.0
116
+ *
117
+ * @access public
118
+ * @return void
119
+ */
120
+ public function add_hooks() {
121
+ // Actions
122
+ add_action( 'init', array( $this, 'init' ) );
123
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
124
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
125
+ add_action( 'wp_ajax_sweep_details', array( $this, 'ajax_sweep_details' ) );
126
+ add_action( 'wp_ajax_sweep', array( $this, 'ajax_sweep' ) );
127
+ }
128
+
129
+ /**
130
+ * Enqueue JS/CSS files used for admin
131
+ *
132
+ * @since 1.0.3
133
+ *
134
+ * @access public
135
+ * @param string $hook
136
+ * @return void
137
+ */
138
+ public function admin_enqueue_scripts( $hook ) {
139
+ if ( 'wp-sweep/admin.php' !== $hook ) {
140
+ return;
141
+ }
142
+
143
+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
144
+ wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.js' ), array( 'jquery' ) , WP_SWEEP_VERSION, true );
145
+ } else {
146
+ wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.min.js' ), array( 'jquery' ) , WP_SWEEP_VERSION, true );
147
+ }
148
+
149
+ wp_localize_script( 'wp-sweep', 'wp_sweep', array(
150
+ 'text_close_warning' => __( 'Sweeping is in progress. If you leave now, the process won\'t be completed.', 'wp-sweep' ),
151
+ 'text_sweep' => __( 'Sweep', 'wp-sweep' ),
152
+ 'text_sweep_all' => __( 'Sweep All', 'wp-sweep' ),
153
+ 'text_sweeping' => __( 'Sweeping ...', 'wp-sweep' ),
154
+ 'text_na' => __( 'N/A', 'wp-sweep' ),
155
+ ) );
156
+ }
157
+
158
+ /**
159
+ * Admin menu
160
+ *
161
+ * @since 1.0.3
162
+ *
163
+ * @access public
164
+ * @return void
165
+ */
166
+ public function admin_menu() {
167
+ add_management_page( __( 'Sweep', 'wp-sweep' ), __( 'Sweep', 'wp-sweep' ), 'manage_options', 'wp-sweep/admin.php' );
168
+ }
169
+
170
+
171
+ /**
172
+ * Sweep Details loaded via AJAX
173
+ *
174
+ * @since 1.0.3
175
+ *
176
+ * @access public
177
+ * @return void
178
+ */
179
+ public function ajax_sweep_details() {
180
+ if ( ! empty( $_GET['action'] )
181
+ && 'sweep_details' === $_GET['action']
182
+ && ! empty( $_GET['sweep_name'] )
183
+ && ! empty( $_GET['sweep_type'] )
184
+ ) {
185
+ // Verify Referer
186
+ if ( ! check_admin_referer( 'wp_sweep_details_' . $_GET['sweep_name'] ) ) {
187
+ wp_send_json_error( array(
188
+ 'error' => __( 'Failed to verify referrer.', 'wp-sweep' ),
189
+ ) );
190
+ } else {
191
+ wp_send_json_success( $this->details( $_GET['sweep_name'] ) );
192
+ }
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Sweep via AJAX
198
+ *
199
+ * @since 1.0.3
200
+ *
201
+ * @access public
202
+ * @return void
203
+ */
204
+ public function ajax_sweep() {
205
+ if ( ! empty( $_GET['action'] )
206
+ && 'sweep' === $_GET['action']
207
+ && ! empty( $_GET['sweep_name'] )
208
+ && ! empty( $_GET['sweep_type'] )
209
+ ) {
210
+ // Verify Referer
211
+ if ( ! check_admin_referer( 'wp_sweep_' . $_GET['sweep_name'] ) ) {
212
+ wp_send_json_error( array(
213
+ 'error' => __( 'Failed to verify referrer.', 'wp-sweep' ),
214
+ ) );
215
+ } else {
216
+ $sweep = $this->sweep( $_GET['sweep_name'] );
217
+ $count = $this->count( $_GET['sweep_name'] );
218
+ $total_count = $this->total_count( $_GET['sweep_type'] );
219
+ $total_stats = array();
220
+ switch ( $_GET['sweep_type'] ) {
221
+ case 'posts':
222
+ case 'postmeta':
223
+ $total_stats = array( 'posts' => $this->total_count( 'posts' ), 'postmeta' => $this->total_count( 'postmeta' ) );
224
+ break;
225
+ case 'comments':
226
+ case 'commentmeta':
227
+ $total_stats = array( 'comments' => $this->total_count( 'comments' ), 'commentmeta' => $this->total_count( 'commentmeta' ) );
228
+ break;
229
+ case 'users':
230
+ case 'usermeta':
231
+ $total_stats = array( 'users' => $this->total_count( 'users' ), 'usermeta' => $this->total_count( 'usermeta' ) );
232
+ break;
233
+ case 'term_relationships':
234
+ case 'term_taxonomy':
235
+ case 'terms':
236
+ case 'termmeta':
237
+ $total_stats = array( 'term_relationships' => $this->total_count( 'term_relationships' ), 'term_taxonomy' => $this->total_count( 'term_taxonomy' ), 'terms' => $this->total_count( 'terms' ), 'termmeta' => $this->total_count( 'termmeta' ) );
238
+ break;
239
+ case 'options':
240
+ $total_stats = array( 'options' => $this->total_count( 'options' ) );
241
+ break;
242
+ case 'tables':
243
+ $total_stats = array( 'tables' => $this->total_count( 'tables' ) );
244
+ break;
245
+ }
246
+
247
+ wp_send_json_success( array(
248
+ 'sweep' => $sweep,
249
+ 'count' => $count,
250
+ 'total' => $total_count,
251
+ 'percentage' => $this->format_percentage( $count, $total_count ),
252
+ 'stats' => $total_stats,
253
+ ) );
254
+ }
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Count the number of total items belonging to each sweep
260
+ *
261
+ * @since 1.0.0
262
+ *
263
+ * @access public
264
+ * @param string $name
265
+ * @return int Number of items belonging to each sweep
266
+ */
267
+ public function total_count( $name ) {
268
+ global $wpdb;
269
+
270
+ $count = 0;
271
+
272
+ switch ( $name ) {
273
+ case 'posts':
274
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts" );
275
+ break;
276
+ case 'postmeta':
277
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta" );
278
+ break;
279
+ case 'comments':
280
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments" );
281
+ break;
282
+ case 'commentmeta':
283
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta" );
284
+ break;
285
+ case 'users':
286
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" );
287
+ break;
288
+ case 'usermeta':
289
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->usermeta" );
290
+ break;
291
+ case 'term_relationships':
292
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_relationships" );
293
+ break;
294
+ case 'term_taxonomy':
295
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_taxonomy" );
296
+ break;
297
+ case 'terms':
298
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->terms" );
299
+ break;
300
+ case 'termmeta':
301
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->termmeta" );
302
+ break;
303
+ case 'options':
304
+ $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->options" );
305
+ break;
306
+ case 'tables':
307
+ $count = sizeof( $wpdb->get_col( 'SHOW TABLES' ) );
308
+ break;
309
+ }
310
+
311
+ return apply_filters( 'wp_sweep_total_count', $count, $name );
312
+ }
313
+
314
+ /**
315
+ * Count the number of items belonging to each sweep
316
+ *
317
+ * @since 1.0.0
318
+ *
319
+ * @access public
320
+ * @param string $name
321
+ * @return int Number of items belonging to each sweep
322
+ */
323
+ public function count( $name ) {
324
+ global $wpdb;
325
+
326
+ $count = 0;
327
+
328
+ switch ( $name ) {
329
+ case 'revisions':
330
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = %s", 'revision' ) );
331
+ break;
332
+ case 'auto_drafts':
333
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = %s", 'auto-draft' ) );
334
+ break;
335
+ case 'deleted_posts':
336
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = %s", 'trash' ) );
337
+ break;
338
+ case 'unapproved_comments':
339
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = %s", '0' ) );
340
+ break;
341
+ case 'spam_comments':
342
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = %s", 'spam' ) );
343
+ break;
344
+ case 'deleted_comments':
345
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed' ) );
346
+ break;
347
+ case 'transient_options':
348
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(option_id) FROM $wpdb->options WHERE option_name LIKE(%s)", '%_transient_%' ) );
349
+ break;
350
+ case 'orphan_postmeta':
351
+ $count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)" );
352
+ break;
353
+ case 'orphan_commentmeta':
354
+ $count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)" );
355
+ break;
356
+ case 'orphan_usermeta':
357
+ $count = $wpdb->get_var( "SELECT COUNT(umeta_id) FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)" );
358
+ break;
359
+ case 'orphan_termmeta':
360
+ $count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
361
+ break;
362
+ case 'orphan_term_relationships':
363
+ $count = $wpdb->get_var( "SELECT COUNT(object_id) FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode( '\',\'', $this->get_excluded_taxonomies() ) . "') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" );
364
+ break;
365
+ case 'unused_terms':
366
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(t.term_id) FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ')', 0 ) );
367
+ break;
368
+ case 'duplicated_postmeta':
369
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1 ) );
370
+ if ( is_array( $query ) ) {
371
+ $count = array_sum( array_map( 'intval', $query ) );
372
+ }
373
+ break;
374
+ case 'duplicated_commentmeta':
375
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->commentmeta GROUP BY comment_id, meta_key, meta_value HAVING count > %d", 1 ) );
376
+ if ( is_array( $query ) ) {
377
+ $count = array_sum( array_map( 'intval', $query ) );
378
+ }
379
+ break;
380
+ case 'duplicated_usermeta':
381
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(umeta_id) AS count FROM $wpdb->usermeta GROUP BY user_id, meta_key, meta_value HAVING count > %d", 1 ) );
382
+ if ( is_array( $query ) ) {
383
+ $count = array_sum( array_map( 'intval', $query ) );
384
+ }
385
+ break;
386
+ case 'duplicated_termmeta':
387
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->termmeta GROUP BY term_id, meta_key, meta_value HAVING count > %d", 1 ) );
388
+ if ( is_array( $query ) ) {
389
+ $count = array_sum( array_map( 'intval', $query ) );
390
+ }
391
+ break;
392
+ case 'optimize_database':
393
+ $count = sizeof( $wpdb->get_col( 'SHOW TABLES' ) );
394
+ break;
395
+ case 'oembed_postmeta':
396
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_id) FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
397
+ break;
398
+ }
399
+
400
+ return apply_filters( 'wp_sweep_count', $count, $name );
401
+ }
402
+
403
+ /**
404
+ * Return more details about a sweep
405
+ *
406
+ * @since 1.0.3
407
+ *
408
+ * @access public
409
+ * @param string $name
410
+ * @return int Number of items belonging to each sweep
411
+ */
412
+ public function details( $name ) {
413
+ global $wpdb;
414
+
415
+ $details = array();
416
+
417
+ switch ( $name ) {
418
+ case 'revisions':
419
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_type = %s LIMIT %d", 'revision', $this->limit_details ) );
420
+ break;
421
+ case 'auto_drafts':
422
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_status = %s LIMIT %d", 'auto-draft', $this->limit_details ) );
423
+ break;
424
+ case 'deleted_posts':
425
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_status = %s LIMIT %d", 'trash', $this->limit_details ) );
426
+ break;
427
+ case 'unapproved_comments':
428
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT comment_author FROM $wpdb->comments WHERE comment_approved = %s LIMIT %d", '0', $this->limit_details ) );
429
+ break;
430
+ case 'spam_comments':
431
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT comment_author FROM $wpdb->comments WHERE comment_approved = %s LIMIT %d", 'spam', $this->limit_details ) );
432
+ break;
433
+ case 'deleted_comments':
434
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT comment_author FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s) LIMIT %d", 'trash', 'post-trashed', $this->limit_details ) );
435
+ break;
436
+ case 'transient_options':
437
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE(%s) LIMIT %d", '%_transient_%', $this->limit_details ) );
438
+ break;
439
+ case 'orphan_postmeta':
440
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts) LIMIT %d", $this->limit_details ) );
441
+ break;
442
+ case 'orphan_commentmeta':
443
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments) LIMIT %d", $this->limit_details ) );
444
+ break;
445
+ case 'orphan_usermeta':
446
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users) LIMIT %d", $this->limit_details ) );
447
+ break;
448
+ case 'orphan_termmeta':
449
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms) LIMIT %d", $this->limit_details ) );
450
+ break;
451
+ case 'orphan_term_relationships':
452
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode( '\',\'', $this->get_excluded_taxonomies() ) . "') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts) LIMIT %d", $this->limit_details ) );
453
+ break;
454
+ case 'unused_terms':
455
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ') LIMIT %d', 0, $this->limit_details ) );
456
+ break;
457
+ case 'duplicated_postmeta':
458
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(meta_id) AS count, meta_key FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
459
+ $details = array();
460
+ if ( $query ) {
461
+ foreach ( $query as $meta ) {
462
+ $details[] = $meta->meta_key;
463
+ }
464
+ }
465
+ break;
466
+ case 'duplicated_commentmeta':
467
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(meta_id) AS count, meta_key FROM $wpdb->commentmeta GROUP BY comment_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
468
+ $details = array();
469
+ if ( $query ) {
470
+ foreach ( $query as $meta ) {
471
+ $details[] = $meta->meta_key;
472
+ }
473
+ }
474
+ break;
475
+ case 'duplicated_usermeta':
476
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(umeta_id) AS count, meta_key FROM $wpdb->usermeta GROUP BY user_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
477
+ $details = array();
478
+ if ( $query ) {
479
+ foreach ( $query as $meta ) {
480
+ $details[] = $meta->meta_key;
481
+ }
482
+ }
483
+ break;
484
+ case 'duplicated_termmeta':
485
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT COUNT(meta_id) AS count, meta_key FROM $wpdb->termmeta GROUP BY term_id, meta_key, meta_value HAVING count > %d LIMIT %d", 1, $this->limit_details ) );
486
+ $details = array();
487
+ if ( $query ) {
488
+ foreach ( $query as $meta ) {
489
+ $details[] = $meta->meta_key;
490
+ }
491
+ }
492
+ break;
493
+ case 'optimize_database':
494
+ $details = $wpdb->get_col( 'SHOW TABLES' );
495
+ break;
496
+ case 'oembed_postmeta':
497
+ $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s) LIMIT %d", '%_oembed_%', $this->limit_details ) );
498
+ break;
499
+ }
500
+
501
+ return apply_filters( 'wp_sweep_details', $details, $name );
502
+ }
503
+
504
+ /**
505
+ * Does the sweeping/cleaning up
506
+ *
507
+ * @since 1.0.0
508
+ *
509
+ * @access public
510
+ * @param string $name
511
+ * @return string Processed message
512
+ */
513
+ public function sweep( $name ) {
514
+ global $wpdb;
515
+
516
+ $message = '';
517
+
518
+ switch ( $name ) {
519
+ case 'revisions':
520
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s", 'revision' ) );
521
+ if ( $query ) {
522
+ foreach ( $query as $id ) {
523
+ wp_delete_post_revision( intval( $id ) );
524
+ }
525
+
526
+ $message = sprintf( __( '%s Revisions Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
527
+ }
528
+ break;
529
+ case 'auto_drafts':
530
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s", 'auto-draft' ) );
531
+ if ( $query ) {
532
+ foreach ( $query as $id ) {
533
+ wp_delete_post( intval( $id ), true );
534
+ }
535
+
536
+ $message = sprintf( __( '%s Auto Drafts Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
537
+ }
538
+ break;
539
+ case 'deleted_posts':
540
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s", 'trash' ) );
541
+ if ( $query ) {
542
+ foreach ( $query as $id ) {
543
+ wp_delete_post( $id, true );
544
+ }
545
+
546
+ $message = sprintf( __( '%s Deleted Posts Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
547
+ }
548
+ break;
549
+ case 'unapproved_comments':
550
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", '0' ) );
551
+ if ( $query ) {
552
+ foreach ( $query as $id ) {
553
+ wp_delete_comment( intval( $id ), true );
554
+ }
555
+
556
+ $message = sprintf( __( '%s Unapproved Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
557
+ }
558
+ break;
559
+ case 'spam_comments':
560
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", 'spam' ) );
561
+ if ( $query ) {
562
+ foreach ( $query as $id ) {
563
+ wp_delete_comment( intval( $id ), true );
564
+ }
565
+
566
+ $message = sprintf( __( '%s Spam Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
567
+ }
568
+ break;
569
+ case 'deleted_comments':
570
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed' ) );
571
+ if ( $query ) {
572
+ foreach ( $query as $id ) {
573
+ wp_delete_comment( intval( $id ), true );
574
+ }
575
+
576
+ $message = sprintf( __( '%s Trash Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
577
+ }
578
+ break;
579
+ case 'transient_options':
580
+ $query = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE(%s)", '%_transient_%' ) );
581
+ if ( $query ) {
582
+ foreach ( $query as $option_name ) {
583
+ if ( strpos( $option_name, '_site_transient_' ) !== false ) {
584
+ delete_site_transient( str_replace( '_site_transient_', '', $option_name ) );
585
+ } else {
586
+ delete_transient( str_replace( '_transient_', '', $option_name ) );
587
+ }
588
+ }
589
+
590
+ $message = sprintf( __( '%s Transient Options Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
591
+ }
592
+ break;
593
+ case 'orphan_postmeta':
594
+ $query = $wpdb->get_results( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)" );
595
+ if ( $query ) {
596
+ foreach ( $query as $meta ) {
597
+ $post_id = intval( $meta->post_id );
598
+ if ( 0 === $post_id ) {
599
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
600
+ } else {
601
+ delete_post_meta( $post_id, $meta->meta_key );
602
+ }
603
+ }
604
+
605
+ $message = sprintf( __( '%s Orphaned Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
606
+ }
607
+ break;
608
+ case 'orphan_commentmeta':
609
+ $query = $wpdb->get_results( "SELECT comment_id, meta_key FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)" );
610
+ if ( $query ) {
611
+ foreach ( $query as $meta ) {
612
+ $comment_id = intval( $meta->comment_id );
613
+ if ( 0 === $comment_id ) {
614
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s", $comment_id, $meta->meta_key ) );
615
+ } else {
616
+ delete_comment_meta( $comment_id, $meta->meta_key );
617
+ }
618
+ }
619
+
620
+ $message = sprintf( __( '%s Orphaned Comment Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
621
+ }
622
+ break;
623
+ case 'orphan_usermeta':
624
+ $query = $wpdb->get_results( "SELECT user_id, meta_key FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)" );
625
+ if ( $query ) {
626
+ foreach ( $query as $meta ) {
627
+ $user_id = intval( $meta->user_id );
628
+ if ( 0 === $user_id ) {
629
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta->meta_key ) );
630
+ } else {
631
+ delete_user_meta( $user_id, $meta->meta_key );
632
+ }
633
+ }
634
+
635
+ $message = sprintf( __( '%s Orphaned User Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
636
+ }
637
+ break;
638
+ case 'orphan_termmeta':
639
+ $query = $wpdb->get_results( "SELECT term_id, meta_key FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
640
+ if ( $query ) {
641
+ foreach ( $query as $meta ) {
642
+ $term_id = intval( $meta->term_id );
643
+ if ( 0 === $term_id ) {
644
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE term_id = %d AND meta_key = %s", $term_id, $meta->meta_key ) );
645
+ } else {
646
+ delete_term_meta( $term_id, $meta->meta_key );
647
+ }
648
+ }
649
+
650
+ $message = sprintf( __( '%s Orphaned Term Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
651
+ }
652
+ break;
653
+ case 'orphan_term_relationships':
654
+ $query = $wpdb->get_results( "SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode( '\',\'', $this->get_excluded_taxonomies() ) . "') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" );
655
+ if ( $query ) {
656
+ foreach ( $query as $tax ) {
657
+ $wp_remove_object_terms = wp_remove_object_terms( intval( $tax->object_id ), intval( $tax->term_id ), $tax->taxonomy );
658
+ if ( true !== $wp_remove_object_terms ) {
659
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $tax->object_id, $tax->term_taxonomy_id ) );
660
+ }
661
+ }
662
+
663
+ $message = sprintf( __( '%s Orphaned Term Relationships Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
664
+ }
665
+ break;
666
+ case 'unused_terms':
667
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT tt.term_taxonomy_id, t.term_id, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ')', 0 ) );
668
+ if ( $query ) {
669
+ $check_wp_terms = false;
670
+ foreach ( $query as $tax ) {
671
+ if ( taxonomy_exists( $tax->taxonomy ) ) {
672
+ wp_delete_term( intval( $tax->term_id ), $tax->taxonomy );
673
+ } else {
674
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", intval( $tax->term_taxonomy_id ) ) );
675
+ $check_wp_terms = true;
676
+ }
677
+ }
678
+ // We need this for invalid taxonomies
679
+ if ( $check_wp_terms ) {
680
+ $wpdb->get_results( "DELETE FROM $wpdb->terms WHERE term_id NOT IN (SELECT term_id FROM $wpdb->term_taxonomy)" );
681
+ }
682
+
683
+ $message = sprintf( __( '%s Unused Terms Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
684
+ }
685
+ break;
686
+ case 'duplicated_postmeta':
687
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, post_id, COUNT(*) AS count FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1 ) );
688
+ if ( $query ) {
689
+ foreach ( $query as $meta ) {
690
+ $ids = array_map( 'intval', explode( ',', $meta->ids ) );
691
+ array_pop( $ids );
692
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND post_id = %d', intval( $meta->post_id ) ) );
693
+ }
694
+
695
+ $message = sprintf( __( '%s Duplicated Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
696
+ }
697
+ break;
698
+ case 'duplicated_commentmeta':
699
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, comment_id, COUNT(*) AS count FROM $wpdb->commentmeta GROUP BY comment_id, meta_key, meta_value HAVING count > %d", 1 ) );
700
+ if ( $query ) {
701
+ foreach ( $query as $meta ) {
702
+ $ids = array_map( 'intval', explode( ',', $meta->ids ) );
703
+ array_pop( $ids );
704
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND comment_id = %d', intval( $meta->comment_id ) ) );
705
+ }
706
+
707
+ $message = sprintf( __( '%s Duplicated Comment Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
708
+ }
709
+ break;
710
+ case 'duplicated_usermeta':
711
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT GROUP_CONCAT(umeta_id ORDER BY umeta_id DESC) AS ids, user_id, COUNT(*) AS count FROM $wpdb->usermeta GROUP BY user_id, meta_key, meta_value HAVING count > %d", 1 ) );
712
+ if ( $query ) {
713
+ foreach ( $query as $meta ) {
714
+ $ids = array_map( 'intval', explode( ',', $meta->ids ) );
715
+ array_pop( $ids );
716
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE umeta_id IN (" . implode( ',', $ids ) . ') AND user_id = %d', intval( $meta->user_id ) ) );
717
+ }
718
+
719
+ $message = sprintf( __( '%s Duplicated User Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
720
+ }
721
+ break;
722
+ case 'duplicated_termmeta':
723
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT GROUP_CONCAT(meta_id ORDER BY meta_id DESC) AS ids, term_id, COUNT(*) AS count FROM $wpdb->termmeta GROUP BY term_id, meta_key, meta_value HAVING count > %d", 1 ) );
724
+ if ( $query ) {
725
+ foreach ( $query as $meta ) {
726
+ $ids = array_map( 'intval', explode( ',', $meta->ids ) );
727
+ array_pop( $ids );
728
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND term_id = %d', intval( $meta->term_id ) ) );
729
+ }
730
+
731
+ $message = sprintf( __( '%s Duplicated Term Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
732
+ }
733
+ break;
734
+ case 'optimize_database':
735
+ $query = $wpdb->get_col( 'SHOW TABLES' );
736
+ if ( $query ) {
737
+ $tables = implode( ',', $query );
738
+ $wpdb->query( "OPTIMIZE TABLE $tables" );
739
+ $message = sprintf( __( '%s Tables Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
740
+ }
741
+ break;
742
+ case 'oembed_postmeta':
743
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
744
+ if ( $query ) {
745
+ foreach ( $query as $meta ) {
746
+ $post_id = intval( $meta->post_id );
747
+ if ( 0 === $post_id ) {
748
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
749
+ } else {
750
+ delete_post_meta( $post_id, $meta->meta_key );
751
+ }
752
+ }
753
+
754
+ $message = sprintf( __( '%s oEmbed Caches In Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
755
+ }
756
+ break;
757
+ }
758
+
759
+ return apply_filters( 'wp_sweep_sweep', $message, $name );
760
+ }
761
+
762
+ /**
763
+ * Format number to percentage, taking care of division by 0.
764
+ * Props @barisunver https://github.com/barisunver
765
+ *
766
+ * @since 1.0.2
767
+ *
768
+ * @access public
769
+ * @param int $current
770
+ * @param int $total
771
+ * @return string Number in percentage
772
+ */
773
+ public function format_percentage( $current, $total ) {
774
+ return ( $total > 0 ? round( ( $current / $total ) * 100, 2 ) : 0 ) . '%';
775
+ }
776
+
777
+ /**
778
+ * Get excluded taxonomies
779
+ *
780
+ * @since 1.0.8
781
+ *
782
+ * @access private
783
+ * @return array Excluded taxonomies
784
+ */
785
+ private function get_excluded_taxonomies() {
786
+ $excluded_taxonomies = array();
787
+ $excluded_taxonomies[] = 'link_category';
788
+
789
+ return apply_filters( 'wp_sweep_excluded_taxonomies', $excluded_taxonomies );
790
+ }
791
+
792
+ /**
793
+ * Get excluded term IDs
794
+ *
795
+ * @since 1.0.3
796
+ *
797
+ * @access private
798
+ * @return array Excluded term IDs
799
+ */
800
+ private function get_excluded_termids() {
801
+ $default_term_ids = $this->get_default_taxonomy_termids();
802
+ if ( ! is_array( $default_term_ids ) ) {
803
+ $default_term_ids = array();
804
+ }
805
+ $parent_term_ids = $this->get_parent_termids();
806
+ if ( ! is_array( $parent_term_ids ) ) {
807
+ $parent_term_ids = array();
808
+ }
809
+ return array_merge( $default_term_ids, $parent_term_ids );
810
+ }
811
+
812
+ /**
813
+ * Get all default taxonomy term IDs
814
+ *
815
+ * @since 1.0.3
816
+ *
817
+ * @access private
818
+ * @return array Default taxonomy term IDs
819
+ */
820
+ private function get_default_taxonomy_termids() {
821
+ $taxonomies = get_taxonomies();
822
+ $default_term_ids = array();
823
+ if ( $taxonomies ) {
824
+ $tax = array_keys( $taxonomies );
825
+ if ( $tax ) {
826
+ foreach ( $tax as $t ) {
827
+ $term_id = intval( get_option( 'default_' . $t ) );
828
+ if ( $term_id > 0 ) {
829
+ $default_term_ids[] = $term_id;
830
+ }
831
+ }
832
+ }
833
+ }
834
+ return $default_term_ids;
835
+ }
836
+
837
+ /**
838
+ * Get terms that has a parent term
839
+ *
840
+ * @since 1.0.3
841
+ *
842
+ * @access private
843
+ * @return array Parent term IDs
844
+ */
845
+ private function get_parent_termids() {
846
+ global $wpdb;
847
+ return $wpdb->get_col( $wpdb->prepare( "SELECT tt.parent FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.parent > %d", 0 ) );
848
+ }
849
+
850
+ /**
851
+ * Wrapper to get WordPress Multisite
852
+ *
853
+ * @since 1.0.9
854
+ *
855
+ * @access private
856
+ * @return array
857
+ */
858
+ private function get_sites() {
859
+ return function_exists( 'get_sites' ) ? get_sites() : wp_get_sites();
860
+ }
861
+
862
+ /**
863
+ * Wrapper to get WordPress Multisite ID
864
+ *
865
+ * @since 1.0.9
866
+ *
867
+ * @access private
868
+ * @param WP_Site $ms_site
869
+ * @return int
870
+ */
871
+ private function get_site_blog_id( $ms_site ) {
872
+ return class_exists( 'WP_Site' ) ? $ms_site->blog_id : $ms_site['blog_id'];
873
+ }
874
+
875
+ /**
876
+ * What to do when the plugin is being deactivated
877
+ *
878
+ * @since 1.0.0
879
+ *
880
+ * @access public
881
+ * @param boolean $network_wide
882
+ * @return void
883
+ */
884
+ public function plugin_activation( $network_wide ) {
885
+ if ( is_multisite() && $network_wide ) {
886
+ $ms_sites = $this->get_sites();
887
+
888
+ if ( 0 < sizeof( $ms_sites ) ) {
889
+ foreach ( $ms_sites as $ms_site ) {
890
+ switch_to_blog( $this->get_site_blog_id( $ms_site ) );
891
+ $this->plugin_activated();
892
+ restore_current_blog();
893
+ }
894
+ }
895
+ } else {
896
+ $this->plugin_activated();
897
+ }
898
+ }
899
+
900
+ /**
901
+ * Perform plugin activation tasks
902
+ *
903
+ * @since 1.0.0
904
+ *
905
+ * @access private
906
+ * @return void
907
+ */
908
+ private function plugin_activated() {
909
+ }
910
+
911
+ /**
912
+ * What to do when the plugin is being activated
913
+ *
914
+ * @since 1.0.0
915
+ *
916
+ * @access public
917
+ * @param boolean $network_wide
918
+ * @return void
919
+ */
920
+ public function plugin_deactivation( $network_wide ) {
921
+ if ( is_multisite() && $network_wide ) {
922
+ $ms_sites = $this->get_sites();
923
+
924
+ if ( 0 < sizeof( $ms_sites ) ) {
925
+ foreach ( $ms_sites as $ms_site ) {
926
+ switch_to_blog( $this->get_site_blog_id( $ms_site ) );
927
+ $this->plugin_deactivated();
928
+ restore_current_blog();
929
+ }
930
+ }
931
+ } else {
932
+ $this->plugin_deactivated();
933
+ }
934
+ }
935
+
936
+ /**
937
+ * Perform plugin deactivation tasks
938
+ *
939
+ * @since 1.0.0
940
+ *
941
+ * @access private
942
+ * @return void
943
+ */
944
+ private function plugin_deactivated() {
945
+ }
946
  }
947
 
948
  /**