WP-Sweep - Version 1.0.5

Version Description

  • FIXED: apply_filters() wrong arguments
Download this release

Release Info

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

Version 1.0.5

Files changed (9) hide show
  1. admin.php +520 -0
  2. composer.json +12 -0
  3. index.php +2 -0
  4. js/wp-sweep.js +95 -0
  5. js/wp-sweep.min.js +4 -0
  6. languages/wp-sweep.pot +321 -0
  7. readme.txt +103 -0
  8. uninstall.php +29 -0
  9. wp-sweep.php +843 -0
admin.php ADDED
@@ -0,0 +1,520 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ ### Exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) ) exit;
4
+
5
+ ### Variables
6
+ $current_page = admin_url( 'tools.php?page=' . plugin_basename( 'wp-sweep/admin.php' ) );
7
+ $message = '';
8
+
9
+ ### Sweeping
10
+ if( ! empty( $_GET['sweep'] ) ) {
11
+ if ( check_admin_referer( 'wp_sweep_' . $_GET['sweep'] ) ) {
12
+ $message = WPSweep::get_instance()->sweep( $_GET['sweep'] );
13
+ }
14
+ }
15
+
16
+ ### Database Table Status
17
+ $total_posts = WPSweep::get_instance()->total_count( 'posts' );
18
+ $total_postmeta = WPSweep::get_instance()->total_count( 'postmeta' );
19
+ $total_comments = WPSweep::get_instance()->total_count( 'comments' );
20
+ $total_commentmeta = WPSweep::get_instance()->total_count( 'commentmeta' );
21
+ $total_users = WPSweep::get_instance()->total_count( 'users' );
22
+ $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
+
29
+ ### Count
30
+ $revisions = WPSweep::get_instance()->count( 'revisions' );
31
+ $auto_drafts = WPSweep::get_instance()->count( 'auto_drafts' );
32
+ $deleted_posts = WPSweep::get_instance()->count( 'deleted_posts' );
33
+ $orphan_postmeta = WPSweep::get_instance()->count( 'orphan_postmeta' );
34
+ $duplicated_postmeta = WPSweep::get_instance()->count( 'duplicated_postmeta' );
35
+ $oembed_postmeta = WPSweep::get_instance()->count( 'oembed_postmeta' );
36
+
37
+ $unapproved_comments = WPSweep::get_instance()->count( 'unapproved_comments' );
38
+ $spam_comments = WPSweep::get_instance()->count( 'spam_comments' );
39
+ $deleted_comments = WPSweep::get_instance()->count( 'deleted_comments' ) ;
40
+ $orphan_commentmeta = WPSweep::get_instance()->count( 'orphan_commentmeta' );
41
+ $duplicated_commentmeta = WPSweep::get_instance()->count( 'duplicated_commentmeta' );
42
+
43
+ $orphan_usermeta = WPSweep::get_instance()->count( 'orphan_usermeta' );
44
+ $duplicated_usermeta = WPSweep::get_instance()->count( 'duplicated_usermeta' );
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>
composer.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
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"
11
+ }
12
+ }
index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ # Silence is golden.
js/wp-sweep.js ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function ($) {
2
+ 'use strict';
3
+
4
+ $(function () {
5
+ var $body = $('body'),
6
+ sweep = function($node) {
7
+ var $row = $node.parents('tr');
8
+
9
+ // Add Active
10
+ $body.addClass('sweep-active');
11
+ // Add Disabled
12
+ $node.prop('disabled', true).text(wp_sweep.text_sweeping);
13
+
14
+ return $.get(ajaxurl, { action: $node.data('action'), sweep_name: $node.data('sweep_name'), sweep_type: $node.data('sweep_type'), '_wpnonce': $node.data('nonce') }, function(data) {
15
+ if(data.success) {
16
+ var count = parseInt(data.data.count, 10);
17
+ // Count Col
18
+ $('.sweep-count', $row).text(count.toLocaleString());
19
+ // % Of Col
20
+ $('.sweep-percentage', $row).text(data.data.percentage);
21
+ // Action Col
22
+ if(count === 0) {
23
+ $node.parent('td').html(wp_sweep.text_na);
24
+ }
25
+ // Stats
26
+ $.each(data.data.stats, function(key, value) {
27
+ $('.sweep-count-type-' + key).text(parseInt(value, 10).toLocaleString());
28
+ });
29
+ // Message
30
+ $row.parents('.table-sweep').prev('.sweep-message').html('<div class="updated"><p>' + data.data.sweep + '</p></div>');
31
+ // Hide Sweep Details
32
+ $('.sweep-details', $row).html('').hide();
33
+ // Remove Active
34
+ $body.removeClass('sweep-active');
35
+ // Remove Disabled
36
+ $node.prop('disabled', false).text(wp_sweep.text_sweep);
37
+ }
38
+ });
39
+ };
40
+
41
+ $('.btn-sweep').click(function(evt) {
42
+ evt.preventDefault();
43
+ sweep($(this));
44
+ });
45
+
46
+ $('.btn-sweep-details').click(function(evt) {
47
+ evt.preventDefault();
48
+ var $node = $(this);
49
+
50
+ $.get(ajaxurl, { action: $node.data('action'), sweep_name: $node.data('sweep_name'), sweep_type: $node.data('sweep_type'), '_wpnonce': $node.data('nonce') }, function(data) {
51
+ if(data.success) {
52
+ if(data.data.length > 0) {
53
+ var html = '';
54
+ $.each(data.data, function(i, n) {
55
+ html += '<li>' + n + '</li>';
56
+ });
57
+ $('.sweep-details', $node.parents('tr')).html('<ol>' + html + '</ol>').show();
58
+ }
59
+ }
60
+ });
61
+ });
62
+
63
+ $('.btn-sweep-all').click(function(evt) {
64
+ evt.preventDefault();
65
+ var $node = $(this), $btn_sweep = $('.btn-sweep'), sweep_all;
66
+
67
+ $node.prop('disabled', true).text(wp_sweep.text_sweeping);
68
+
69
+ sweep_all = $btn_sweep.toArray().reduce(function(current, next) {
70
+ return current.then(function() {
71
+ return sweep($(next));
72
+ });
73
+ }, $().promise());
74
+
75
+ sweep_all.done(function() {
76
+ // Remove Active
77
+ $body.removeClass('sweep-active');
78
+ // Remove Disabled
79
+ $node.prop('disabled', false).text(wp_sweep.text_sweep_all);
80
+ });
81
+ });
82
+
83
+ /*
84
+ Page closing confirmation
85
+ https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/beforeunload
86
+ */
87
+ $(window).on('beforeunload', function (e) {
88
+ if ($body.hasClass('sweep-active')) {
89
+ (e || window.event).returnValue = wp_sweep.text_close_warning; // Gecko and Trident
90
+ return wp_sweep.text_close_warning; // Gecko and WebKit
91
+ }
92
+ });
93
+ });
94
+
95
+ })(jQuery);
js/wp-sweep.min.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ (function(b){b(function(){var f=b("body"),g=function(a){var c=a.parents("tr");f.addClass("sweep-active");a.prop("disabled",!0).text(wp_sweep.text_sweeping);return b.get(ajaxurl,{action:a.data("action"),sweep_name:a.data("sweep_name"),sweep_type:a.data("sweep_type"),_wpnonce:a.data("nonce")},function(e){if(e.success){var d=parseInt(e.data.count,10);b(".sweep-count",c).text(d.toLocaleString());b(".sweep-percentage",c).text(e.data.percentage);0===d&&a.parent("td").html(wp_sweep.text_na);b.each(e.data.stats,
2
+ function(a,c){b(".sweep-count-type-"+a).text(parseInt(c,10).toLocaleString())});c.parents(".table-sweep").prev(".sweep-message").html('<div class="updated"><p>'+e.data.sweep+"</p></div>");b(".sweep-details",c).html("").hide();f.removeClass("sweep-active");a.prop("disabled",!1).text(wp_sweep.text_sweep)}})};b(".btn-sweep").click(function(a){a.preventDefault();g(b(this))});b(".btn-sweep-details").click(function(a){a.preventDefault();var c=b(this);b.get(ajaxurl,{action:c.data("action"),sweep_name:c.data("sweep_name"),
3
+ sweep_type:c.data("sweep_type"),_wpnonce:c.data("nonce")},function(a){if(a.success&&0<a.data.length){var d="";b.each(a.data,function(a,b){d+="<li>"+b+"</li>"});b(".sweep-details",c.parents("tr")).html("<ol>"+d+"</ol>").show()}})});b(".btn-sweep-all").click(function(a){a.preventDefault();var c=b(this);a=b(".btn-sweep");c.prop("disabled",!0).text(wp_sweep.text_sweeping);a.toArray().reduce(function(a,c){return a.then(function(){return g(b(c))})},b().promise()).done(function(){f.removeClass("sweep-active");
4
+ c.prop("disabled",!1).text(wp_sweep.text_sweep_all)})});b(window).on("beforeunload",function(a){if(f.hasClass("sweep-active"))return(a||window.event).returnValue=wp_sweep.text_close_warning})})})(jQuery);
languages/wp-sweep.pot ADDED
@@ -0,0 +1,321 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP-Sweep ===
2
+ Contributors: GamerZ
3
+ Donate link: http://lesterchan.net/site/donation/
4
+ Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term 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
+
11
+ WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It also optimizes your database tables.
12
+
13
+ == Description ==
14
+ This plugin cleans up:
15
+
16
+ * Revisions
17
+ * Auto drafts
18
+ * Deleted comments
19
+ * Unapproved comments
20
+ * Spammed comments
21
+ * Deleted comments
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
33
+
34
+ This plugin uses proper WordPress delete functions as much as possible instead of running direct delete MySQL queries.
35
+
36
+ Following delete functions are used:
37
+
38
+ * wp_delete_post_revision()
39
+ * wp_delete_post()
40
+ * wp_delete_comment()
41
+ * delete_post_meta()
42
+ * delete_comment_meta()
43
+ * delete_user_meta()
44
+ * wp_remove_object_terms()
45
+ * wp_delete_term()
46
+ * delete_transient()
47
+ * delete_site_transient()
48
+
49
+ = Build Status =
50
+ [![Build Status](https://travis-ci.org/lesterchan/wp-sweep.svg?branch=master)](https://travis-ci.org/lesterchan/wp-sweep)
51
+
52
+ = Development =
53
+ * [https://github.com/lesterchan/wp-sweep](https://github.com/lesterchan/wp-sweep "https://github.com/lesterchan/wp-sweep")
54
+
55
+ = Credits =
56
+ * Plugin icon by [Freepik](http://www.freepik.com) from [Flaticon](http://www.flaticon.com)
57
+
58
+ = Donations =
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
+
65
+ = 1.0.4 =
66
+ * NEW: oEmbed caches in post meta Sweep
67
+ * NEW: Add POT file for translators
68
+
69
+ = 1.0.3 =
70
+ * NEW: AJAX Sweep All
71
+ * NEW: AJAX Sweeping
72
+ * NEW: View details of sweep
73
+ * NEW: Optimize DB sweep
74
+ * NEW: User hint and confirmation. Props @SiamKreative
75
+ * FIXED: Division by zero. Pros @barisunver
76
+
77
+ = 1.0.2 =
78
+ * FIXED: Use term_id for wp_remove_object_terms()
79
+ * FIXED: number_format_i18n() issues after sweeping
80
+
81
+ = 1.0.1 =
82
+ * NEW: Moved plugin location to WP-Admin -> Tools -> Sweep
83
+ * NEW: Add Deleted Post Sweep
84
+ * FIXED: Use forced_delete for wp_delete_post() and wp_delete_comment();
85
+ * FIXED: If orphaned meta has an object id of 0, use SQL query to delete
86
+
87
+ = 1.0.0 =
88
+ * Initial release
89
+
90
+ == Installation ==
91
+ 1. Upload `wp-sweep` folder to the `/wp-content/plugins/` directory
92
+ 2. Activate the `WP-Sweep` plugin through the 'Plugins' menu in WordPress
93
+ 3. You can access `WP-Sweep` via `WP-Admin -> Tools -> Sweep`
94
+
95
+ == Screenshots ==
96
+ 1. WP-Sweep Administrator Page (Before Sweeping)
97
+ 2. WP-Sweep Administrator Page (Swept)
98
+
99
+ == Frequently Asked Questions ==
100
+ Coming soon ...
101
+
102
+ == Upgrade Notice ==
103
+ N/A
uninstall.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Uninstall WP-Sweep
4
+ */
5
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
6
+ exit ();
7
+
8
+ if ( is_multisite() ) {
9
+ $ms_sites = wp_get_sites();
10
+
11
+ if( 0 < sizeof( $ms_sites ) ) {
12
+ foreach ( $ms_sites as $ms_site ) {
13
+ switch_to_blog( $ms_site['blog_id'] );
14
+ plugin_uninstalled();
15
+ }
16
+ }
17
+
18
+ restore_current_blog();
19
+ } else {
20
+ plugin_uninstalled();
21
+ }
22
+
23
+ /**
24
+ * Delete plugin table when uninstalled
25
+ *
26
+ * @access public
27
+ * @return void
28
+ */
29
+ function plugin_uninstalled() {}
wp-sweep.php ADDED
@@ -0,0 +1,843 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-Sweep
4
+ Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
+ Description: WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It cleans up revisions, auto drafts, unapproved comments, spam comments, trashed comments, orphan post meta, orphan comment meta, orphan user meta, orphan term relationships, unused terms, duplicated post meta, duplicated comment meta, duplicated user meta and transient options. It also optimizes your database tables.
6
+ Version: 1.0.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
+
14
+ /* Copyright 2015 Lester Chan (email : lesterchan@gmail.com)
15
+
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License, version 2, as
18
+ published by the Free Software Foundation.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program; if not, write to the Free Software
27
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
+ */
29
+
30
+ /**
31
+ * WP-Sweep version
32
+ *
33
+ * @since 1.0.0
34
+ */
35
+ define( 'WP_SWEEP_VERSION', '1.0.4' );
36
+
37
+ /**
38
+ * WP-Sweep class
39
+ *
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();