WP-Sweep - Version 1.0.6

Version Description

  • NEW: Delete 'languages' folder from the plugin
  • NEW: Use translate.wordpress.org to translate the plugin
  • FIXED: Works only with WordPress 4.4 because of new term meta
Download this release

Release Info

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

Code changes from version 1.0.5 to 1.0.6

Files changed (5) hide show
  1. admin.php +512 -469
  2. composer.json +9 -3
  3. languages/wp-sweep.pot +0 -321
  4. readme.txt +11 -3
  5. wp-sweep.php +850 -799
admin.php CHANGED
@@ -8,9 +8,9 @@ $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
@@ -23,6 +23,7 @@ $total_usermeta = WPSweep::get_instance()->total_count( 'usermeta' )
23
  $total_term_relationships = WPSweep::get_instance()->total_count( 'term_relationships' );
24
  $total_term_taxonomy = WPSweep::get_instance()->total_count( 'term_taxonomy' );
25
  $total_terms = WPSweep::get_instance()->total_count( 'terms' );
 
26
  $total_options = WPSweep::get_instance()->total_count( 'options' );
27
  $total_tables = WPSweep::get_instance()->total_count( 'tables' );
28
 
@@ -45,476 +46,518 @@ $duplicated_usermeta = WPSweep::get_instance()->count( 'duplicated_userme
45
 
46
  $orphan_term_relationships = WPSweep::get_instance()->count( 'orphan_term_relationships' );
47
  $unused_terms = WPSweep::get_instance()->count( 'unused_terms' );
 
 
48
 
49
  $transient_options = WPSweep::get_instance()->count( 'transient_options' );
50
  ?>
51
  <style type="text/css">
52
- .table-sweep thead th {
53
- width: 12%;
54
- }
55
- .table-sweep thead th.col-sweep-details {
56
- width: 56%;
57
- }
58
- .table-sweep thead th.col-sweep-action {
59
- width: 20%;
60
- }
61
  </style>
62
  <div class="wrap">
63
- <h2><?php _e( 'WP-Sweep', 'wp-sweep' ); ?></h2>
64
- <div class="update-nag">
65
- <?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' ); ?>
66
- </div>
67
- <p>
68
- <?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 ) ); ?>
69
- </p>
70
- <h3><?php _e( 'Post Sweep', 'wp-sweep' ); ?></h3>
71
- <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>
72
- <div class="sweep-message"></div>
73
- <table class="widefat table-sweep">
74
- <thead>
75
- <tr>
76
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
77
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
78
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
79
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
80
- </tr>
81
- </thead>
82
- <tbody>
83
- <tr>
84
- <td>
85
- <strong><?php _e( 'Revisions', 'wp-sweep' ); ?></strong>
86
- <p class="sweep-details" style="display: none;"></p>
87
- </td>
88
- <td>
89
- <span class="sweep-count"><?php echo number_format_i18n( $revisions ); ?></span>
90
- </td>
91
- <td>
92
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $revisions, $total_posts ); ?></span>
93
- </td>
94
- <td>
95
- <?php if( ! empty( $revisions ) ): ?>
96
- <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>
97
- <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>
98
- <?php else: ?>
99
- <?php _e( 'N/A', 'wp-sweep' ); ?>
100
- <?php endif; ?>
101
- </td>
102
- </tr>
103
- <tr class="alternate">
104
- <td>
105
- <strong><?php _e( 'Auto Drafts', 'wp-sweep' ); ?></strong>
106
- <p class="sweep-details" style="display: none;"></p>
107
- </td>
108
- <td>
109
- <span class="sweep-count"><?php echo number_format_i18n( $auto_drafts ); ?></span>
110
- </td>
111
- <td>
112
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $auto_drafts, $total_posts ); ?></span>
113
- </td>
114
- <td>
115
- <?php if( ! empty( $auto_drafts ) ): ?>
116
- <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>
117
- <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>
118
- <?php else: ?>
119
- <?php _e( 'N/A', 'wp-sweep' ); ?>
120
- <?php endif; ?>
121
- </td>
122
- </tr>
123
- <tr>
124
- <td>
125
- <strong><?php _e( 'Deleted Posts', 'wp-sweep' ); ?></strong>
126
- <p class="sweep-details" style="display: none;"></p>
127
- </td>
128
- <td>
129
- <span class="sweep-count"><?php echo number_format_i18n( $deleted_posts ); ?></span>
130
- </td>
131
- <td>
132
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $deleted_posts, $total_posts ); ?></span>
133
- </td>
134
- <td>
135
- <?php if( ! empty( $deleted_posts ) ): ?>
136
- <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>
137
- <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>
138
- <?php else: ?>
139
- <?php _e( 'N/A', 'wp-sweep' ); ?>
140
- <?php endif; ?>
141
- </td>
142
- </tr>
143
- <tr class="alternate">
144
- <td>
145
- <strong><?php _e( 'Orphaned Post Meta', 'wp-sweep' ); ?></strong>
146
- <p class="sweep-details" style="display: none;"></p>
147
- </td>
148
- <td>
149
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_postmeta ); ?></span>
150
- </td>
151
- <td>
152
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_postmeta, $total_postmeta ); ?></span>
153
- </td>
154
- <td>
155
- <?php if( ! empty( $orphan_postmeta ) ): ?>
156
- <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>
157
- <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>
158
- <?php else: ?>
159
- <?php _e( 'N/A', 'wp-sweep' ); ?>
160
- <?php endif; ?>
161
- </td>
162
- </tr>
163
- <tr>
164
- <td>
165
- <strong><?php _e( 'Duplicated Post Meta', 'wp-sweep' ); ?></strong>
166
- <p class="sweep-details" style="display: none;"></p>
167
- </td>
168
- <td>
169
- <span class="sweep-count"><?php echo number_format_i18n( $duplicated_postmeta ); ?></span>
170
- </td>
171
- <td>
172
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_postmeta, $total_postmeta ); ?></span>
173
- </td>
174
- <td>
175
- <?php if( ! empty( $duplicated_postmeta ) ): ?>
176
- <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>
177
- <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>
178
- <?php else: ?>
179
- <?php _e( 'N/A', 'wp-sweep' ); ?>
180
- <?php endif; ?>
181
- </td>
182
- </tr>
183
- <tr class="alternate">
184
- <td>
185
- <strong><?php _e( 'oEmbed Caches In Post Meta', 'wp-sweep' ); ?></strong>
186
- <p class="sweep-details" style="display: none;"></p>
187
- </td>
188
- <td>
189
- <span class="sweep-count"><?php echo number_format_i18n( $oembed_postmeta ); ?></span>
190
- </td>
191
- <td>
192
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $oembed_postmeta, $total_postmeta ); ?></span>
193
- </td>
194
- <td>
195
- <?php if( ! empty( $oembed_postmeta ) ): ?>
196
- <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>
197
- <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>
198
- <?php else: ?>
199
- <?php _e( 'N/A', 'wp-sweep' ); ?>
200
- <?php endif; ?>
201
- </td>
202
- </tr>
203
- </tbody>
204
- </table>
205
- <?php do_action( 'wp_sweep_admin_post_sweep' ); ?>
206
- <p>&nbsp;</p>
207
- <h3><?php _e( 'Comment Sweep', 'wp-sweep' ); ?></h3>
208
- <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>
209
- <div class="sweep-message"></div>
210
- <table class="widefat table-sweep">
211
- <thead>
212
- <tr>
213
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
214
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
215
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
216
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
217
- </tr>
218
- </thead>
219
- <tbody>
220
- <tr>
221
- <td>
222
- <strong><?php _e( 'Unapproved Comments', 'wp-sweep' ); ?></strong>
223
- <p class="sweep-details" style="display: none;"></p>
224
- </td>
225
- <td>
226
- <span class="sweep-count"><?php echo number_format_i18n( $unapproved_comments ); ?></span>
227
- </td>
228
- <td>
229
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $unapproved_comments, $total_comments ); ?></span>
230
- </td>
231
- <td>
232
- <?php if( ! empty( $unapproved_comments ) ): ?>
233
- <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>
234
- <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>
235
- <?php else: ?>
236
- <?php _e( 'N/A', 'wp-sweep' ); ?>
237
- <?php endif; ?>
238
- </td>
239
- </tr>
240
- <tr class="alternate">
241
- <td>
242
- <strong><?php _e( 'Spammed Comments', 'wp-sweep' ); ?></strong>
243
- <p class="sweep-details" style="display: none;"></p>
244
- </td>
245
- <td>
246
- <span class="sweep-count"><?php echo number_format_i18n( $spam_comments ); ?></span>
247
- </td>
248
- <td>
249
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $spam_comments, $total_comments ); ?></span>
250
- </td>
251
- <td>
252
- <?php if( ! empty( $spam_comments ) ): ?>
253
- <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>
254
- <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>
255
- <?php else: ?>
256
- <?php _e( 'N/A', 'wp-sweep' ); ?>
257
- <?php endif; ?>
258
- </td>
259
- </tr>
260
- <tr>
261
- <td>
262
- <strong><?php _e( 'Deleted Comments', 'wp-sweep' ); ?></strong>
263
- <p class="sweep-details" style="display: none;"></p>
264
- </td>
265
- <td>
266
- <span class="sweep-count"><?php echo number_format_i18n( $deleted_comments ); ?></span>
267
- </td>
268
- <td>
269
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $deleted_comments, $total_comments ); ?></span>
270
- </td>
271
- <td>
272
- <?php if( ! empty( $deleted_comments ) ): ?>
273
- <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>
274
- <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>
275
- <?php else: ?>
276
- <?php _e( 'N/A', 'wp-sweep' ); ?>
277
- <?php endif; ?>
278
- </td>
279
- </tr>
280
- <tr class="alternate">
281
- <td>
282
- <strong><?php _e( 'Orphaned Comment Meta', 'wp-sweep' ); ?></strong>
283
- <p class="sweep-details" style="display: none;"></p>
284
- </td>
285
- <td>
286
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_commentmeta ); ?></span>
287
- </td>
288
- <td>
289
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_commentmeta, $total_commentmeta ); ?></span>
290
- </td>
291
- <td>
292
- <?php if( ! empty( $orphan_commentmeta ) ): ?>
293
- <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>
294
- <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>
295
- <?php else: ?>
296
- <?php _e( 'N/A', 'wp-sweep' ); ?>
297
- <?php endif; ?>
298
- </td>
299
- </tr>
300
- <tr>
301
- <td>
302
- <strong><?php _e( 'Duplicated Comment Meta', 'wp-sweep' ); ?></strong>
303
- <p class="sweep-details" style="display: none;"></p>
304
- </td>
305
- <td>
306
- <span class="sweep-count"><?php echo number_format_i18n( $duplicated_commentmeta ); ?></span>
307
- </td>
308
- <td>
309
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_commentmeta, $total_commentmeta ); ?></span>
310
- </td>
311
- <td>
312
- <?php if( ! empty( $duplicated_commentmeta ) ): ?>
313
- <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>
314
- <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>
315
- <?php else: ?>
316
- <?php _e( 'N/A', 'wp-sweep' ); ?>
317
- <?php endif; ?>
318
- </td>
319
- </tr>
320
- </tbody>
321
- </table>
322
- <?php do_action( 'wp_sweep_admin_comment_sweep' ); ?>
323
- <p>&nbsp;</p>
324
- <h3><?php _e( 'User Sweep', 'wp-sweep' ); ?></h3>
325
- <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>
326
- <div class="sweep-message"></div>
327
- <table class="widefat table-sweep">
328
- <thead>
329
- <tr>
330
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
331
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
332
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
333
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
334
- </tr>
335
- </thead>
336
- <tbody>
337
- <tr>
338
- <td>
339
- <strong><?php _e( 'Orphaned User Meta', 'wp-sweep' ); ?></strong>
340
- <p class="sweep-details" style="display: none;"></p>
341
- </td>
342
- <td>
343
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_usermeta ); ?></span>
344
- </td>
345
- <td>
346
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_usermeta, $total_usermeta ); ?></span>
347
- </td>
348
- <td>
349
- <?php if( ! empty( $orphan_usermeta ) ): ?>
350
- <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>
351
- <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>
352
- <?php else: ?>
353
- <?php _e( 'N/A', 'wp-sweep' ); ?>
354
- <?php endif; ?>
355
- </td>
356
- </tr>
357
- <tr class="alternate">
358
- <td>
359
- <strong><?php _e( 'Duplicated User Meta', 'wp-sweep' ); ?></strong>
360
- <p class="sweep-details" style="display: none;"></p>
361
- </td>
362
- <td>
363
- <span class="sweep-count"><?php echo number_format_i18n( $duplicated_usermeta ); ?></span>
364
- </td>
365
- <td>
366
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_usermeta, $total_usermeta ); ?></span>
367
- </td>
368
- <td>
369
- <?php if( ! empty( $duplicated_usermeta ) ): ?>
370
- <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>
371
- <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>
372
- <?php else: ?>
373
- <?php _e( 'N/A', 'wp-sweep' ); ?>
374
- <?php endif; ?>
375
- </td>
376
- </tr>
377
- </tbody>
378
- </table>
379
- <?php do_action( 'wp_sweep_admin_user_sweep' ); ?>
380
- <p>&nbsp;</p>
381
- <h3><?php _e( 'Term Sweep', 'wp-sweep' ); ?></h3>
382
- <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-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_term_taxonomy ), number_format_i18n( $total_term_relationships ) ); ?></p>
383
- <div class="sweep-message"></div>
384
- <table class="widefat table-sweep">
385
- <thead>
386
- <tr>
387
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
388
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
389
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
390
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
391
- </tr>
392
- </thead>
393
- <tbody>
394
- <tr>
395
- <td>
396
- <strong><?php _e( 'Orphaned Term Relationship', 'wp-sweep' ); ?></strong>
397
- <p class="sweep-details" style="display: none;"></p>
398
- </td>
399
- <td>
400
- <span class="sweep-count"><?php echo number_format_i18n( $orphan_term_relationships ); ?></span>
401
- </td>
402
- <td>
403
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_term_relationships, $total_term_relationships ); ?></span>
404
- </td>
405
- <td>
406
- <?php if( ! empty( $orphan_term_relationships ) ): ?>
407
- <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>
408
- <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>
409
- <?php else: ?>
410
- <?php _e( 'N/A', 'wp-sweep' ); ?>
411
- <?php endif; ?>
412
- </td>
413
- </tr>
414
- <tr class="alternate">
415
- <td>
416
- <strong><?php _e( 'Unused Terms', 'wp-sweep' ); ?></strong>
417
- <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>
418
- <p class="sweep-details" style="display: none;"></p>
419
- </td>
420
- <td>
421
- <span class="sweep-count"><?php echo number_format_i18n( $unused_terms ); ?></span>
422
- </td>
423
- <td>
424
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $unused_terms, $total_terms ); ?></span>
425
- </td>
426
- <td>
427
- <?php if( ! empty( $unused_terms ) ): ?>
428
- <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>
429
- <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>
430
- <?php else: ?>
431
- <?php _e( 'N/A', 'wp-sweep' ); ?>
432
- <?php endif; ?>
433
- </td>
434
- </tr>
435
- </tbody>
436
- </table>
437
- <?php do_action( 'wp_sweep_admin_term_sweep' ); ?>
438
- <p>&nbsp;</p>
439
- <h3><?php _e( 'Option Sweep', 'wp-sweep' ); ?></h3>
440
- <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>
441
- <div class="sweep-message"></div>
442
- <table class="widefat table-sweep">
443
- <thead>
444
- <tr>
445
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
446
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
447
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
448
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
449
- </tr>
450
- </thead>
451
- <tbody>
452
- <tr>
453
- <td>
454
- <strong><?php _e( 'Transient Options', 'wp-sweep' ); ?></strong>
455
- <p class="sweep-details" style="display: none;"></p>
456
- </td>
457
- <td>
458
- <span class="sweep-count"><?php echo number_format_i18n( $transient_options ); ?></span>
459
- </td>
460
- <td>
461
- <span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $transient_options, $total_options ); ?></span>
462
- </td>
463
- <td>
464
- <?php if( ! empty( $transient_options ) ): ?>
465
- <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>
466
- <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>
467
- <?php else: ?>
468
- <?php _e( 'N/A', 'wp-sweep' ); ?>
469
- <?php endif; ?>
470
- </td>
471
- </tr>
472
- </tbody>
473
- </table>
474
- <?php do_action( 'wp_sweep_admin_option_sweep' ); ?>
475
- <p>&nbsp;</p>
476
- <h3><?php _e( 'Database Sweep', 'wp-sweep' ); ?></h3>
477
- <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>
478
- <div class="sweep-message"></div>
479
- <table class="widefat table-sweep">
480
- <thead>
481
- <tr>
482
- <th class="col-sweep-details"><?php _e( 'Details', 'wp-sweep' ); ?></th>
483
- <th class="col-sweep-count"><?php _e( 'Count', 'wp-sweep' ); ?></th>
484
- <th class="col-sweep-percent"><?php _e( '% Of', 'wp-sweep' ); ?></th>
485
- <th class="col-sweep-action"><?php _e( 'Action', 'wp-sweep' ); ?></th>
486
- </tr>
487
- </thead>
488
- <tbody>
489
- <tr>
490
- <td>
491
- <strong><?php _e( 'Optimize Tables', 'wp-sweep' ); ?></strong>
492
- <p class="sweep-details" style="display: none;"></p>
493
- </td>
494
- <td>
495
- <span class="sweep-count"><?php echo number_format_i18n( $total_tables ); ?></span>
496
- </td>
497
- <td>
498
- <?php _e( 'N/A', 'wp-sweep' ); ?>
499
- </td>
500
- <td>
501
- <?php if( ! empty( $total_tables ) ): ?>
502
- <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>
503
- <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>
504
- <?php else: ?>
505
- <?php _e( 'N/A', 'wp-sweep' ); ?>
506
- <?php endif; ?>
507
- </td>
508
- </tr>
509
- </tbody>
510
- </table>
511
- <?php do_action( 'wp_sweep_admin_database_sweep' ); ?>
512
- <p>&nbsp;</p>
513
- <h3><?php _e( 'Sweep All', 'wp-sweep' ); ?></h3>
514
- <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>
515
- <div class="sweep-all">
516
- <p style="text-align: center;">
517
- <button class="button button-primary btn-sweep-all"><?php _e( 'Sweep All', 'wp-sweep' ); ?></button>
518
- </p>
519
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
520
  </div>
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
23
  $total_term_relationships = WPSweep::get_instance()->total_count( 'term_relationships' );
24
  $total_term_taxonomy = WPSweep::get_instance()->total_count( 'term_taxonomy' );
25
  $total_terms = WPSweep::get_instance()->total_count( 'terms' );
26
+ $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
 
46
 
47
  $orphan_term_relationships = WPSweep::get_instance()->count( 'orphan_term_relationships' );
48
  $unused_terms = WPSweep::get_instance()->count( 'unused_terms' );
49
+ $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>
composer.json CHANGED
@@ -1,10 +1,16 @@
1
  {
2
- "name": "wp-sweep/plugin",
3
  "description": "WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It also optimizes your database tables.",
4
  "keywords": ["wordpress", "plugin", "wp-sweep", "sweep"],
5
- "homepage": "https://wordpress.org/plugins/wp-sweep/",
6
  "type": "wordpress-plugin",
7
- "license" : "GPL-2.0+",
 
 
 
 
 
 
 
8
  "require": {
9
  "php": ">=5.3.2",
10
  "composer/installers": "~1.0"
1
  {
2
+ "name": "lesterchan/wp-sweep",
3
  "description": "WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It also optimizes your database tables.",
4
  "keywords": ["wordpress", "plugin", "wp-sweep", "sweep"],
 
5
  "type": "wordpress-plugin",
6
+ "homepage": "https://wordpress.org/plugins/wp-sweep/",
7
+ "authors": [
8
+ {
9
+ "name": "Lester Chan",
10
+ "email": "lesterchan@gmail.com"
11
+ }
12
+ ],
13
+ "license" : "GPL-2.0+",
14
  "require": {
15
  "php": ">=5.3.2",
16
  "composer/installers": "~1.0"
languages/wp-sweep.pot DELETED
@@ -1,321 +0,0 @@
1
- # Copyright (C) 2015 WP-Sweep
2
- # This file is distributed under the same license as the WP-Sweep package.
3
- msgid ""
4
- msgstr ""
5
- "Project-Id-Version: WP-Sweep 1.0.5\n"
6
- "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/wp-sweep\n"
7
- "POT-Creation-Date: 2015-04-23 07:55:55+00:00\n"
8
- "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=UTF-8\n"
10
- "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
12
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
- "Language-Team: LANGUAGE <LL@li.org>\n"
14
-
15
- #. #-#-#-#-# plugin.pot (WP-Sweep 1.0.5) #-#-#-#-#
16
- #. Plugin Name of the plugin/theme
17
- #: admin.php:63
18
- msgid "WP-Sweep"
19
- msgstr ""
20
-
21
- #: admin.php:65
22
- msgid ""
23
- "Before you do any sweep, please <a href=\"%s\" target=\"%s\">backup your "
24
- "database</a> first because any sweep done is irreversible."
25
- msgstr ""
26
-
27
- #: admin.php:68
28
- msgid ""
29
- "For performance reasons, only %s items will be shown if you click Details"
30
- msgstr ""
31
-
32
- #: admin.php:70
33
- msgid "Post Sweep"
34
- msgstr ""
35
-
36
- #: admin.php:71
37
- msgid ""
38
- "There are a total of <strong class=\"attention\"><span class=\"sweep-count-"
39
- "type-posts\">%s</span> Posts</strong> and <strong class=\"attention\"><span "
40
- "class=\"sweep-count-type-postmeta\">%s</span> Post Meta</strong>."
41
- msgstr ""
42
-
43
- #: admin.php:76 admin.php:97 admin.php:117 admin.php:137 admin.php:157
44
- #: admin.php:177 admin.php:197 admin.php:213 admin.php:234 admin.php:254
45
- #: admin.php:274 admin.php:294 admin.php:314 admin.php:330 admin.php:351
46
- #: admin.php:371 admin.php:387 admin.php:408 admin.php:429 admin.php:445
47
- #: admin.php:466 admin.php:482 admin.php:503
48
- msgid "Details"
49
- msgstr ""
50
-
51
- #: admin.php:77 admin.php:214 admin.php:331 admin.php:388 admin.php:446
52
- #: admin.php:483
53
- msgid "Count"
54
- msgstr ""
55
-
56
- #: admin.php:78 admin.php:215 admin.php:332 admin.php:389 admin.php:447
57
- #: admin.php:484
58
- msgid "% Of"
59
- msgstr ""
60
-
61
- #: admin.php:79 admin.php:216 admin.php:333 admin.php:390 admin.php:448
62
- #: admin.php:485
63
- msgid "Action"
64
- msgstr ""
65
-
66
- #: admin.php:85
67
- msgid "Revisions"
68
- msgstr ""
69
-
70
- #: admin.php:96 admin.php:116 admin.php:136 admin.php:156 admin.php:176
71
- #: admin.php:196 admin.php:233 admin.php:253 admin.php:273 admin.php:293
72
- #: admin.php:313 admin.php:350 admin.php:370 admin.php:407 admin.php:428
73
- #: admin.php:465 admin.php:502 wp-sweep.php:146 wp-sweep.php:162
74
- msgid "Sweep"
75
- msgstr ""
76
-
77
- #: admin.php:99 admin.php:119 admin.php:139 admin.php:159 admin.php:179
78
- #: admin.php:199 admin.php:236 admin.php:256 admin.php:276 admin.php:296
79
- #: admin.php:316 admin.php:353 admin.php:373 admin.php:410 admin.php:431
80
- #: admin.php:468 admin.php:498 admin.php:505 wp-sweep.php:149
81
- msgid "N/A"
82
- msgstr ""
83
-
84
- #: admin.php:105
85
- msgid "Auto Drafts"
86
- msgstr ""
87
-
88
- #: admin.php:125
89
- msgid "Deleted Posts"
90
- msgstr ""
91
-
92
- #: admin.php:145
93
- msgid "Orphaned Post Meta"
94
- msgstr ""
95
-
96
- #: admin.php:165
97
- msgid "Duplicated Post Meta"
98
- msgstr ""
99
-
100
- #: admin.php:185
101
- msgid "oEmbed Caches In Post Meta"
102
- msgstr ""
103
-
104
- #: admin.php:207
105
- msgid "Comment Sweep"
106
- msgstr ""
107
-
108
- #: admin.php:208
109
- msgid ""
110
- "There are a total of <strong class=\"attention\"><span class=\"sweep-count-"
111
- "type-comments\">%s</span> Comments</strong> and <strong class=\"attention"
112
- "\"><span class=\"sweep-count-type-commentmeta\">%s</span> Comment Meta</"
113
- "strong>."
114
- msgstr ""
115
-
116
- #: admin.php:222
117
- msgid "Unapproved Comments"
118
- msgstr ""
119
-
120
- #: admin.php:242
121
- msgid "Spammed Comments"
122
- msgstr ""
123
-
124
- #: admin.php:262
125
- msgid "Deleted Comments"
126
- msgstr ""
127
-
128
- #: admin.php:282
129
- msgid "Orphaned Comment Meta"
130
- msgstr ""
131
-
132
- #: admin.php:302
133
- msgid "Duplicated Comment Meta"
134
- msgstr ""
135
-
136
- #: admin.php:324
137
- msgid "User Sweep"
138
- msgstr ""
139
-
140
- #: admin.php:325
141
- msgid ""
142
- "There are a total of <strong class=\"attention\"><span class=\"sweep-count-"
143
- "type-users\">%s</span> Users</strong> and <strong class=\"attention\"><span "
144
- "class=\"sweep-count-type-usermeta\">%s</span> User Meta</strong>."
145
- msgstr ""
146
-
147
- #: admin.php:339
148
- msgid "Orphaned User Meta"
149
- msgstr ""
150
-
151
- #: admin.php:359
152
- msgid "Duplicated User Meta"
153
- msgstr ""
154
-
155
- #: admin.php:381
156
- msgid "Term Sweep"
157
- msgstr ""
158
-
159
- #: admin.php:382
160
- msgid ""
161
- "There are a total of <strong class=\"attention \"><span class=\"sweep-count-"
162
- "type-terms\">%s</span> Terms</strong>, <strong class=\"attention\"><span "
163
- "class=\"sweep-count-type-term_taxonomy\">%s</span> Term Taxonomy</strong> "
164
- "and <strong class=\"attention\"><span class=\"sweep-count-type-"
165
- "term_relationships\">%s</span> Term Relationships</strong>."
166
- msgstr ""
167
-
168
- #: admin.php:396
169
- msgid "Orphaned Term Relationship"
170
- msgstr ""
171
-
172
- #: admin.php:416
173
- msgid "Unused Terms"
174
- msgstr ""
175
-
176
- #: admin.php:417
177
- msgid ""
178
- "Note that some unused terms might belong to draft posts that have not been "
179
- "published yet. Only sweep this when you do not have any draft posts."
180
- msgstr ""
181
-
182
- #: admin.php:439
183
- msgid "Option Sweep"
184
- msgstr ""
185
-
186
- #: admin.php:440
187
- msgid ""
188
- "There are a total of <strong class=\"attention\"><span class=\"sweep-count-"
189
- "type-options\">%s</span> Options</strong>."
190
- msgstr ""
191
-
192
- #: admin.php:454
193
- msgid "Transient Options"
194
- msgstr ""
195
-
196
- #: admin.php:476
197
- msgid "Database Sweep"
198
- msgstr ""
199
-
200
- #: admin.php:477
201
- msgid ""
202
- "There are a total of <strong class=\"attention\"><span class=\"sweep-count-"
203
- "type-tables\">%s</span> Tables</strong>."
204
- msgstr ""
205
-
206
- #: admin.php:491
207
- msgid "Optimize Tables"
208
- msgstr ""
209
-
210
- #: admin.php:513 admin.php:517 wp-sweep.php:147
211
- msgid "Sweep All"
212
- msgstr ""
213
-
214
- #: admin.php:514
215
- msgid ""
216
- "Note that some unused terms might belong to draft posts that have not been "
217
- "published yet. Only sweep all when you do not have any draft posts."
218
- msgstr ""
219
-
220
- #: wp-sweep.php:145
221
- msgid ""
222
- "Sweeping is in progress. If you leave now the process won't be completed."
223
- msgstr ""
224
-
225
- #: wp-sweep.php:148
226
- msgid "Sweeping ..."
227
- msgstr ""
228
-
229
- #: wp-sweep.php:179 wp-sweep.php:200
230
- msgid "Failed to verify referrer."
231
- msgstr ""
232
-
233
- #: wp-sweep.php:488
234
- msgid "%s Revisions Processed"
235
- msgstr ""
236
-
237
- #: wp-sweep.php:498
238
- msgid "%s Auto Drafts Processed"
239
- msgstr ""
240
-
241
- #: wp-sweep.php:508
242
- msgid "%s Deleted Posts Processed"
243
- msgstr ""
244
-
245
- #: wp-sweep.php:518
246
- msgid "%s Unapproved Comments Processed"
247
- msgstr ""
248
-
249
- #: wp-sweep.php:528
250
- msgid "%s Spam Comments Processed"
251
- msgstr ""
252
-
253
- #: wp-sweep.php:538
254
- msgid "%s Trash Comments Processed"
255
- msgstr ""
256
-
257
- #: wp-sweep.php:552
258
- msgid "%s Transient Options Processed"
259
- msgstr ""
260
-
261
- #: wp-sweep.php:567
262
- msgid "%s Orphaned Post Meta Processed"
263
- msgstr ""
264
-
265
- #: wp-sweep.php:582
266
- msgid "%s Orphaned Comment Meta Processed"
267
- msgstr ""
268
-
269
- #: wp-sweep.php:597
270
- msgid "%s Orphaned User Meta Processed"
271
- msgstr ""
272
-
273
- #: wp-sweep.php:607
274
- msgid "%s Orphaned Term Relationships Processed"
275
- msgstr ""
276
-
277
- #: wp-sweep.php:627
278
- msgid "%s Unused Terms Processed"
279
- msgstr ""
280
-
281
- #: wp-sweep.php:639
282
- msgid "%s Duplicated Post Meta Processed"
283
- msgstr ""
284
-
285
- #: wp-sweep.php:651
286
- msgid "%s Duplicated Comment Meta Processed"
287
- msgstr ""
288
-
289
- #: wp-sweep.php:663
290
- msgid "%s Duplicated User Meta Processed"
291
- msgstr ""
292
-
293
- #: wp-sweep.php:671
294
- msgid "%s Tables Processed"
295
- msgstr ""
296
-
297
- #: wp-sweep.php:686
298
- msgid "%s oEmbed Caches In Post Meta Processed"
299
- msgstr ""
300
-
301
- #. Plugin URI of the plugin/theme
302
- msgid "http://lesterchan.net/portfolio/programming/php/"
303
- msgstr ""
304
-
305
- #. Description of the plugin/theme
306
- msgid ""
307
- "WP-Sweep allows you to clean up unused, orphaned and duplicated data in your "
308
- "WordPress. It cleans up revisions, auto drafts, unapproved comments, spam "
309
- "comments, trashed comments, orphan post meta, orphan comment meta, orphan "
310
- "user meta, orphan term relationships, unused terms, duplicated post meta, "
311
- "duplicated comment meta, duplicated user meta and transient options. It also "
312
- "optimizes your database tables."
313
- msgstr ""
314
-
315
- #. Author of the plugin/theme
316
- msgid "Lester 'GaMerZ' Chan"
317
- msgstr ""
318
-
319
- #. Author URI of the plugin/theme
320
- msgid "http://lesterchan.net"
321
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -2,9 +2,9 @@
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 relationships, revisions, auto drafts, transient, database, tables, oembed
5
- Requires at least: 4.1
6
- Tested up to: 4.3
7
- Stable tag: 1.0.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -22,11 +22,13 @@ This plugin cleans up:
22
  * Orphaned post meta
23
  * Orphaned comment meta
24
  * Orphaned user meta
 
25
  * Orphan term relationships
26
  * Unused terms
27
  * Duplicated post meta
28
  * Duplicated comment meta
29
  * Duplicated user meta
 
30
  * Transient options
31
  * Optimizes database tables
32
  * oEmbed caches in post meta
@@ -41,6 +43,7 @@ Following delete functions are used:
41
  * delete_post_meta()
42
  * delete_comment_meta()
43
  * delete_user_meta()
 
44
  * wp_remove_object_terms()
45
  * wp_delete_term()
46
  * delete_transient()
@@ -59,6 +62,11 @@ Following delete functions are used:
59
  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.
60
 
61
  == Changelog ==
 
 
 
 
 
62
  = 1.0.5 =
63
  * FIXED: apply_filters() wrong arguments
64
 
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 relationships, revisions, auto drafts, transient, database, tables, oembed
5
+ Requires at least: 4.4
6
+ Tested up to: 4.4
7
+ Stable tag: 1.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
22
  * Orphaned post meta
23
  * Orphaned comment meta
24
  * Orphaned user meta
25
+ * Orphaned term meta
26
  * Orphan term relationships
27
  * Unused terms
28
  * Duplicated post meta
29
  * Duplicated comment meta
30
  * Duplicated user meta
31
+ * Duplicated term meta
32
  * Transient options
33
  * Optimizes database tables
34
  * oEmbed caches in post meta
43
  * delete_post_meta()
44
  * delete_comment_meta()
45
  * delete_user_meta()
46
+ * delete_term_meta()
47
  * wp_remove_object_terms()
48
  * wp_delete_term()
49
  * delete_transient()
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.6 =
66
+ * NEW: Delete 'languages' folder from the plugin
67
+ * NEW: Use translate.wordpress.org to translate the plugin
68
+ * FIXED: Works only with WordPress 4.4 because of new term meta
69
+
70
  = 1.0.5 =
71
  * FIXED: apply_filters() wrong arguments
72
 
wp-sweep.php CHANGED
@@ -3,11 +3,10 @@
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.5
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-sweep
10
- Domain Path: /languages/
11
  License: GPL2
12
  */
13
 
@@ -32,7 +31,7 @@ License: GPL2
32
  *
33
  * @since 1.0.0
34
  */
35
- define( 'WP_SWEEP_VERSION', '1.0.4' );
36
 
37
  /**
38
  * WP-Sweep class
@@ -40,804 +39,856 @@ define( 'WP_SWEEP_VERSION', '1.0.4' );
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', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
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
-
107
- /**
108
- * Adds all the plugin hooks
109
- *
110
- * @since 1.0.0
111
- *
112
- * @access public
113
- * @return void
114
- */
115
- public function add_hooks() {
116
- // Actions
117
- add_action( 'init', array( $this, 'init' ) );
118
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
119
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts') );
120
- add_action( 'wp_ajax_sweep_details', array( $this, 'ajax_sweep_details' ) );
121
- add_action( 'wp_ajax_sweep', array( $this, 'ajax_sweep' ) );
122
- }
123
-
124
- /**
125
- * Enqueue JS/CSS files used for admin
126
- *
127
- * @since 1.0.3
128
- *
129
- * @access public
130
- * @param string $hook
131
- * @return void
132
- */
133
- public function admin_enqueue_scripts( $hook ) {
134
- if( 'wp-sweep/admin.php' !== $hook ) {
135
- return;
136
- }
137
-
138
- if( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
139
- wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.js' ), array( 'jquery' ) , WP_SWEEP_VERSION, true );
140
- } else {
141
- wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.min.js' ), array( 'jquery' ) , WP_SWEEP_VERSION, true );
142
- }
143
-
144
- wp_localize_script( 'wp-sweep', 'wp_sweep', array(
145
- 'text_close_warning' => __( 'Sweeping is in progress. If you leave now the process won\'t be completed.', 'wp-sweep' ),
146
- 'text_sweep' => __( 'Sweep', 'wp-sweep' ),
147
- 'text_sweep_all' => __( 'Sweep All', 'wp-sweep' ),
148
- 'text_sweeping' => __( 'Sweeping ...', 'wp-sweep' ),
149
- 'text_na' => __( 'N/A', 'wp-sweep' )
150
- ) );
151
- }
152
-
153
- /**
154
- * Admin menu
155
- *
156
- * @since 1.0.3
157
- *
158
- * @access public
159
- * @return void
160
- */
161
- public function admin_menu() {
162
- add_management_page( __( 'Sweep', 'wp-sweep' ), __( 'Sweep', 'wp-sweep' ), 'activate_plugins', 'wp-sweep/admin.php' );
163
- }
164
-
165
-
166
- /**
167
- * Sweep Details loaded via AJAX
168
- *
169
- * @since 1.0.3
170
- *
171
- * @access public
172
- * @return void
173
- */
174
- public function ajax_sweep_details() {
175
- if( ! empty( $_GET['action'] ) && $_GET['action'] === 'sweep_details' && ! empty( $_GET['sweep_name'] ) && ! empty( $_GET['sweep_type'] ) ) {
176
- // Verify Referer
177
- if ( ! check_admin_referer( 'wp_sweep_details_' . $_GET['sweep_name'] ) ) {
178
- wp_send_json_error( array(
179
- 'error' => __( 'Failed to verify referrer.', 'wp-sweep' )
180
- ) );
181
- } else {
182
- wp_send_json_success( $this->details( $_GET['sweep_name'] ) );
183
- }
184
- }
185
- }
186
-
187
- /**
188
- * Sweep via AJAX
189
- *
190
- * @since 1.0.3
191
- *
192
- * @access public
193
- * @return void
194
- */
195
- public function ajax_sweep() {
196
- if( ! empty( $_GET['action'] ) && $_GET['action'] === 'sweep' && ! empty( $_GET['sweep_name'] ) && ! empty( $_GET['sweep_type'] ) ) {
197
- // Verify Referer
198
- if ( ! check_admin_referer( 'wp_sweep_' . $_GET['sweep_name'] ) ) {
199
- wp_send_json_error( array(
200
- 'error' => __( 'Failed to verify referrer.', 'wp-sweep' )
201
- ) );
202
- } else {
203
- $sweep = $this->sweep( $_GET['sweep_name'] );
204
- $count = $this->count( $_GET['sweep_name'] );
205
- $total_count = $this->total_count( $_GET['sweep_type'] );
206
- $total_stats = array();
207
- switch( $_GET['sweep_type'] ) {
208
- case 'posts':
209
- case 'postmeta':
210
- $total_stats = array( 'posts' => $this->total_count( 'posts' ), 'postmeta' => $this->total_count( 'postmeta') );
211
- break;
212
- case 'comments':
213
- case 'commentmeta':
214
- $total_stats = array( 'comments' => $this->total_count( 'comments' ), 'commentmeta' => $this->total_count( 'commentmeta') );
215
- break;
216
- case 'users':
217
- case 'usermeta':
218
- $total_stats = array( 'users' => $this->total_count( 'users' ), 'usermeta' => $this->total_count( 'usermeta') );
219
- break;
220
- case 'term_relationships':
221
- case 'term_taxonomy':
222
- case 'terms':
223
- $total_stats = array( 'term_relationships' => $this->total_count( 'term_relationships' ), 'term_taxonomy' => $this->total_count( 'term_taxonomy'), 'terms' => $this->total_count( 'terms') );
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 'options':
287
- $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->options" );
288
- break;
289
- case 'tables':
290
- $count = sizeof( $wpdb->get_col( 'SHOW TABLES' ) );
291
- break;
292
- }
293
-
294
- return apply_filters( 'wp_sweep_total_count', $count, $name );
295
- }
296
-
297
- /**
298
- * Count the number of items belonging to each sweep
299
- *
300
- * @since 1.0.0
301
- *
302
- * @access public
303
- * @param string $name
304
- * @return int Number of items belonging to each sweep
305
- */
306
- public function count( $name ) {
307
- global $wpdb;
308
-
309
- $count = 0;
310
-
311
- switch( $name ) {
312
- case 'revisions':
313
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = %s", 'revision' ) );
314
- break;
315
- case 'auto_drafts':
316
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = %s", 'auto-draft' ) );
317
- break;
318
- case 'deleted_posts':
319
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_status = %s", 'trash' ) );
320
- break;
321
- case 'unapproved_comments':
322
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = %s", '0' ) );
323
- break;
324
- case 'spam_comments':
325
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = %s", 'spam' ) );
326
- break;
327
- case 'deleted_comments':
328
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed' ) );
329
- break;
330
- case 'transient_options':
331
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(option_id) FROM $wpdb->options WHERE option_name LIKE(%s)", '%_transient_%' ) );
332
- break;
333
- case 'orphan_postmeta':
334
- $count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)" );
335
- break;
336
- case 'orphan_commentmeta':
337
- $count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)" );
338
- break;
339
- case 'orphan_usermeta':
340
- $count = $wpdb->get_var( "SELECT COUNT(umeta_id) FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)" );
341
- break;
342
- case 'orphan_term_relationships':
343
- $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)" );
344
- break;
345
- case 'unused_terms':
346
- $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 ) );
347
- break;
348
- case 'duplicated_postmeta':
349
- $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 ) );
350
- if( is_array( $query ) ) {
351
- $count = array_sum( array_map( 'intval', $query ) );
352
- }
353
- break;
354
- case 'duplicated_commentmeta':
355
- $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 ) );
356
- if( is_array( $query ) ) {
357
- $count = array_sum( array_map( 'intval', $query ) );
358
- }
359
- break;
360
- case 'duplicated_usermeta':
361
- $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 ) );
362
- if( is_array( $query ) ) {
363
- $count = array_sum( array_map( 'intval', $query ) );
364
- }
365
- break;
366
- case 'optimize_database':
367
- $count = sizeof( $wpdb->get_col( 'SHOW TABLES' ) );
368
- break;
369
- case 'oembed_postmeta':
370
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_id) FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
371
- break;
372
- }
373
-
374
- return apply_filters( 'wp_sweep_count', $count, $name );
375
- }
376
-
377
- /**
378
- * Return more details about a sweep
379
- *
380
- * @since 1.0.3
381
- *
382
- * @access public
383
- * @param string $name
384
- * @return int Number of items belonging to each sweep
385
- */
386
- public function details( $name ) {
387
- global $wpdb;
388
-
389
- $details = array();
390
-
391
- switch( $name ) {
392
- case 'revisions':
393
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_type = %s LIMIT %d", 'revision', $this->limit_details ) );
394
- break;
395
- case 'auto_drafts':
396
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_status = %s LIMIT %d", 'auto-draft', $this->limit_details ) );
397
- break;
398
- case 'deleted_posts':
399
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT post_title FROM $wpdb->posts WHERE post_status = %s LIMIT %d", 'trash', $this->limit_details ) );
400
- break;
401
- case 'unapproved_comments':
402
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT comment_author FROM $wpdb->comments WHERE comment_approved = %s LIMIT %d", '0', $this->limit_details ) );
403
- break;
404
- case 'spam_comments':
405
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT comment_author FROM $wpdb->comments WHERE comment_approved = %s LIMIT %d", 'spam', $this->limit_details ) );
406
- break;
407
- case 'deleted_comments':
408
- $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 ) );
409
- break;
410
- case 'transient_options':
411
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE(%s) LIMIT %d", '%_transient_%', $this->limit_details ) );
412
- break;
413
- case 'orphan_postmeta':
414
- $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 ) );
415
- break;
416
- case 'orphan_commentmeta':
417
- $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 ) );
418
- break;
419
- case 'orphan_usermeta':
420
- $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 ) );
421
- break;
422
- case 'orphan_term_relationships':
423
- $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 ) );
424
- break;
425
- case 'unused_terms':
426
- $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 ) );
427
- break;
428
- case 'duplicated_postmeta':
429
- $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 ) );
430
- $details = array();
431
- if( $query ) {
432
- foreach( $query as $meta ) {
433
- $details[] = $meta->meta_key;
434
- }
435
- }
436
- break;
437
- case 'duplicated_commentmeta':
438
- $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 ) );
439
- $details = array();
440
- if( $query ) {
441
- foreach( $query as $meta ) {
442
- $details[] = $meta->meta_key;
443
- }
444
- }
445
- break;
446
- case 'duplicated_usermeta':
447
- $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 ) );
448
- $details = array();
449
- if( $query ) {
450
- foreach( $query as $meta ) {
451
- $details[] = $meta->meta_key;
452
- }
453
- }
454
- break;
455
- case 'optimize_database':
456
- $details = $wpdb->get_col( 'SHOW TABLES' );
457
- break;
458
- case 'oembed_postmeta':
459
- $details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s) LIMIT %d", '%_oembed_%', $this->limit_details ) );
460
- break;
461
- }
462
-
463
- return apply_filters( 'wp_sweep_details', $details, $name );
464
- }
465
-
466
- /**
467
- * Does the sweeping/cleaning up
468
- *
469
- * @since 1.0.0
470
- *
471
- * @access public
472
- * @param string $name
473
- * @return string Processed message
474
- */
475
- public function sweep( $name ) {
476
- global $wpdb;
477
-
478
- $message = '';
479
-
480
- switch( $name ) {
481
- case 'revisions':
482
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s", 'revision' ) );
483
- if( $query ) {
484
- foreach ( $query as $id ) {
485
- wp_delete_post_revision( intval( $id ) );
486
- }
487
-
488
- $message = sprintf( __( '%s Revisions Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
489
- }
490
- break;
491
- case 'auto_drafts':
492
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s", 'auto-draft' ) );
493
- if( $query ) {
494
- foreach ( $query as $id ) {
495
- wp_delete_post( intval( $id ), true );
496
- }
497
-
498
- $message = sprintf( __( '%s Auto Drafts Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
499
- }
500
- break;
501
- case 'deleted_posts':
502
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s", 'trash' ) );
503
- if( $query ) {
504
- foreach ( $query as $id ) {
505
- wp_delete_post( $id, true );
506
- }
507
-
508
- $message = sprintf( __( '%s Deleted Posts Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
509
- }
510
- break;
511
- case 'unapproved_comments':
512
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", '0' ) );
513
- if( $query ) {
514
- foreach ( $query as $id ) {
515
- wp_delete_comment( intval( $id ), true );
516
- }
517
-
518
- $message = sprintf( __( '%s Unapproved Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
519
- }
520
- break;
521
- case 'spam_comments':
522
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", 'spam' ) );
523
- if( $query ) {
524
- foreach ( $query as $id ) {
525
- wp_delete_comment( intval( $id ), true );
526
- }
527
-
528
- $message = sprintf( __( '%s Spam Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
529
- }
530
- break;
531
- case 'deleted_comments':
532
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed' ) );
533
- if( $query ) {
534
- foreach ( $query as $id ) {
535
- wp_delete_comment( intval( $id ), true );
536
- }
537
-
538
- $message = sprintf( __( '%s Trash Comments Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
539
- }
540
- break;
541
- case 'transient_options':
542
- $query = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE(%s)", '%_transient_%' ) );
543
- if( $query ) {
544
- foreach ( $query as $option_name ) {
545
- if( strpos( $option_name, '_site_transient_' ) !== false ) {
546
- delete_site_transient( str_replace( '_site_transient_', '', $option_name ) );
547
- } else {
548
- delete_transient( str_replace( '_transient_', '', $option_name ) );
549
- }
550
- }
551
-
552
- $message = sprintf( __( '%s Transient Options Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
553
- }
554
- break;
555
- case 'orphan_postmeta':
556
- $query = $wpdb->get_results( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)" );
557
- if( $query ) {
558
- foreach ( $query as $meta ) {
559
- $post_id = intval( $meta->post_id );
560
- if( $post_id === 0 ) {
561
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
562
- } else {
563
- delete_post_meta( $post_id, $meta->meta_key );
564
- }
565
- }
566
-
567
- $message = sprintf( __( '%s Orphaned Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
568
- }
569
- break;
570
- case 'orphan_commentmeta':
571
- $query = $wpdb->get_results( "SELECT comment_id, meta_key FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)" );
572
- if( $query ) {
573
- foreach ( $query as $meta ) {
574
- $comment_id = intval( $meta->comment_id );
575
- if( $comment_id === 0 ) {
576
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s", $comment_id, $meta->meta_key ) );
577
- } else {
578
- delete_comment_meta( $comment_id, $meta->meta_key );
579
- }
580
- }
581
-
582
- $message = sprintf( __( '%s Orphaned Comment Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
583
- }
584
- break;
585
- case 'orphan_usermeta':
586
- $query = $wpdb->get_results( "SELECT user_id, meta_key FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)" );
587
- if( $query ) {
588
- foreach ( $query as $meta ) {
589
- $user_id = intval( $meta->user_id );
590
- if( $user_id === 0 ) {
591
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta->meta_key ) );
592
- } else {
593
- delete_user_meta( $user_id, $meta->meta_key );
594
- }
595
- }
596
-
597
- $message = sprintf( __( '%s Orphaned User Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
598
- }
599
- break;
600
- case 'orphan_term_relationships':
601
- $query = $wpdb->get_results( "SELECT tr.object_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)" );
602
- if( $query ) {
603
- foreach ( $query as $tax ) {
604
- wp_remove_object_terms( intval( $tax->object_id ), intval( $tax->term_id ), $tax->taxonomy );
605
- }
606
-
607
- $message = sprintf( __( '%s Orphaned Term Relationships Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
608
- }
609
- break;
610
- case 'unused_terms':
611
- $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 ) );
612
- if( $query ) {
613
- $check_wp_terms = false;
614
- foreach ( $query as $tax ) {
615
- if( taxonomy_exists( $tax->taxonomy ) ) {
616
- wp_delete_term( intval( $tax->term_id ), $tax->taxonomy );
617
- } else {
618
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", intval( $tax->term_taxonomy_id ) ) );
619
- $check_wp_terms = true;
620
- }
621
- }
622
- // We need this for invalid taxonomies
623
- if( $check_wp_terms ) {
624
- $wpdb->get_results( "DELETE FROM $wpdb->terms WHERE term_id NOT IN (SELECT term_id FROM $wpdb->term_taxonomy)" );
625
- }
626
-
627
- $message = sprintf( __( '%s Unused Terms Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
628
- }
629
- break;
630
- case 'duplicated_postmeta':
631
- $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 ) );
632
- if( $query ) {
633
- foreach ( $query as $meta ) {
634
- $ids = array_map( 'intval', explode( ',', $meta->ids ) );
635
- array_pop( $ids );
636
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN (" . implode( ',', $ids ) . ") AND post_id = %d", intval( $meta->post_id ) ) );
637
- }
638
-
639
- $message = sprintf( __( '%s Duplicated Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
640
- }
641
- break;
642
- case 'duplicated_commentmeta':
643
- $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 ) );
644
- if( $query ) {
645
- foreach ( $query as $meta ) {
646
- $ids = array_map( 'intval', explode( ',', $meta->ids ) );
647
- array_pop( $ids );
648
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN (" . implode( ',', $ids ) . ") AND comment_id = %d", intval( $meta->comment_id ) ) );
649
- }
650
-
651
- $message = sprintf( __( '%s Duplicated Comment Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
652
- }
653
- break;
654
- case 'duplicated_usermeta':
655
- $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 ) );
656
- if( $query ) {
657
- foreach ( $query as $meta ) {
658
- $ids = array_map( 'intval', explode( ',', $meta->ids ) );
659
- array_pop( $ids );
660
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE umeta_id IN (" . implode( ',', $ids ) . ") AND user_id = %d", intval( $meta->user_id ) ) );
661
- }
662
-
663
- $message = sprintf( __( '%s Duplicated User Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
664
- }
665
- break;
666
- case 'optimize_database':
667
- $query = $wpdb->get_col( 'SHOW TABLES' );
668
- if( $query ) {
669
- $tables = implode( ',', $query );
670
- $wpdb->query( "OPTIMIZE TABLE $tables" );
671
- $message = sprintf( __( '%s Tables Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
672
- }
673
- break;
674
- case 'oembed_postmeta':
675
- $query = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
676
- if( $query ) {
677
- foreach ( $query as $meta ) {
678
- $post_id = intval( $meta->post_id );
679
- if( $post_id === 0 ) {
680
- $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
681
- } else {
682
- delete_post_meta( $post_id, $meta->meta_key );
683
- }
684
- }
685
-
686
- $message = sprintf( __( '%s oEmbed Caches In Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
687
- }
688
- break;
689
- }
690
-
691
- return apply_filters( 'wp_sweep_sweep', $message, $name );
692
- }
693
-
694
- /**
695
- * Format number to percentage, taking care of division by 0.
696
- * Props @barisunver https://github.com/barisunver
697
- *
698
- * @since 1.0.2
699
- *
700
- * @access public
701
- * @param int $current
702
- * @param int $total
703
- * @return string Number in percentage
704
- */
705
- public function format_percentage( $current, $total ) {
706
- return ( $total > 0 ? round( ( $current / $total ) * 100, 2 ) : 0 ) . '%';
707
- }
708
-
709
- /*
710
- * Get excluded term IDs
711
- *
712
- * @since 1.0.3
713
- *
714
- * @access private
715
- * @return array Excluded term IDs
716
- */
717
- private function get_excluded_termids() {
718
- $default_term_ids = $this->get_default_taxonomy_termids();
719
- if( ! is_array( $default_term_ids ) ) {
720
- $default_term_ids = array();
721
- }
722
- $parent_term_ids = $this->get_parent_termids();
723
- if( ! is_array( $parent_term_ids ) ) {
724
- $parent_term_ids = array();
725
- }
726
- return array_merge( $default_term_ids, $parent_term_ids );
727
- }
728
-
729
- /*
730
- * Get all default taxonomy term IDs
731
- *
732
- * @since 1.0.3
733
- *
734
- * @access private
735
- * @return array Default taxonomy term IDs
736
- */
737
- private function get_default_taxonomy_termids() {
738
- $taxonomies = get_taxonomies();
739
- $default_term_ids = array();
740
- if( $taxonomies ) {
741
- $tax = array_keys( $taxonomies );
742
- if( $tax ) {
743
- foreach( $tax as $t ) {
744
- $term_id = intval( get_option( 'default_' . $t ) );
745
- if( $term_id > 0 ) {
746
- $default_term_ids[] = $term_id;
747
- }
748
- }
749
- }
750
- }
751
- return $default_term_ids;
752
- }
753
-
754
- /*
755
- * Get terms that has a parent term
756
- *
757
- * @since 1.0.3
758
- *
759
- * @access private
760
- * @return array Parent term IDs
761
- */
762
- private function get_parent_termids() {
763
- global $wpdb;
764
- 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 ) );
765
- }
766
-
767
- /**
768
- * What to do when the plugin is being deactivated
769
- *
770
- * @since 1.0.0
771
- *
772
- * @access public
773
- * @param boolean $network_wide
774
- * @return void
775
- */
776
- public function plugin_activation( $network_wide ) {
777
- if ( is_multisite() && $network_wide ) {
778
- $ms_sites = wp_get_sites();
779
-
780
- if( 0 < sizeof( $ms_sites ) ) {
781
- foreach ( $ms_sites as $ms_site ) {
782
- switch_to_blog( $ms_site['blog_id'] );
783
- $this->plugin_activated();
784
- }
785
- }
786
-
787
- restore_current_blog();
788
- } else {
789
- $this->plugin_activated();
790
- }
791
- }
792
-
793
- /**
794
- * Perform plugin activation tasks
795
- *
796
- * @since 1.0.0
797
- *
798
- * @access private
799
- * @return void
800
- */
801
- private function plugin_activated() {}
802
-
803
- /**
804
- * What to do when the plugin is being activated
805
- *
806
- * @since 1.0.0
807
- *
808
- * @access public
809
- * @param boolean $network_wide
810
- * @return void
811
- */
812
- public function plugin_deactivation( $network_wide ) {
813
- if ( is_multisite() && $network_wide ) {
814
- $ms_sites = wp_get_sites();
815
-
816
- if( 0 < sizeof( $ms_sites ) ) {
817
- foreach ( $ms_sites as $ms_site ) {
818
- switch_to_blog( $ms_site['blog_id'] );
819
- $this->plugin_deactivated();
820
- }
821
- }
822
-
823
- restore_current_blog();
824
- } else {
825
- $this->plugin_deactivated();
826
- }
827
- }
828
-
829
- /**
830
- * Perform plugin deactivation tasks
831
- *
832
- * @since 1.0.0
833
- *
834
- * @access private
835
- * @return void
836
- */
837
- private function plugin_deactivated() {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
838
  }
839
 
840
  /**
841
  * Init WP-Sweep
842
  */
843
- WPSweep::get_instance();
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.6
7
  Author: Lester 'GaMerZ' Chan
8
  Author URI: http://lesterchan.net
9
  Text Domain: wp-sweep
 
10
  License: GPL2
11
  */
12
 
31
  *
32
  * @since 1.0.0
33
  */
34
+ define( 'WP_SWEEP_VERSION', '1.0.6' );
35
 
36
  /**
37
  * WP-Sweep class
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, 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( intval( $tax->object_id ), intval( $tax->term_id ), $tax->taxonomy );
644
+ }
645
+
646
+ $message = sprintf( __( '%s Orphaned Term Relationships Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
647
+ }
648
+ break;
649
+ case 'unused_terms':
650
+ $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 ) );
651
+ if( $query ) {
652
+ $check_wp_terms = false;
653
+ foreach ( $query as $tax ) {
654
+ if( taxonomy_exists( $tax->taxonomy ) ) {
655
+ wp_delete_term( intval( $tax->term_id ), $tax->taxonomy );
656
+ } else {
657
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", intval( $tax->term_taxonomy_id ) ) );
658
+ $check_wp_terms = true;
659
+ }
660
+ }
661
+ // We need this for invalid taxonomies
662
+ if( $check_wp_terms ) {
663
+ $wpdb->get_results( "DELETE FROM $wpdb->terms WHERE term_id NOT IN (SELECT term_id FROM $wpdb->term_taxonomy)" );
664
+ }
665
+
666
+ $message = sprintf( __( '%s Unused Terms Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
667
+ }
668
+ break;
669
+ case 'duplicated_postmeta':
670
+ $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 ) );
671
+ if( $query ) {
672
+ foreach ( $query as $meta ) {
673
+ $ids = array_map( 'intval', explode( ',', $meta->ids ) );
674
+ array_pop( $ids );
675
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN (" . implode( ',', $ids ) . ") AND post_id = %d", intval( $meta->post_id ) ) );
676
+ }
677
+
678
+ $message = sprintf( __( '%s Duplicated Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
679
+ }
680
+ break;
681
+ case 'duplicated_commentmeta':
682
+ $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 ) );
683
+ if( $query ) {
684
+ foreach ( $query as $meta ) {
685
+ $ids = array_map( 'intval', explode( ',', $meta->ids ) );
686
+ array_pop( $ids );
687
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN (" . implode( ',', $ids ) . ") AND comment_id = %d", intval( $meta->comment_id ) ) );
688
+ }
689
+
690
+ $message = sprintf( __( '%s Duplicated Comment Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
691
+ }
692
+ break;
693
+ case 'duplicated_usermeta':
694
+ $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 ) );
695
+ if( $query ) {
696
+ foreach ( $query as $meta ) {
697
+ $ids = array_map( 'intval', explode( ',', $meta->ids ) );
698
+ array_pop( $ids );
699
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE umeta_id IN (" . implode( ',', $ids ) . ") AND user_id = %d", intval( $meta->user_id ) ) );
700
+ }
701
+
702
+ $message = sprintf( __( '%s Duplicated User Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
703
+ }
704
+ break;
705
+ case 'duplicated_termmeta':
706
+ $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 ) );
707
+ if( $query ) {
708
+ foreach ( $query as $meta ) {
709
+ $ids = array_map( 'intval', explode( ',', $meta->ids ) );
710
+ array_pop( $ids );
711
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_id IN (" . implode( ',', $ids ) . ") AND term_id = %d", intval( $meta->term_id ) ) );
712
+ }
713
+
714
+ $message = sprintf( __( '%s Duplicated Term Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
715
+ }
716
+ break;
717
+ case 'optimize_database':
718
+ $query = $wpdb->get_col( 'SHOW TABLES' );
719
+ if( $query ) {
720
+ $tables = implode( ',', $query );
721
+ $wpdb->query( "OPTIMIZE TABLE $tables" );
722
+ $message = sprintf( __( '%s Tables Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
723
+ }
724
+ break;
725
+ case 'oembed_postmeta':
726
+ $query = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
727
+ if( $query ) {
728
+ foreach ( $query as $meta ) {
729
+ $post_id = intval( $meta->post_id );
730
+ if( $post_id === 0 ) {
731
+ $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
732
+ } else {
733
+ delete_post_meta( $post_id, $meta->meta_key );
734
+ }
735
+ }
736
+
737
+ $message = sprintf( __( '%s oEmbed Caches In Post Meta Processed', 'wp-sweep' ), number_format_i18n( sizeof( $query ) ) );
738
+ }
739
+ break;
740
+ }
741
+
742
+ return apply_filters( 'wp_sweep_sweep', $message, $name );
743
+ }
744
+
745
+ /**
746
+ * Format number to percentage, taking care of division by 0.
747
+ * Props @barisunver https://github.com/barisunver
748
+ *
749
+ * @since 1.0.2
750
+ *
751
+ * @access public
752
+ * @param int $current
753
+ * @param int $total
754
+ * @return string Number in percentage
755
+ */
756
+ public function format_percentage( $current, $total ) {
757
+ return ( $total > 0 ? round( ( $current / $total ) * 100, 2 ) : 0 ) . '%';
758
+ }
759
+
760
+ /*
761
+ * Get excluded term IDs
762
+ *
763
+ * @since 1.0.3
764
+ *
765
+ * @access private
766
+ * @return array Excluded term IDs
767
+ */
768
+ private function get_excluded_termids() {
769
+ $default_term_ids = $this->get_default_taxonomy_termids();
770
+ if( ! is_array( $default_term_ids ) ) {
771
+ $default_term_ids = array();
772
+ }
773
+ $parent_term_ids = $this->get_parent_termids();
774
+ if( ! is_array( $parent_term_ids ) ) {
775
+ $parent_term_ids = array();
776
+ }
777
+ return array_merge( $default_term_ids, $parent_term_ids );
778
+ }
779
+
780
+ /*
781
+ * Get all default taxonomy term IDs
782
+ *
783
+ * @since 1.0.3
784
+ *
785
+ * @access private
786
+ * @return array Default taxonomy term IDs
787
+ */
788
+ private function get_default_taxonomy_termids() {
789
+ $taxonomies = get_taxonomies();
790
+ $default_term_ids = array();
791
+ if( $taxonomies ) {
792
+ $tax = array_keys( $taxonomies );
793
+ if( $tax ) {
794
+ foreach( $tax as $t ) {
795
+ $term_id = intval( get_option( 'default_' . $t ) );
796
+ if( $term_id > 0 ) {
797
+ $default_term_ids[] = $term_id;
798
+ }
799
+ }
800
+ }
801
+ }
802
+ return $default_term_ids;
803
+ }
804
+
805
+ /*
806
+ * Get terms that has a parent term
807
+ *
808
+ * @since 1.0.3
809
+ *
810
+ * @access private
811
+ * @return array Parent term IDs
812
+ */
813
+ private function get_parent_termids() {
814
+ global $wpdb;
815
+ 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 ) );
816
+ }
817
+
818
+ /**
819
+ * What to do when the plugin is being deactivated
820
+ *
821
+ * @since 1.0.0
822
+ *
823
+ * @access public
824
+ * @param boolean $network_wide
825
+ * @return void
826
+ */
827
+ public function plugin_activation( $network_wide ) {
828
+ if ( is_multisite() && $network_wide ) {
829
+ $ms_sites = wp_get_sites();
830
+
831
+ if( 0 < sizeof( $ms_sites ) ) {
832
+ foreach ( $ms_sites as $ms_site ) {
833
+ switch_to_blog( $ms_site['blog_id'] );
834
+ $this->plugin_activated();
835
+ }
836
+ }
837
+
838
+ restore_current_blog();
839
+ } else {
840
+ $this->plugin_activated();
841
+ }
842
+ }
843
+
844
+ /**
845
+ * Perform plugin activation tasks
846
+ *
847
+ * @since 1.0.0
848
+ *
849
+ * @access private
850
+ * @return void
851
+ */
852
+ private function plugin_activated() {}
853
+
854
+ /**
855
+ * What to do when the plugin is being activated
856
+ *
857
+ * @since 1.0.0
858
+ *
859
+ * @access public
860
+ * @param boolean $network_wide
861
+ * @return void
862
+ */
863
+ public function plugin_deactivation( $network_wide ) {
864
+ if ( is_multisite() && $network_wide ) {
865
+ $ms_sites = wp_get_sites();
866
+
867
+ if( 0 < sizeof( $ms_sites ) ) {
868
+ foreach ( $ms_sites as $ms_site ) {
869
+ switch_to_blog( $ms_site['blog_id'] );
870
+ $this->plugin_deactivated();
871
+ }
872
+ }
873
+
874
+ restore_current_blog();
875
+ } else {
876
+ $this->plugin_deactivated();
877
+ }
878
+ }
879
+
880
+ /**
881
+ * Perform plugin deactivation tasks
882
+ *
883
+ * @since 1.0.0
884
+ *
885
+ * @access private
886
+ * @return void
887
+ */
888
+ private function plugin_deactivated() {}
889
  }
890
 
891
  /**
892
  * Init WP-Sweep
893
  */
894
+ WPSweep::get_instance();