Version Description
Download this release
Release Info
Developer | GamerZ |
Plugin | WP-Sweep |
Version | 1.1.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.12 to 1.1.0
- admin.php +225 -212
- composer.json +10 -2
- composer.lock +125 -0
- inc/class-wpsweep-api.php +180 -0
- class-command.php → inc/class-wpsweep-command.php +49 -28
- index.php +7 -1
- readme.txt +42 -4
- uninstall.php +8 -8
- wp-sweep.php +169 -140
admin.php
CHANGED
@@ -1,58 +1,63 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
// Exit if accessed directly
|
4 |
if ( ! defined( 'ABSPATH' ) ) {
|
5 |
exit;
|
6 |
}
|
7 |
|
8 |
-
// Variables
|
9 |
$current_page = admin_url( 'tools.php?page=' . plugin_basename( 'wp-sweep/admin.php' ) );
|
10 |
-
$message
|
11 |
|
12 |
-
// Sweeping
|
13 |
if ( ! empty( $_GET['sweep'] ) ) {
|
14 |
if ( check_admin_referer( 'wp_sweep_' . $_GET['sweep'] ) ) {
|
15 |
$message = WPSweep::get_instance()->sweep( $_GET['sweep'] );
|
16 |
}
|
17 |
}
|
18 |
|
19 |
-
// Database Table Status
|
20 |
-
$total_posts
|
21 |
-
$total_postmeta
|
22 |
-
$total_comments
|
23 |
-
$total_commentmeta
|
24 |
-
$total_users
|
25 |
-
$total_usermeta
|
26 |
-
$total_term_relationships
|
27 |
-
$total_term_taxonomy
|
28 |
-
$total_terms
|
29 |
-
$total_termmeta
|
30 |
-
$total_options
|
31 |
-
$total_tables
|
32 |
|
33 |
-
// Count
|
34 |
-
$revisions
|
35 |
-
$auto_drafts
|
36 |
-
$deleted_posts
|
37 |
-
$orphan_postmeta
|
38 |
-
$duplicated_postmeta
|
39 |
-
$oembed_postmeta
|
40 |
|
41 |
-
$unapproved_comments
|
42 |
-
$spam_comments
|
43 |
-
$deleted_comments
|
44 |
-
$orphan_commentmeta
|
45 |
-
$duplicated_commentmeta
|
46 |
|
47 |
-
$orphan_usermeta
|
48 |
-
$duplicated_usermeta
|
49 |
|
50 |
-
$orphan_term_relationships
|
51 |
-
$unused_terms
|
52 |
-
$orphan_termmeta
|
53 |
-
$duplicated_termmeta
|
54 |
|
55 |
-
$transient_options
|
56 |
|
57 |
?>
|
58 |
<style type="text/css">
|
@@ -67,145 +72,148 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
67 |
}
|
68 |
</style>
|
69 |
<div class="wrap">
|
70 |
-
<h2><?php
|
71 |
<div class="notice notice-warning">
|
72 |
<p>
|
73 |
-
<?php
|
|
|
74 |
</p>
|
75 |
</div>
|
76 |
<p>
|
77 |
-
<?php
|
|
|
78 |
</p>
|
79 |
-
<h3><?php
|
80 |
-
|
|
|
81 |
<div class="sweep-message"></div>
|
82 |
<table class="widefat table-sweep">
|
83 |
<thead>
|
84 |
<tr>
|
85 |
-
<th class="col-sweep-details"><?php
|
86 |
-
<th class="col-sweep-count"><?php
|
87 |
-
<th class="col-sweep-percent"><?php
|
88 |
-
<th class="col-sweep-action"><?php
|
89 |
</tr>
|
90 |
</thead>
|
91 |
<tbody>
|
92 |
<tr>
|
93 |
<td>
|
94 |
-
<strong><?php
|
95 |
<p class="sweep-details" style="display: none;"></p>
|
96 |
</td>
|
97 |
<td>
|
98 |
-
<span class="sweep-count"><?php echo number_format_i18n( $revisions ); ?></span>
|
99 |
</td>
|
100 |
<td>
|
101 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $revisions, $total_posts ); ?></span>
|
102 |
</td>
|
103 |
<td>
|
104 |
-
<?php if ( ! empty( $revisions ) ) :
|
105 |
-
<button data-action="sweep" data-sweep_name="revisions" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_revisions' ); ?>" class="button button-primary btn-sweep"><?php
|
106 |
-
<button data-action="sweep_details" data-sweep_name="revisions" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_revisions' ); ?>" class="button btn-sweep-details"><?php
|
107 |
<?php else : ?>
|
108 |
-
<?php
|
109 |
<?php endif; ?>
|
110 |
</td>
|
111 |
</tr>
|
112 |
<tr class="alternate">
|
113 |
<td>
|
114 |
-
<strong><?php
|
115 |
<p class="sweep-details" style="display: none;"></p>
|
116 |
</td>
|
117 |
<td>
|
118 |
-
<span class="sweep-count"><?php echo number_format_i18n( $auto_drafts ); ?></span>
|
119 |
</td>
|
120 |
<td>
|
121 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $auto_drafts, $total_posts ); ?></span>
|
122 |
</td>
|
123 |
<td>
|
124 |
-
<?php if ( ! empty( $auto_drafts ) ) :
|
125 |
-
<button data-action="sweep" data-sweep_name="auto_drafts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_auto_drafts' ); ?>" class="button button-primary btn-sweep"><?php
|
126 |
-
<button data-action="sweep_details" data-sweep_name="auto_drafts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_auto_drafts' ); ?>" class="button btn-sweep-details"><?php
|
127 |
<?php else : ?>
|
128 |
-
<?php
|
129 |
<?php endif; ?>
|
130 |
</td>
|
131 |
</tr>
|
132 |
<tr>
|
133 |
<td>
|
134 |
-
<strong><?php
|
135 |
<p class="sweep-details" style="display: none;"></p>
|
136 |
</td>
|
137 |
<td>
|
138 |
-
<span class="sweep-count"><?php echo number_format_i18n( $deleted_posts ); ?></span>
|
139 |
</td>
|
140 |
<td>
|
141 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $deleted_posts, $total_posts ); ?></span>
|
142 |
</td>
|
143 |
<td>
|
144 |
-
<?php if ( ! empty( $deleted_posts ) ) :
|
145 |
-
<button data-action="sweep" data-sweep_name="deleted_posts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_deleted_posts' ); ?>" class="button button-primary btn-sweep"><?php
|
146 |
-
<button data-action="sweep_details" data-sweep_name="deleted_posts" data-sweep_type="posts" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_deleted_posts' ); ?>" class="button btn-sweep-details"><?php
|
147 |
<?php else : ?>
|
148 |
-
<?php
|
149 |
<?php endif; ?>
|
150 |
</td>
|
151 |
</tr>
|
152 |
<tr class="alternate">
|
153 |
<td>
|
154 |
-
<strong><?php
|
155 |
<p class="sweep-details" style="display: none;"></p>
|
156 |
</td>
|
157 |
<td>
|
158 |
-
<span class="sweep-count"><?php echo number_format_i18n( $orphan_postmeta ); ?></span>
|
159 |
</td>
|
160 |
<td>
|
161 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_postmeta, $total_postmeta ); ?></span>
|
162 |
</td>
|
163 |
<td>
|
164 |
-
<?php if ( ! empty( $orphan_postmeta ) ) :
|
165 |
-
<button data-action="sweep" data-sweep_name="orphan_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_postmeta' ); ?>" class="button button-primary btn-sweep"><?php
|
166 |
-
<button data-action="sweep_details" data-sweep_name="orphan_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_postmeta' ); ?>" class="button btn-sweep-details"><?php
|
167 |
<?php else : ?>
|
168 |
-
<?php
|
169 |
<?php endif; ?>
|
170 |
</td>
|
171 |
</tr>
|
172 |
<tr>
|
173 |
<td>
|
174 |
-
<strong><?php
|
175 |
<p class="sweep-details" style="display: none;"></p>
|
176 |
</td>
|
177 |
<td>
|
178 |
-
<span class="sweep-count"><?php echo number_format_i18n( $duplicated_postmeta ); ?></span>
|
179 |
</td>
|
180 |
<td>
|
181 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_postmeta, $total_postmeta ); ?></span>
|
182 |
</td>
|
183 |
<td>
|
184 |
-
<?php if ( ! empty( $duplicated_postmeta ) ) :
|
185 |
-
<button data-action="sweep" data-sweep_name="duplicated_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_postmeta' ); ?>" class="button button-primary btn-sweep"><?php
|
186 |
-
<button data-action="sweep_details" data-sweep_name="duplicated_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_postmeta' ); ?>" class="button btn-sweep-details"><?php
|
187 |
<?php else : ?>
|
188 |
-
<?php
|
189 |
<?php endif; ?>
|
190 |
</td>
|
191 |
</tr>
|
192 |
<tr class="alternate">
|
193 |
<td>
|
194 |
-
<strong><?php
|
195 |
<p class="sweep-details" style="display: none;"></p>
|
196 |
</td>
|
197 |
<td>
|
198 |
-
<span class="sweep-count"><?php echo number_format_i18n( $oembed_postmeta ); ?></span>
|
199 |
</td>
|
200 |
<td>
|
201 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $oembed_postmeta, $total_postmeta ); ?></span>
|
202 |
</td>
|
203 |
<td>
|
204 |
-
<?php if ( ! empty( $oembed_postmeta ) ) :
|
205 |
-
<button data-action="sweep" data-sweep_name="oembed_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_oembed_postmeta' ); ?>" class="button button-primary btn-sweep"><?php
|
206 |
-
<button data-action="sweep_details" data-sweep_name="oembed_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_oembed_postmeta' ); ?>" class="button btn-sweep-details"><?php
|
207 |
<?php else : ?>
|
208 |
-
<?php
|
209 |
<?php endif; ?>
|
210 |
</td>
|
211 |
</tr>
|
@@ -213,116 +221,117 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
213 |
</table>
|
214 |
<?php do_action( 'wp_sweep_admin_post_sweep' ); ?>
|
215 |
<p> </p>
|
216 |
-
<h3><?php
|
217 |
-
|
|
|
218 |
<div class="sweep-message"></div>
|
219 |
<table class="widefat table-sweep">
|
220 |
<thead>
|
221 |
<tr>
|
222 |
-
<th class="col-sweep-details"><?php
|
223 |
-
<th class="col-sweep-count"><?php
|
224 |
-
<th class="col-sweep-percent"><?php
|
225 |
-
<th class="col-sweep-action"><?php
|
226 |
</tr>
|
227 |
</thead>
|
228 |
<tbody>
|
229 |
<tr>
|
230 |
<td>
|
231 |
-
<strong><?php
|
232 |
<p class="sweep-details" style="display: none;"></p>
|
233 |
</td>
|
234 |
<td>
|
235 |
-
<span class="sweep-count"><?php echo number_format_i18n( $unapproved_comments ); ?></span>
|
236 |
</td>
|
237 |
<td>
|
238 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $unapproved_comments, $total_comments ); ?></span>
|
239 |
</td>
|
240 |
<td>
|
241 |
-
<?php if ( ! empty( $unapproved_comments ) ) :
|
242 |
-
<button data-action="sweep" data-sweep_name="unapproved_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_unapproved_comments' ); ?>" class="button button-primary btn-sweep"><?php
|
243 |
-
<button data-action="sweep_details" data-sweep_name="unapproved_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_unapproved_comments' ); ?>" class="button btn-sweep-details"><?php
|
244 |
<?php else : ?>
|
245 |
-
<?php
|
246 |
<?php endif; ?>
|
247 |
</td>
|
248 |
</tr>
|
249 |
<tr class="alternate">
|
250 |
<td>
|
251 |
-
<strong><?php
|
252 |
<p class="sweep-details" style="display: none;"></p>
|
253 |
</td>
|
254 |
<td>
|
255 |
-
<span class="sweep-count"><?php echo number_format_i18n( $spam_comments ); ?></span>
|
256 |
</td>
|
257 |
<td>
|
258 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $spam_comments, $total_comments ); ?></span>
|
259 |
</td>
|
260 |
<td>
|
261 |
-
<?php if ( ! empty( $spam_comments ) ) :
|
262 |
-
<button data-action="sweep" data-sweep_name="spam_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_spam_comments' ); ?>" class="button button-primary btn-sweep"><?php
|
263 |
-
<button data-action="sweep_details" data-sweep_name="spam_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_spam_comments' ); ?>" class="button btn-sweep-details"><?php
|
264 |
<?php else : ?>
|
265 |
-
<?php
|
266 |
<?php endif; ?>
|
267 |
</td>
|
268 |
</tr>
|
269 |
<tr>
|
270 |
<td>
|
271 |
-
<strong><?php
|
272 |
<p class="sweep-details" style="display: none;"></p>
|
273 |
</td>
|
274 |
<td>
|
275 |
-
<span class="sweep-count"><?php echo number_format_i18n( $deleted_comments ); ?></span>
|
276 |
</td>
|
277 |
<td>
|
278 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $deleted_comments, $total_comments ); ?></span>
|
279 |
</td>
|
280 |
<td>
|
281 |
-
<?php if ( ! empty( $deleted_comments ) ) :
|
282 |
-
<button data-action="sweep" data-sweep_name="deleted_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_deleted_comments' ); ?>" class="button button-primary btn-sweep"><?php
|
283 |
-
<button data-action="sweep_details" data-sweep_name="deleted_comments" data-sweep_type="comments" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_deleted_comments' ); ?>" class="button btn-sweep-details"><?php
|
284 |
<?php else : ?>
|
285 |
-
<?php
|
286 |
<?php endif; ?>
|
287 |
</td>
|
288 |
</tr>
|
289 |
<tr class="alternate">
|
290 |
<td>
|
291 |
-
<strong><?php
|
292 |
<p class="sweep-details" style="display: none;"></p>
|
293 |
</td>
|
294 |
<td>
|
295 |
-
<span class="sweep-count"><?php echo number_format_i18n( $orphan_commentmeta ); ?></span>
|
296 |
</td>
|
297 |
<td>
|
298 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_commentmeta, $total_commentmeta ); ?></span>
|
299 |
</td>
|
300 |
<td>
|
301 |
-
<?php if ( ! empty( $orphan_commentmeta ) ) :
|
302 |
-
<button data-action="sweep" data-sweep_name="orphan_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_commentmeta' ); ?>" class="button button-primary btn-sweep"><?php
|
303 |
-
<button data-action="sweep_details" data-sweep_name="orphan_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_commentmeta' ); ?>" class="button btn-sweep-details"><?php
|
304 |
<?php else : ?>
|
305 |
-
<?php
|
306 |
<?php endif; ?>
|
307 |
</td>
|
308 |
</tr>
|
309 |
<tr>
|
310 |
<td>
|
311 |
-
<strong><?php
|
312 |
<p class="sweep-details" style="display: none;"></p>
|
313 |
</td>
|
314 |
<td>
|
315 |
-
<span class="sweep-count"><?php echo number_format_i18n( $duplicated_commentmeta ); ?></span>
|
316 |
</td>
|
317 |
<td>
|
318 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_commentmeta, $total_commentmeta ); ?></span>
|
319 |
</td>
|
320 |
<td>
|
321 |
-
<?php if ( ! empty( $duplicated_commentmeta ) ) :
|
322 |
-
<button data-action="sweep" data-sweep_name="duplicated_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_commentmeta' ); ?>" class="button button-primary btn-sweep"><?php
|
323 |
-
<button data-action="sweep_details" data-sweep_name="duplicated_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_commentmeta' ); ?>" class="button btn-sweep-details"><?php
|
324 |
<?php else : ?>
|
325 |
-
<?php
|
326 |
<?php endif; ?>
|
327 |
</td>
|
328 |
</tr>
|
@@ -330,56 +339,57 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
330 |
</table>
|
331 |
<?php do_action( 'wp_sweep_admin_comment_sweep' ); ?>
|
332 |
<p> </p>
|
333 |
-
<h3><?php
|
334 |
-
|
|
|
335 |
<div class="sweep-message"></div>
|
336 |
<table class="widefat table-sweep">
|
337 |
<thead>
|
338 |
<tr>
|
339 |
-
<th class="col-sweep-details"><?php
|
340 |
-
<th class="col-sweep-count"><?php
|
341 |
-
<th class="col-sweep-percent"><?php
|
342 |
-
<th class="col-sweep-action"><?php
|
343 |
</tr>
|
344 |
</thead>
|
345 |
<tbody>
|
346 |
<tr>
|
347 |
<td>
|
348 |
-
<strong><?php
|
349 |
<p class="sweep-details" style="display: none;"></p>
|
350 |
</td>
|
351 |
<td>
|
352 |
-
<span class="sweep-count"><?php echo number_format_i18n( $orphan_usermeta ); ?></span>
|
353 |
</td>
|
354 |
<td>
|
355 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_usermeta, $total_usermeta ); ?></span>
|
356 |
</td>
|
357 |
<td>
|
358 |
-
<?php if ( ! empty( $orphan_usermeta ) ) :
|
359 |
-
<button data-action="sweep" data-sweep_name="orphan_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_usermeta' ); ?>" class="button button-primary btn-sweep"><?php
|
360 |
-
<button data-action="sweep_details" data-sweep_name="orphan_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_usermeta' ); ?>" class="button btn-sweep-details"><?php
|
361 |
<?php else : ?>
|
362 |
-
<?php
|
363 |
<?php endif; ?>
|
364 |
</td>
|
365 |
</tr>
|
366 |
<tr class="alternate">
|
367 |
<td>
|
368 |
-
<strong><?php
|
369 |
<p class="sweep-details" style="display: none;"></p>
|
370 |
</td>
|
371 |
<td>
|
372 |
-
<span class="sweep-count"><?php echo number_format_i18n( $duplicated_usermeta ); ?></span>
|
373 |
</td>
|
374 |
<td>
|
375 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_usermeta, $total_usermeta ); ?></span>
|
376 |
</td>
|
377 |
<td>
|
378 |
-
<?php if ( ! empty( $duplicated_usermeta ) ) :
|
379 |
-
<button data-action="sweep" data-sweep_name="duplicated_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_usermeta' ); ?>" class="button button-primary btn-sweep"><?php
|
380 |
-
<button data-action="sweep_details" data-sweep_name="duplicated_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_usermeta' ); ?>" class="button btn-sweep-details"><?php
|
381 |
<?php else : ?>
|
382 |
-
<?php
|
383 |
<?php endif; ?>
|
384 |
</td>
|
385 |
</tr>
|
@@ -387,97 +397,98 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
387 |
</table>
|
388 |
<?php do_action( 'wp_sweep_admin_user_sweep' ); ?>
|
389 |
<p> </p>
|
390 |
-
<h3><?php
|
391 |
-
|
|
|
392 |
<div class="sweep-message"></div>
|
393 |
<table class="widefat table-sweep">
|
394 |
<thead>
|
395 |
<tr>
|
396 |
-
<th class="col-sweep-details"><?php
|
397 |
-
<th class="col-sweep-count"><?php
|
398 |
-
<th class="col-sweep-percent"><?php
|
399 |
-
<th class="col-sweep-action"><?php
|
400 |
</tr>
|
401 |
</thead>
|
402 |
<tbody>
|
403 |
<tr>
|
404 |
<td>
|
405 |
-
<strong><?php
|
406 |
<p class="sweep-details" style="display: none;"></p>
|
407 |
</td>
|
408 |
<td>
|
409 |
-
<span class="sweep-count"><?php echo number_format_i18n( $orphan_termmeta ); ?></span>
|
410 |
</td>
|
411 |
<td>
|
412 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_termmeta, $total_termmeta ); ?></span>
|
413 |
</td>
|
414 |
<td>
|
415 |
-
<?php if ( ! empty( $orphan_termmeta ) ) :
|
416 |
-
<button data-action="sweep" data-sweep_name="orphan_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_termmeta' ); ?>" class="button button-primary btn-sweep"><?php
|
417 |
-
<button data-action="sweep_details" data-sweep_name="orphan_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_termmeta' ); ?>" class="button btn-sweep-details"><?php
|
418 |
<?php else : ?>
|
419 |
-
<?php
|
420 |
<?php endif; ?>
|
421 |
</td>
|
422 |
</tr>
|
423 |
<tr class="alternate">
|
424 |
<td>
|
425 |
-
<strong><?php
|
426 |
<p class="sweep-details" style="display: none;"></p>
|
427 |
</td>
|
428 |
<td>
|
429 |
-
<span class="sweep-count"><?php echo number_format_i18n( $duplicated_termmeta ); ?></span>
|
430 |
</td>
|
431 |
<td>
|
432 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $duplicated_termmeta, $total_termmeta ); ?></span>
|
433 |
</td>
|
434 |
<td>
|
435 |
-
<?php if ( ! empty( $duplicated_termmeta ) ) :
|
436 |
-
<button data-action="sweep" data-sweep_name="duplicated_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_duplicated_termmeta' ); ?>" class="button button-primary btn-sweep"><?php
|
437 |
-
<button data-action="sweep_details" data-sweep_name="duplicated_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_duplicated_termmeta' ); ?>" class="button btn-sweep-details"><?php
|
438 |
<?php else : ?>
|
439 |
-
<?php
|
440 |
<?php endif; ?>
|
441 |
</td>
|
442 |
</tr>
|
443 |
<tr>
|
444 |
<td>
|
445 |
-
<strong><?php
|
446 |
<p class="sweep-details" style="display: none;"></p>
|
447 |
</td>
|
448 |
<td>
|
449 |
-
<span class="sweep-count"><?php echo number_format_i18n( $orphan_term_relationships ); ?></span>
|
450 |
</td>
|
451 |
<td>
|
452 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $orphan_term_relationships, $total_term_relationships ); ?></span>
|
453 |
</td>
|
454 |
<td>
|
455 |
-
<?php if ( ! empty( $orphan_term_relationships ) ) :
|
456 |
-
<button data-action="sweep" data-sweep_name="orphan_term_relationships" data-sweep_type="term_relationships" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_orphan_term_relationships' ); ?>" class="button button-primary btn-sweep"><?php
|
457 |
-
<button data-action="sweep_details" data-sweep_name="orphan_term_relationships" data-sweep_type="term_relationships" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_orphan_term_relationships' ); ?>" class="button btn-sweep-details"><?php
|
458 |
<?php else : ?>
|
459 |
-
<?php
|
460 |
<?php endif; ?>
|
461 |
</td>
|
462 |
</tr>
|
463 |
<tr class="alternate">
|
464 |
<td>
|
465 |
-
<strong><?php
|
466 |
-
<p><?php
|
467 |
<p class="sweep-details" style="display: none;"></p>
|
468 |
</td>
|
469 |
<td>
|
470 |
-
<span class="sweep-count"><?php echo number_format_i18n( $unused_terms ); ?></span>
|
471 |
</td>
|
472 |
<td>
|
473 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $unused_terms, $total_terms ); ?></span>
|
474 |
</td>
|
475 |
<td>
|
476 |
-
<?php if ( ! empty( $unused_terms ) ) :
|
477 |
-
<button data-action="sweep" data-sweep_name="unused_terms" data-sweep_type="terms" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_unused_terms' ); ?>" class="button button-primary btn-sweep"><?php
|
478 |
-
<button data-action="sweep_details" data-sweep_name="unused_terms" data-sweep_type="terms" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_unused_terms' ); ?>" class="button btn-sweep-details"><?php
|
479 |
<?php else : ?>
|
480 |
-
<?php
|
481 |
<?php endif; ?>
|
482 |
</td>
|
483 |
</tr>
|
@@ -485,36 +496,37 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
485 |
</table>
|
486 |
<?php do_action( 'wp_sweep_admin_term_sweep' ); ?>
|
487 |
<p> </p>
|
488 |
-
<h3><?php
|
489 |
-
|
|
|
490 |
<div class="sweep-message"></div>
|
491 |
<table class="widefat table-sweep">
|
492 |
<thead>
|
493 |
<tr>
|
494 |
-
<th class="col-sweep-details"><?php
|
495 |
-
<th class="col-sweep-count"><?php
|
496 |
-
<th class="col-sweep-percent"><?php
|
497 |
-
<th class="col-sweep-action"><?php
|
498 |
</tr>
|
499 |
</thead>
|
500 |
<tbody>
|
501 |
<tr>
|
502 |
<td>
|
503 |
-
<strong><?php
|
504 |
<p class="sweep-details" style="display: none;"></p>
|
505 |
</td>
|
506 |
<td>
|
507 |
-
<span class="sweep-count"><?php echo number_format_i18n( $transient_options ); ?></span>
|
508 |
</td>
|
509 |
<td>
|
510 |
-
<span class="sweep-percentage"><?php echo WPSweep::get_instance()->format_percentage( $transient_options, $total_options ); ?></span>
|
511 |
</td>
|
512 |
<td>
|
513 |
-
<?php if ( ! empty( $transient_options ) ) :
|
514 |
-
<button data-action="sweep" data-sweep_name="transient_options" data-sweep_type="options" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_transient_options' ); ?>" class="button button-primary btn-sweep"><?php
|
515 |
-
<button data-action="sweep_details" data-sweep_name="transient_options" data-sweep_type="options" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_transient_options' ); ?>" class="button btn-sweep-details"><?php
|
516 |
<?php else : ?>
|
517 |
-
<?php
|
518 |
<?php endif; ?>
|
519 |
</td>
|
520 |
</tr>
|
@@ -522,36 +534,37 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
522 |
</table>
|
523 |
<?php do_action( 'wp_sweep_admin_option_sweep' ); ?>
|
524 |
<p> </p>
|
525 |
-
<h3><?php
|
526 |
-
|
|
|
527 |
<div class="sweep-message"></div>
|
528 |
<table class="widefat table-sweep">
|
529 |
<thead>
|
530 |
<tr>
|
531 |
-
<th class="col-sweep-details"><?php
|
532 |
-
<th class="col-sweep-count"><?php
|
533 |
-
<th class="col-sweep-percent"><?php
|
534 |
-
<th class="col-sweep-action"><?php
|
535 |
</tr>
|
536 |
</thead>
|
537 |
<tbody>
|
538 |
<tr>
|
539 |
<td>
|
540 |
-
<strong><?php
|
541 |
<p class="sweep-details" style="display: none;"></p>
|
542 |
</td>
|
543 |
<td>
|
544 |
-
<span class="sweep-count"><?php echo number_format_i18n( $total_tables ); ?></span>
|
545 |
</td>
|
546 |
<td>
|
547 |
-
<?php
|
548 |
</td>
|
549 |
<td>
|
550 |
-
<?php if ( ! empty( $total_tables ) ) :
|
551 |
-
<button data-action="sweep" data-sweep_name="optimize_database" data-sweep_type="tables" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_optimize_database' ); ?>" class="button button-primary btn-sweep"><?php
|
552 |
-
<button data-action="sweep_details" data-sweep_name="optimize_database" data-sweep_type="tables" data-nonce="<?php echo wp_create_nonce( 'wp_sweep_details_optimize_database' ); ?>" class="button btn-sweep-details"><?php
|
553 |
<?php else : ?>
|
554 |
-
<?php
|
555 |
<?php endif; ?>
|
556 |
</td>
|
557 |
</tr>
|
@@ -559,11 +572,11 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
559 |
</table>
|
560 |
<?php do_action( 'wp_sweep_admin_database_sweep' ); ?>
|
561 |
<p> </p>
|
562 |
-
<h3><?php
|
563 |
-
<p><?php
|
564 |
<div class="sweep-all">
|
565 |
<p style="text-align: center;">
|
566 |
-
<button class="button button-primary btn-sweep-all"><?php
|
567 |
</p>
|
568 |
</div>
|
569 |
</div>
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* WP-Sweep admin.php
|
4 |
+
*
|
5 |
+
* @package wp-sweep
|
6 |
+
*/
|
7 |
|
8 |
+
// Exit if accessed directly.
|
9 |
if ( ! defined( 'ABSPATH' ) ) {
|
10 |
exit;
|
11 |
}
|
12 |
|
13 |
+
// Variables.
|
14 |
$current_page = admin_url( 'tools.php?page=' . plugin_basename( 'wp-sweep/admin.php' ) );
|
15 |
+
$message = '';
|
16 |
|
17 |
+
// Sweeping.
|
18 |
if ( ! empty( $_GET['sweep'] ) ) {
|
19 |
if ( check_admin_referer( 'wp_sweep_' . $_GET['sweep'] ) ) {
|
20 |
$message = WPSweep::get_instance()->sweep( $_GET['sweep'] );
|
21 |
}
|
22 |
}
|
23 |
|
24 |
+
// Database Table Status.
|
25 |
+
$total_posts = WPSweep::get_instance()->total_count( 'posts' );
|
26 |
+
$total_postmeta = WPSweep::get_instance()->total_count( 'postmeta' );
|
27 |
+
$total_comments = WPSweep::get_instance()->total_count( 'comments' );
|
28 |
+
$total_commentmeta = WPSweep::get_instance()->total_count( 'commentmeta' );
|
29 |
+
$total_users = WPSweep::get_instance()->total_count( 'users' );
|
30 |
+
$total_usermeta = WPSweep::get_instance()->total_count( 'usermeta' );
|
31 |
+
$total_term_relationships = WPSweep::get_instance()->total_count( 'term_relationships' );
|
32 |
+
$total_term_taxonomy = WPSweep::get_instance()->total_count( 'term_taxonomy' );
|
33 |
+
$total_terms = WPSweep::get_instance()->total_count( 'terms' );
|
34 |
+
$total_termmeta = WPSweep::get_instance()->total_count( 'termmeta' );
|
35 |
+
$total_options = WPSweep::get_instance()->total_count( 'options' );
|
36 |
+
$total_tables = WPSweep::get_instance()->total_count( 'tables' );
|
37 |
|
38 |
+
// Count.
|
39 |
+
$revisions = WPSweep::get_instance()->count( 'revisions' );
|
40 |
+
$auto_drafts = WPSweep::get_instance()->count( 'auto_drafts' );
|
41 |
+
$deleted_posts = WPSweep::get_instance()->count( 'deleted_posts' );
|
42 |
+
$orphan_postmeta = WPSweep::get_instance()->count( 'orphan_postmeta' );
|
43 |
+
$duplicated_postmeta = WPSweep::get_instance()->count( 'duplicated_postmeta' );
|
44 |
+
$oembed_postmeta = WPSweep::get_instance()->count( 'oembed_postmeta' );
|
45 |
|
46 |
+
$unapproved_comments = WPSweep::get_instance()->count( 'unapproved_comments' );
|
47 |
+
$spam_comments = WPSweep::get_instance()->count( 'spam_comments' );
|
48 |
+
$deleted_comments = WPSweep::get_instance()->count( 'deleted_comments' );
|
49 |
+
$orphan_commentmeta = WPSweep::get_instance()->count( 'orphan_commentmeta' );
|
50 |
+
$duplicated_commentmeta = WPSweep::get_instance()->count( 'duplicated_commentmeta' );
|
51 |
|
52 |
+
$orphan_usermeta = WPSweep::get_instance()->count( 'orphan_usermeta' );
|
53 |
+
$duplicated_usermeta = WPSweep::get_instance()->count( 'duplicated_usermeta' );
|
54 |
|
55 |
+
$orphan_term_relationships = WPSweep::get_instance()->count( 'orphan_term_relationships' );
|
56 |
+
$unused_terms = WPSweep::get_instance()->count( 'unused_terms' );
|
57 |
+
$orphan_termmeta = WPSweep::get_instance()->count( 'orphan_termmeta' );
|
58 |
+
$duplicated_termmeta = WPSweep::get_instance()->count( 'duplicated_termmeta' );
|
59 |
|
60 |
+
$transient_options = WPSweep::get_instance()->count( 'transient_options' );
|
61 |
|
62 |
?>
|
63 |
<style type="text/css">
|
72 |
}
|
73 |
</style>
|
74 |
<div class="wrap">
|
75 |
+
<h2><?php esc_html_e( 'WP-Sweep', 'wp-sweep' ); ?></h2>
|
76 |
<div class="notice notice-warning">
|
77 |
<p>
|
78 |
+
<?php /* translators: %1 WP-DBManager Plugin URL, %2 _blank to open new window */ ?>
|
79 |
+
<?php echo wp_kses_post( sprintf( __( 'Before you do any sweep, please <a href="%1$s" target="%2$s">backup your database</a> first because any sweep done is irreversible.', 'wp-sweep' ), 'https://wordpress.org/plugins/wp-dbmanager/', '_blank' ) ); ?>
|
80 |
</p>
|
81 |
</div>
|
82 |
<p>
|
83 |
+
<?php /* translators: %s maximum number of results */ ?>
|
84 |
+
<?php echo esc_html( sprintf( __( 'For performance reasons, only %s items will be shown if you click Details.', 'wp-sweep' ), number_format_i18n( WPSweep::get_instance()->limit_details ) ) ); ?>
|
85 |
</p>
|
86 |
+
<h3><?php esc_html_e( 'Post Sweep', 'wp-sweep' ); ?></h3>
|
87 |
+
<?php /* translators: %1 is the number of posts, %2 is the number of post meta */ ?>
|
88 |
+
<p><?php echo wp_kses_post( sprintf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-posts">%1$s</span> Posts</strong> and <strong class="attention"><span class="sweep-count-type-postmeta">%2$s</span> Post Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_posts ), number_format_i18n( $total_postmeta ) ) ); ?></p>
|
89 |
<div class="sweep-message"></div>
|
90 |
<table class="widefat table-sweep">
|
91 |
<thead>
|
92 |
<tr>
|
93 |
+
<th class="col-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></th>
|
94 |
+
<th class="col-sweep-count"><?php esc_html_e( 'Count', 'wp-sweep' ); ?></th>
|
95 |
+
<th class="col-sweep-percent"><?php esc_html_e( '% Of', 'wp-sweep' ); ?></th>
|
96 |
+
<th class="col-sweep-action"><?php esc_html_e( 'Action', 'wp-sweep' ); ?></th>
|
97 |
</tr>
|
98 |
</thead>
|
99 |
<tbody>
|
100 |
<tr>
|
101 |
<td>
|
102 |
+
<strong><?php esc_html_e( 'Revisions', 'wp-sweep' ); ?></strong>
|
103 |
<p class="sweep-details" style="display: none;"></p>
|
104 |
</td>
|
105 |
<td>
|
106 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $revisions ) ); ?></span>
|
107 |
</td>
|
108 |
<td>
|
109 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $revisions, $total_posts ) ); ?></span>
|
110 |
</td>
|
111 |
<td>
|
112 |
+
<?php if ( ! empty( $revisions ) ) : ?>
|
113 |
+
<button data-action="sweep" data-sweep_name="revisions" data-sweep_type="posts" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_revisions' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
114 |
+
<button data-action="sweep_details" data-sweep_name="revisions" data-sweep_type="posts" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_revisions' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
115 |
<?php else : ?>
|
116 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
117 |
<?php endif; ?>
|
118 |
</td>
|
119 |
</tr>
|
120 |
<tr class="alternate">
|
121 |
<td>
|
122 |
+
<strong><?php esc_html_e( 'Auto Drafts', 'wp-sweep' ); ?></strong>
|
123 |
<p class="sweep-details" style="display: none;"></p>
|
124 |
</td>
|
125 |
<td>
|
126 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $auto_drafts ) ); ?></span>
|
127 |
</td>
|
128 |
<td>
|
129 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $auto_drafts, $total_posts ) ); ?></span>
|
130 |
</td>
|
131 |
<td>
|
132 |
+
<?php if ( ! empty( $auto_drafts ) ) : ?>
|
133 |
+
<button data-action="sweep" data-sweep_name="auto_drafts" data-sweep_type="posts" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_auto_drafts' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
134 |
+
<button data-action="sweep_details" data-sweep_name="auto_drafts" data-sweep_type="posts" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_auto_drafts' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
135 |
<?php else : ?>
|
136 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
137 |
<?php endif; ?>
|
138 |
</td>
|
139 |
</tr>
|
140 |
<tr>
|
141 |
<td>
|
142 |
+
<strong><?php esc_html_e( 'Deleted Posts', 'wp-sweep' ); ?></strong>
|
143 |
<p class="sweep-details" style="display: none;"></p>
|
144 |
</td>
|
145 |
<td>
|
146 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $deleted_posts ) ); ?></span>
|
147 |
</td>
|
148 |
<td>
|
149 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $deleted_posts, $total_posts ) ); ?></span>
|
150 |
</td>
|
151 |
<td>
|
152 |
+
<?php if ( ! empty( $deleted_posts ) ) : ?>
|
153 |
+
<button data-action="sweep" data-sweep_name="deleted_posts" data-sweep_type="posts" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_deleted_posts' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
154 |
+
<button data-action="sweep_details" data-sweep_name="deleted_posts" data-sweep_type="posts" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_deleted_posts' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
155 |
<?php else : ?>
|
156 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
157 |
<?php endif; ?>
|
158 |
</td>
|
159 |
</tr>
|
160 |
<tr class="alternate">
|
161 |
<td>
|
162 |
+
<strong><?php esc_html_e( 'Orphaned Post Meta', 'wp-sweep' ); ?></strong>
|
163 |
<p class="sweep-details" style="display: none;"></p>
|
164 |
</td>
|
165 |
<td>
|
166 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $orphan_postmeta ) ); ?></span>
|
167 |
</td>
|
168 |
<td>
|
169 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $orphan_postmeta, $total_postmeta ) ); ?></span>
|
170 |
</td>
|
171 |
<td>
|
172 |
+
<?php if ( ! empty( $orphan_postmeta ) ) : ?>
|
173 |
+
<button data-action="sweep" data-sweep_name="orphan_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_orphan_postmeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
174 |
+
<button data-action="sweep_details" data-sweep_name="orphan_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_orphan_postmeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
175 |
<?php else : ?>
|
176 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
177 |
<?php endif; ?>
|
178 |
</td>
|
179 |
</tr>
|
180 |
<tr>
|
181 |
<td>
|
182 |
+
<strong><?php esc_html_e( 'Duplicated Post Meta', 'wp-sweep' ); ?></strong>
|
183 |
<p class="sweep-details" style="display: none;"></p>
|
184 |
</td>
|
185 |
<td>
|
186 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $duplicated_postmeta ) ); ?></span>
|
187 |
</td>
|
188 |
<td>
|
189 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $duplicated_postmeta, $total_postmeta ) ); ?></span>
|
190 |
</td>
|
191 |
<td>
|
192 |
+
<?php if ( ! empty( $duplicated_postmeta ) ) : ?>
|
193 |
+
<button data-action="sweep" data-sweep_name="duplicated_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_duplicated_postmeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
194 |
+
<button data-action="sweep_details" data-sweep_name="duplicated_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_duplicated_postmeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
195 |
<?php else : ?>
|
196 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
197 |
<?php endif; ?>
|
198 |
</td>
|
199 |
</tr>
|
200 |
<tr class="alternate">
|
201 |
<td>
|
202 |
+
<strong><?php esc_html_e( 'oEmbed Caches In Post Meta', 'wp-sweep' ); ?></strong>
|
203 |
<p class="sweep-details" style="display: none;"></p>
|
204 |
</td>
|
205 |
<td>
|
206 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $oembed_postmeta ) ); ?></span>
|
207 |
</td>
|
208 |
<td>
|
209 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $oembed_postmeta, $total_postmeta ) ); ?></span>
|
210 |
</td>
|
211 |
<td>
|
212 |
+
<?php if ( ! empty( $oembed_postmeta ) ) : ?>
|
213 |
+
<button data-action="sweep" data-sweep_name="oembed_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_oembed_postmeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
214 |
+
<button data-action="sweep_details" data-sweep_name="oembed_postmeta" data-sweep_type="postmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_oembed_postmeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
215 |
<?php else : ?>
|
216 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
217 |
<?php endif; ?>
|
218 |
</td>
|
219 |
</tr>
|
221 |
</table>
|
222 |
<?php do_action( 'wp_sweep_admin_post_sweep' ); ?>
|
223 |
<p> </p>
|
224 |
+
<h3><?php esc_html_e( 'Comment Sweep', 'wp-sweep' ); ?></h3>
|
225 |
+
<?php /* translators: %1 is the number of comments, %2 is the number of comment meta */ ?>
|
226 |
+
<p><?php echo wp_kses_post( sprintf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-comments">%1$s</span> Comments</strong> and <strong class="attention"><span class="sweep-count-type-commentmeta">%2$s</span> Comment Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_comments ), number_format_i18n( $total_commentmeta ) ) ); ?></p>
|
227 |
<div class="sweep-message"></div>
|
228 |
<table class="widefat table-sweep">
|
229 |
<thead>
|
230 |
<tr>
|
231 |
+
<th class="col-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></th>
|
232 |
+
<th class="col-sweep-count"><?php esc_html_e( 'Count', 'wp-sweep' ); ?></th>
|
233 |
+
<th class="col-sweep-percent"><?php esc_html_e( '% Of', 'wp-sweep' ); ?></th>
|
234 |
+
<th class="col-sweep-action"><?php esc_html_e( 'Action', 'wp-sweep' ); ?></th>
|
235 |
</tr>
|
236 |
</thead>
|
237 |
<tbody>
|
238 |
<tr>
|
239 |
<td>
|
240 |
+
<strong><?php esc_html_e( 'Unapproved Comments', 'wp-sweep' ); ?></strong>
|
241 |
<p class="sweep-details" style="display: none;"></p>
|
242 |
</td>
|
243 |
<td>
|
244 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $unapproved_comments ) ); ?></span>
|
245 |
</td>
|
246 |
<td>
|
247 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $unapproved_comments, $total_comments ) ); ?></span>
|
248 |
</td>
|
249 |
<td>
|
250 |
+
<?php if ( ! empty( $unapproved_comments ) ) : ?>
|
251 |
+
<button data-action="sweep" data-sweep_name="unapproved_comments" data-sweep_type="comments" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_unapproved_comments' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
252 |
+
<button data-action="sweep_details" data-sweep_name="unapproved_comments" data-sweep_type="comments" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_unapproved_comments' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
253 |
<?php else : ?>
|
254 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
255 |
<?php endif; ?>
|
256 |
</td>
|
257 |
</tr>
|
258 |
<tr class="alternate">
|
259 |
<td>
|
260 |
+
<strong><?php esc_html_e( 'Spammed Comments', 'wp-sweep' ); ?></strong>
|
261 |
<p class="sweep-details" style="display: none;"></p>
|
262 |
</td>
|
263 |
<td>
|
264 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $spam_comments ) ); ?></span>
|
265 |
</td>
|
266 |
<td>
|
267 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $spam_comments, $total_comments ) ); ?></span>
|
268 |
</td>
|
269 |
<td>
|
270 |
+
<?php if ( ! empty( $spam_comments ) ) : ?>
|
271 |
+
<button data-action="sweep" data-sweep_name="spam_comments" data-sweep_type="comments" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_spam_comments' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
272 |
+
<button data-action="sweep_details" data-sweep_name="spam_comments" data-sweep_type="comments" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_spam_comments' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
273 |
<?php else : ?>
|
274 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
275 |
<?php endif; ?>
|
276 |
</td>
|
277 |
</tr>
|
278 |
<tr>
|
279 |
<td>
|
280 |
+
<strong><?php esc_html_e( 'Deleted Comments', 'wp-sweep' ); ?></strong>
|
281 |
<p class="sweep-details" style="display: none;"></p>
|
282 |
</td>
|
283 |
<td>
|
284 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $deleted_comments ) ); ?></span>
|
285 |
</td>
|
286 |
<td>
|
287 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $deleted_comments, $total_comments ) ); ?></span>
|
288 |
</td>
|
289 |
<td>
|
290 |
+
<?php if ( ! empty( $deleted_comments ) ) : ?>
|
291 |
+
<button data-action="sweep" data-sweep_name="deleted_comments" data-sweep_type="comments" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_deleted_comments' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
292 |
+
<button data-action="sweep_details" data-sweep_name="deleted_comments" data-sweep_type="comments" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_deleted_comments' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
293 |
<?php else : ?>
|
294 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
295 |
<?php endif; ?>
|
296 |
</td>
|
297 |
</tr>
|
298 |
<tr class="alternate">
|
299 |
<td>
|
300 |
+
<strong><?php esc_html_e( 'Orphaned Comment Meta', 'wp-sweep' ); ?></strong>
|
301 |
<p class="sweep-details" style="display: none;"></p>
|
302 |
</td>
|
303 |
<td>
|
304 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $orphan_commentmeta ) ); ?></span>
|
305 |
</td>
|
306 |
<td>
|
307 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $orphan_commentmeta, $total_commentmeta ) ); ?></span>
|
308 |
</td>
|
309 |
<td>
|
310 |
+
<?php if ( ! empty( $orphan_commentmeta ) ) : ?>
|
311 |
+
<button data-action="sweep" data-sweep_name="orphan_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_orphan_commentmeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
312 |
+
<button data-action="sweep_details" data-sweep_name="orphan_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_orphan_commentmeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
313 |
<?php else : ?>
|
314 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
315 |
<?php endif; ?>
|
316 |
</td>
|
317 |
</tr>
|
318 |
<tr>
|
319 |
<td>
|
320 |
+
<strong><?php esc_html_e( 'Duplicated Comment Meta', 'wp-sweep' ); ?></strong>
|
321 |
<p class="sweep-details" style="display: none;"></p>
|
322 |
</td>
|
323 |
<td>
|
324 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $duplicated_commentmeta ) ); ?></span>
|
325 |
</td>
|
326 |
<td>
|
327 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $duplicated_commentmeta, $total_commentmeta ) ); ?></span>
|
328 |
</td>
|
329 |
<td>
|
330 |
+
<?php if ( ! empty( $duplicated_commentmeta ) ) : ?>
|
331 |
+
<button data-action="sweep" data-sweep_name="duplicated_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_duplicated_commentmeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
332 |
+
<button data-action="sweep_details" data-sweep_name="duplicated_commentmeta" data-sweep_type="commentmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_duplicated_commentmeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
333 |
<?php else : ?>
|
334 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
335 |
<?php endif; ?>
|
336 |
</td>
|
337 |
</tr>
|
339 |
</table>
|
340 |
<?php do_action( 'wp_sweep_admin_comment_sweep' ); ?>
|
341 |
<p> </p>
|
342 |
+
<h3><?php esc_html_e( 'User Sweep', 'wp-sweep' ); ?></h3>
|
343 |
+
<?php /* translators: %1 is the number of users, %2 is the number of user meta */ ?>
|
344 |
+
<p><?php echo wp_kses_post( sprintf( __( 'There are a total of <strong class="attention"><span class="sweep-count-type-users">%1$s</span> Users</strong> and <strong class="attention"><span class="sweep-count-type-usermeta">%2$s</span> User Meta</strong>.', 'wp-sweep' ), number_format_i18n( $total_users ), number_format_i18n( $total_usermeta ) ) ); ?></p>
|
345 |
<div class="sweep-message"></div>
|
346 |
<table class="widefat table-sweep">
|
347 |
<thead>
|
348 |
<tr>
|
349 |
+
<th class="col-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></th>
|
350 |
+
<th class="col-sweep-count"><?php esc_html_e( 'Count', 'wp-sweep' ); ?></th>
|
351 |
+
<th class="col-sweep-percent"><?php esc_html_e( '% Of', 'wp-sweep' ); ?></th>
|
352 |
+
<th class="col-sweep-action"><?php esc_html_e( 'Action', 'wp-sweep' ); ?></th>
|
353 |
</tr>
|
354 |
</thead>
|
355 |
<tbody>
|
356 |
<tr>
|
357 |
<td>
|
358 |
+
<strong><?php esc_html_e( 'Orphaned User Meta', 'wp-sweep' ); ?></strong>
|
359 |
<p class="sweep-details" style="display: none;"></p>
|
360 |
</td>
|
361 |
<td>
|
362 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $orphan_usermeta ) ); ?></span>
|
363 |
</td>
|
364 |
<td>
|
365 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $orphan_usermeta, $total_usermeta ) ); ?></span>
|
366 |
</td>
|
367 |
<td>
|
368 |
+
<?php if ( ! empty( $orphan_usermeta ) ) : ?>
|
369 |
+
<button data-action="sweep" data-sweep_name="orphan_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_orphan_usermeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
370 |
+
<button data-action="sweep_details" data-sweep_name="orphan_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_orphan_usermeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
371 |
<?php else : ?>
|
372 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
373 |
<?php endif; ?>
|
374 |
</td>
|
375 |
</tr>
|
376 |
<tr class="alternate">
|
377 |
<td>
|
378 |
+
<strong><?php esc_html_e( 'Duplicated User Meta', 'wp-sweep' ); ?></strong>
|
379 |
<p class="sweep-details" style="display: none;"></p>
|
380 |
</td>
|
381 |
<td>
|
382 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $duplicated_usermeta ) ); ?></span>
|
383 |
</td>
|
384 |
<td>
|
385 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $duplicated_usermeta, $total_usermeta ) ); ?></span>
|
386 |
</td>
|
387 |
<td>
|
388 |
+
<?php if ( ! empty( $duplicated_usermeta ) ) : ?>
|
389 |
+
<button data-action="sweep" data-sweep_name="duplicated_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_duplicated_usermeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
390 |
+
<button data-action="sweep_details" data-sweep_name="duplicated_usermeta" data-sweep_type="usermeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_duplicated_usermeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
391 |
<?php else : ?>
|
392 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
393 |
<?php endif; ?>
|
394 |
</td>
|
395 |
</tr>
|
397 |
</table>
|
398 |
<?php do_action( 'wp_sweep_admin_user_sweep' ); ?>
|
399 |
<p> </p>
|
400 |
+
<h3><?php esc_html_e( 'Term Sweep', 'wp-sweep' ); ?></h3>
|
401 |
+
<?php /* translators: %1 is the number of terms, %2 is the number of term meta */ ?>
|
402 |
+
<p><?php echo wp_kses_post( sprintf( __( 'There are a total of <strong class="attention "><span class="sweep-count-type-terms">%1$s</span> Terms</strong>, <strong class="attention "><span class="sweep-count-type-termmeta">%2$s</span> Term Meta</strong>, <strong class="attention"><span class="sweep-count-type-term_taxonomy">%3$s</span> Term Taxonomy</strong> and <strong class="attention"><span class="sweep-count-type-term_relationships">%4$s</span> Term Relationships</strong>.', 'wp-sweep' ), number_format_i18n( $total_terms ), number_format_i18n( $total_termmeta ), number_format_i18n( $total_term_taxonomy ), number_format_i18n( $total_term_relationships ) ) ); ?></p>
|
403 |
<div class="sweep-message"></div>
|
404 |
<table class="widefat table-sweep">
|
405 |
<thead>
|
406 |
<tr>
|
407 |
+
<th class="col-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></th>
|
408 |
+
<th class="col-sweep-count"><?php esc_html_e( 'Count', 'wp-sweep' ); ?></th>
|
409 |
+
<th class="col-sweep-percent"><?php esc_html_e( '% Of', 'wp-sweep' ); ?></th>
|
410 |
+
<th class="col-sweep-action"><?php esc_html_e( 'Action', 'wp-sweep' ); ?></th>
|
411 |
</tr>
|
412 |
</thead>
|
413 |
<tbody>
|
414 |
<tr>
|
415 |
<td>
|
416 |
+
<strong><?php esc_html_e( 'Orphaned Term Meta', 'wp-sweep' ); ?></strong>
|
417 |
<p class="sweep-details" style="display: none;"></p>
|
418 |
</td>
|
419 |
<td>
|
420 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $orphan_termmeta ) ); ?></span>
|
421 |
</td>
|
422 |
<td>
|
423 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $orphan_termmeta, $total_termmeta ) ); ?></span>
|
424 |
</td>
|
425 |
<td>
|
426 |
+
<?php if ( ! empty( $orphan_termmeta ) ) : ?>
|
427 |
+
<button data-action="sweep" data-sweep_name="orphan_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_orphan_termmeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
428 |
+
<button data-action="sweep_details" data-sweep_name="orphan_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_orphan_termmeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
429 |
<?php else : ?>
|
430 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
431 |
<?php endif; ?>
|
432 |
</td>
|
433 |
</tr>
|
434 |
<tr class="alternate">
|
435 |
<td>
|
436 |
+
<strong><?php esc_html_e( 'Duplicated Term Meta', 'wp-sweep' ); ?></strong>
|
437 |
<p class="sweep-details" style="display: none;"></p>
|
438 |
</td>
|
439 |
<td>
|
440 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $duplicated_termmeta ) ); ?></span>
|
441 |
</td>
|
442 |
<td>
|
443 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $duplicated_termmeta, $total_termmeta ) ); ?></span>
|
444 |
</td>
|
445 |
<td>
|
446 |
+
<?php if ( ! empty( $duplicated_termmeta ) ) : ?>
|
447 |
+
<button data-action="sweep" data-sweep_name="duplicated_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_duplicated_termmeta' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
448 |
+
<button data-action="sweep_details" data-sweep_name="duplicated_termmeta" data-sweep_type="termmeta" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_duplicated_termmeta' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
449 |
<?php else : ?>
|
450 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
451 |
<?php endif; ?>
|
452 |
</td>
|
453 |
</tr>
|
454 |
<tr>
|
455 |
<td>
|
456 |
+
<strong><?php esc_html_e( 'Orphaned Term Relationship', 'wp-sweep' ); ?></strong>
|
457 |
<p class="sweep-details" style="display: none;"></p>
|
458 |
</td>
|
459 |
<td>
|
460 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $orphan_term_relationships ) ); ?></span>
|
461 |
</td>
|
462 |
<td>
|
463 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $orphan_term_relationships, $total_term_relationships ) ); ?></span>
|
464 |
</td>
|
465 |
<td>
|
466 |
+
<?php if ( ! empty( $orphan_term_relationships ) ) : ?>
|
467 |
+
<button data-action="sweep" data-sweep_name="orphan_term_relationships" data-sweep_type="term_relationships" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_orphan_term_relationships' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
468 |
+
<button data-action="sweep_details" data-sweep_name="orphan_term_relationships" data-sweep_type="term_relationships" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_orphan_term_relationships' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
469 |
<?php else : ?>
|
470 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
471 |
<?php endif; ?>
|
472 |
</td>
|
473 |
</tr>
|
474 |
<tr class="alternate">
|
475 |
<td>
|
476 |
+
<strong><?php esc_html_e( 'Unused Terms', 'wp-sweep' ); ?></strong>
|
477 |
+
<p><?php esc_html_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>
|
478 |
<p class="sweep-details" style="display: none;"></p>
|
479 |
</td>
|
480 |
<td>
|
481 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $unused_terms ) ); ?></span>
|
482 |
</td>
|
483 |
<td>
|
484 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $unused_terms, $total_terms ) ); ?></span>
|
485 |
</td>
|
486 |
<td>
|
487 |
+
<?php if ( ! empty( $unused_terms ) ) : ?>
|
488 |
+
<button data-action="sweep" data-sweep_name="unused_terms" data-sweep_type="terms" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_unused_terms' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
489 |
+
<button data-action="sweep_details" data-sweep_name="unused_terms" data-sweep_type="terms" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_unused_terms' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
490 |
<?php else : ?>
|
491 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
492 |
<?php endif; ?>
|
493 |
</td>
|
494 |
</tr>
|
496 |
</table>
|
497 |
<?php do_action( 'wp_sweep_admin_term_sweep' ); ?>
|
498 |
<p> </p>
|
499 |
+
<h3><?php esc_html_e( 'Option Sweep', 'wp-sweep' ); ?></h3>
|
500 |
+
<?php /* translators: %1 is the number of options */ ?>
|
501 |
+
<p><?php echo wp_kses_post( sprintf( __( '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>
|
502 |
<div class="sweep-message"></div>
|
503 |
<table class="widefat table-sweep">
|
504 |
<thead>
|
505 |
<tr>
|
506 |
+
<th class="col-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></th>
|
507 |
+
<th class="col-sweep-count"><?php esc_html_e( 'Count', 'wp-sweep' ); ?></th>
|
508 |
+
<th class="col-sweep-percent"><?php esc_html_e( '% Of', 'wp-sweep' ); ?></th>
|
509 |
+
<th class="col-sweep-action"><?php esc_html_e( 'Action', 'wp-sweep' ); ?></th>
|
510 |
</tr>
|
511 |
</thead>
|
512 |
<tbody>
|
513 |
<tr>
|
514 |
<td>
|
515 |
+
<strong><?php esc_html_e( 'Transient Options', 'wp-sweep' ); ?></strong>
|
516 |
<p class="sweep-details" style="display: none;"></p>
|
517 |
</td>
|
518 |
<td>
|
519 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $transient_options ) ); ?></span>
|
520 |
</td>
|
521 |
<td>
|
522 |
+
<span class="sweep-percentage"><?php echo esc_html( WPSweep::get_instance()->format_percentage( $transient_options, $total_options ) ); ?></span>
|
523 |
</td>
|
524 |
<td>
|
525 |
+
<?php if ( ! empty( $transient_options ) ) : ?>
|
526 |
+
<button data-action="sweep" data-sweep_name="transient_options" data-sweep_type="options" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_transient_options' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
527 |
+
<button data-action="sweep_details" data-sweep_name="transient_options" data-sweep_type="options" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_transient_options' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
528 |
<?php else : ?>
|
529 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
530 |
<?php endif; ?>
|
531 |
</td>
|
532 |
</tr>
|
534 |
</table>
|
535 |
<?php do_action( 'wp_sweep_admin_option_sweep' ); ?>
|
536 |
<p> </p>
|
537 |
+
<h3><?php esc_html_e( 'Database Sweep', 'wp-sweep' ); ?></h3>
|
538 |
+
<?php /* translators: %1 is the number of database tables */ ?>
|
539 |
+
<p><?php echo wp_kses_post( sprintf( __( '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>
|
540 |
<div class="sweep-message"></div>
|
541 |
<table class="widefat table-sweep">
|
542 |
<thead>
|
543 |
<tr>
|
544 |
+
<th class="col-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></th>
|
545 |
+
<th class="col-sweep-count"><?php esc_html_e( 'Count', 'wp-sweep' ); ?></th>
|
546 |
+
<th class="col-sweep-percent"><?php esc_html_e( '% Of', 'wp-sweep' ); ?></th>
|
547 |
+
<th class="col-sweep-action"><?php esc_html_e( 'Action', 'wp-sweep' ); ?></th>
|
548 |
</tr>
|
549 |
</thead>
|
550 |
<tbody>
|
551 |
<tr>
|
552 |
<td>
|
553 |
+
<strong><?php esc_html_e( 'Optimize Tables', 'wp-sweep' ); ?></strong>
|
554 |
<p class="sweep-details" style="display: none;"></p>
|
555 |
</td>
|
556 |
<td>
|
557 |
+
<span class="sweep-count"><?php echo esc_html( number_format_i18n( $total_tables ) ); ?></span>
|
558 |
</td>
|
559 |
<td>
|
560 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
561 |
</td>
|
562 |
<td>
|
563 |
+
<?php if ( ! empty( $total_tables ) ) : ?>
|
564 |
+
<button data-action="sweep" data-sweep_name="optimize_database" data-sweep_type="tables" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_optimize_database' ) ); ?>" class="button button-primary btn-sweep"><?php esc_html_e( 'Sweep', 'wp-sweep' ); ?></button>
|
565 |
+
<button data-action="sweep_details" data-sweep_name="optimize_database" data-sweep_type="tables" data-nonce="<?php echo esc_attr( wp_create_nonce( 'wp_sweep_details_optimize_database' ) ); ?>" class="button btn-sweep-details"><?php esc_html_e( 'Details', 'wp-sweep' ); ?></button>
|
566 |
<?php else : ?>
|
567 |
+
<?php esc_html_e( 'N/A', 'wp-sweep' ); ?>
|
568 |
<?php endif; ?>
|
569 |
</td>
|
570 |
</tr>
|
572 |
</table>
|
573 |
<?php do_action( 'wp_sweep_admin_database_sweep' ); ?>
|
574 |
<p> </p>
|
575 |
+
<h3><?php esc_html_e( 'Sweep All', 'wp-sweep' ); ?></h3>
|
576 |
+
<p><?php esc_html_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>
|
577 |
<div class="sweep-all">
|
578 |
<p style="text-align: center;">
|
579 |
+
<button class="button button-primary btn-sweep-all"><?php esc_html_e( 'Sweep All', 'wp-sweep' ); ?></button>
|
580 |
</p>
|
581 |
</div>
|
582 |
</div>
|
composer.json
CHANGED
@@ -11,8 +11,16 @@
|
|
11 |
}
|
12 |
],
|
13 |
"license" : "GPL-2.0+",
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
"require": {
|
15 |
-
"php": ">=5.
|
16 |
-
|
|
|
|
|
17 |
}
|
18 |
}
|
11 |
}
|
12 |
],
|
13 |
"license" : "GPL-2.0+",
|
14 |
+
"repositories": [
|
15 |
+
{
|
16 |
+
"type": "vcs",
|
17 |
+
"url": "git@github.com:techinasia/WordPress-Coding-Standards.git"
|
18 |
+
}
|
19 |
+
],
|
20 |
"require": {
|
21 |
+
"php": ">=5.4.0"
|
22 |
+
},
|
23 |
+
"require-dev": {
|
24 |
+
"wp-coding-standards/wpcs": "dev-develop"
|
25 |
}
|
26 |
}
|
composer.lock
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_readme": [
|
3 |
+
"This file locks the dependencies of your project to a known state",
|
4 |
+
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
5 |
+
"This file is @generated automatically"
|
6 |
+
],
|
7 |
+
"content-hash": "b4fb02c188443d529694b8f83ca80300",
|
8 |
+
"packages": [],
|
9 |
+
"packages-dev": [
|
10 |
+
{
|
11 |
+
"name": "squizlabs/php_codesniffer",
|
12 |
+
"version": "3.3.2",
|
13 |
+
"source": {
|
14 |
+
"type": "git",
|
15 |
+
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
|
16 |
+
"reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e"
|
17 |
+
},
|
18 |
+
"dist": {
|
19 |
+
"type": "zip",
|
20 |
+
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e",
|
21 |
+
"reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e",
|
22 |
+
"shasum": ""
|
23 |
+
},
|
24 |
+
"require": {
|
25 |
+
"ext-simplexml": "*",
|
26 |
+
"ext-tokenizer": "*",
|
27 |
+
"ext-xmlwriter": "*",
|
28 |
+
"php": ">=5.4.0"
|
29 |
+
},
|
30 |
+
"require-dev": {
|
31 |
+
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
|
32 |
+
},
|
33 |
+
"bin": [
|
34 |
+
"bin/phpcs",
|
35 |
+
"bin/phpcbf"
|
36 |
+
],
|
37 |
+
"type": "library",
|
38 |
+
"extra": {
|
39 |
+
"branch-alias": {
|
40 |
+
"dev-master": "3.x-dev"
|
41 |
+
}
|
42 |
+
},
|
43 |
+
"notification-url": "https://packagist.org/downloads/",
|
44 |
+
"license": [
|
45 |
+
"BSD-3-Clause"
|
46 |
+
],
|
47 |
+
"authors": [
|
48 |
+
{
|
49 |
+
"name": "Greg Sherwood",
|
50 |
+
"role": "lead"
|
51 |
+
}
|
52 |
+
],
|
53 |
+
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
|
54 |
+
"homepage": "http://www.squizlabs.com/php-codesniffer",
|
55 |
+
"keywords": [
|
56 |
+
"phpcs",
|
57 |
+
"standards"
|
58 |
+
],
|
59 |
+
"time": "2018-09-23T23:08:17+00:00"
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"name": "wp-coding-standards/wpcs",
|
63 |
+
"version": "dev-develop",
|
64 |
+
"source": {
|
65 |
+
"type": "git",
|
66 |
+
"url": "https://github.com/techinasia/WordPress-Coding-Standards.git",
|
67 |
+
"reference": "bb4cb53e0e1e6510bb2be0afb2bd2079fd47220b"
|
68 |
+
},
|
69 |
+
"dist": {
|
70 |
+
"type": "zip",
|
71 |
+
"url": "https://api.github.com/repos/techinasia/WordPress-Coding-Standards/zipball/bb4cb53e0e1e6510bb2be0afb2bd2079fd47220b",
|
72 |
+
"reference": "bb4cb53e0e1e6510bb2be0afb2bd2079fd47220b",
|
73 |
+
"shasum": ""
|
74 |
+
},
|
75 |
+
"require": {
|
76 |
+
"php": ">=5.3",
|
77 |
+
"squizlabs/php_codesniffer": "^2.9.0 || ^3.0.2"
|
78 |
+
},
|
79 |
+
"suggest": {
|
80 |
+
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3"
|
81 |
+
},
|
82 |
+
"type": "phpcodesniffer-standard",
|
83 |
+
"scripts": {
|
84 |
+
"post-install-cmd": [
|
85 |
+
"\"vendor/bin/phpcs\" --config-set installed_paths ../../.."
|
86 |
+
],
|
87 |
+
"post-update-cmd": [
|
88 |
+
"\"vendor/bin/phpcs\" --config-set installed_paths ../../.."
|
89 |
+
]
|
90 |
+
},
|
91 |
+
"license": [
|
92 |
+
"MIT"
|
93 |
+
],
|
94 |
+
"authors": [
|
95 |
+
{
|
96 |
+
"name": "Contributors",
|
97 |
+
"homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors"
|
98 |
+
}
|
99 |
+
],
|
100 |
+
"description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions",
|
101 |
+
"keywords": [
|
102 |
+
"WordPress",
|
103 |
+
"phpcs",
|
104 |
+
"standards"
|
105 |
+
],
|
106 |
+
"support": {
|
107 |
+
"issues": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues",
|
108 |
+
"wiki": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki",
|
109 |
+
"source": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards"
|
110 |
+
},
|
111 |
+
"time": "2018-03-14T07:49:12+00:00"
|
112 |
+
}
|
113 |
+
],
|
114 |
+
"aliases": [],
|
115 |
+
"minimum-stability": "stable",
|
116 |
+
"stability-flags": {
|
117 |
+
"wp-coding-standards/wpcs": 20
|
118 |
+
},
|
119 |
+
"prefer-stable": false,
|
120 |
+
"prefer-lowest": false,
|
121 |
+
"platform": {
|
122 |
+
"php": ">=5.4.0"
|
123 |
+
},
|
124 |
+
"platform-dev": []
|
125 |
+
}
|
inc/class-wpsweep-api.php
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WP-Sweep WP-API
|
4 |
+
*
|
5 |
+
* @package wp-sweep
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class WPSweep_Api
|
10 |
+
*/
|
11 |
+
class WPSweep_Api {
|
12 |
+
/**
|
13 |
+
* WP-Sweep WP Rest API namespace
|
14 |
+
*
|
15 |
+
* @var string
|
16 |
+
*/
|
17 |
+
private $namespace = 'sweep/v1';
|
18 |
+
|
19 |
+
/**
|
20 |
+
* List of sweeps
|
21 |
+
*
|
22 |
+
* @var array
|
23 |
+
*/
|
24 |
+
private $sweeps = array(
|
25 |
+
'revisions',
|
26 |
+
'auto_drafts',
|
27 |
+
'deleted_posts',
|
28 |
+
'unapproved_comments',
|
29 |
+
'spam_comments',
|
30 |
+
'deleted_comments',
|
31 |
+
'transient_options',
|
32 |
+
'orphan_postmeta',
|
33 |
+
'orphan_commentmeta',
|
34 |
+
'orphan_usermeta',
|
35 |
+
'orphan_termmeta',
|
36 |
+
'orphan_term_relationships',
|
37 |
+
'unused_terms',
|
38 |
+
'duplicated_postmeta',
|
39 |
+
'duplicated_commentmeta',
|
40 |
+
'duplicated_usermeta',
|
41 |
+
'duplicated_termmeta',
|
42 |
+
'optimize_database',
|
43 |
+
'oembed_postmeta',
|
44 |
+
);
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Register WP-Sweep API Routes
|
48 |
+
*
|
49 |
+
* @since 1.1.0
|
50 |
+
*
|
51 |
+
* @access public
|
52 |
+
* @return void
|
53 |
+
*/
|
54 |
+
public function __construct() {
|
55 |
+
add_action( 'rest_api_init', function() {
|
56 |
+
register_rest_route( $this->namespace, 'count/(?P<name>\w+)', array(
|
57 |
+
'methods' => WP_REST_Server::READABLE,
|
58 |
+
'callback' => array( $this, 'count' ),
|
59 |
+
'permission_callback' => array( $this, 'permission_check' ),
|
60 |
+
'args' => array(
|
61 |
+
'name' => array(
|
62 |
+
'required' => true,
|
63 |
+
'validate_callback' => array( $this, 'is_sweep_name_valid' ),
|
64 |
+
),
|
65 |
+
),
|
66 |
+
));
|
67 |
+
register_rest_route( $this->namespace, 'details/(?P<name>\w+)', array(
|
68 |
+
'methods' => WP_REST_Server::READABLE,
|
69 |
+
'callback' => array( $this, 'details' ),
|
70 |
+
'permission_callback' => array( $this, 'permission_check' ),
|
71 |
+
'args' => array(
|
72 |
+
'name' => array(
|
73 |
+
'required' => true,
|
74 |
+
'validate_callback' => array( $this, 'is_sweep_name_valid' ),
|
75 |
+
),
|
76 |
+
),
|
77 |
+
));
|
78 |
+
register_rest_route( $this->namespace, 'sweep/(?P<name>\w+)', array(
|
79 |
+
'methods' => WP_REST_Server::DELETABLE,
|
80 |
+
'callback' => array( $this, 'sweep' ),
|
81 |
+
'permission_callback' => array( $this, 'permission_check' ),
|
82 |
+
'args' => array(
|
83 |
+
'name' => array(
|
84 |
+
'required' => true,
|
85 |
+
'validate_callback' => array( $this, 'is_sweep_name_valid' ),
|
86 |
+
),
|
87 |
+
),
|
88 |
+
));
|
89 |
+
});
|
90 |
+
}
|
91 |
+
/**
|
92 |
+
* Sweep item count
|
93 |
+
*
|
94 |
+
* @since 1.1.0
|
95 |
+
*
|
96 |
+
* @access public
|
97 |
+
* @param WP_REST_Request $request Request.
|
98 |
+
* @return WP_REST_Response
|
99 |
+
*/
|
100 |
+
public function count( $request ) {
|
101 |
+
$params = $request->get_params();
|
102 |
+
|
103 |
+
$sweep = new WPSweep();
|
104 |
+
$count = (int) $sweep->count( $params['name'] );
|
105 |
+
|
106 |
+
return new WP_REST_Response( array(
|
107 |
+
'name' => $params['name'],
|
108 |
+
'count' => $count,
|
109 |
+
) );
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Sweep details
|
114 |
+
*
|
115 |
+
* @since 1.1.0
|
116 |
+
*
|
117 |
+
* @access public
|
118 |
+
* @param WP_REST_Request $request Request.
|
119 |
+
* @return WP_REST_Response
|
120 |
+
*/
|
121 |
+
public function details( $request ) {
|
122 |
+
$params = $request->get_params();
|
123 |
+
|
124 |
+
$sweep = new WPSweep();
|
125 |
+
$details = $sweep->details( $params['name'] );
|
126 |
+
|
127 |
+
return new WP_REST_Response( array(
|
128 |
+
'name' => $params['name'],
|
129 |
+
'count' => count( $details ),
|
130 |
+
'data' => $details,
|
131 |
+
) );
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Lets do the sweeping
|
136 |
+
*
|
137 |
+
* @since 1.1.0
|
138 |
+
*
|
139 |
+
* @access public
|
140 |
+
* @param WP_REST_Request $request Request.
|
141 |
+
* @return WP_REST_Response
|
142 |
+
*/
|
143 |
+
public function sweep( $request ) {
|
144 |
+
$params = $request->get_params();
|
145 |
+
|
146 |
+
$sweep = new WPSweep();
|
147 |
+
$results = $sweep->sweep( $params['name'] );
|
148 |
+
|
149 |
+
return new WP_REST_Response( array(
|
150 |
+
'success' => ! empty( $results ),
|
151 |
+
'name' => $params['name'],
|
152 |
+
'message' => empty( $results ) ? __( 'No items left to sweep.', 'wp-sweep' ) : $results,
|
153 |
+
) );
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Check whether a sweep is valid
|
158 |
+
*
|
159 |
+
* @since 1.1.0
|
160 |
+
*
|
161 |
+
* @access public
|
162 |
+
* @param string $name Sweep name.
|
163 |
+
* @return bool Is the sweep name valid?
|
164 |
+
*/
|
165 |
+
public function is_sweep_name_valid( $name ) {
|
166 |
+
return in_array( $name, $this->sweeps, true );
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Check whether the function is allowed to be run. Must have either capabilities to enact action, or a valid nonce.
|
171 |
+
*
|
172 |
+
* @since 1.1.0
|
173 |
+
*
|
174 |
+
* @access public
|
175 |
+
* @return bool Does the user has access to sweep?
|
176 |
+
*/
|
177 |
+
public function permission_check() {
|
178 |
+
return current_user_can( 'manage_options' );
|
179 |
+
}
|
180 |
+
}
|
class-command.php → inc/class-wpsweep-command.php
RENAMED
@@ -1,5 +1,13 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
3 |
class WPSweep_Command extends WP_CLI_Command {
|
4 |
/**
|
5 |
* Clean up unused, orphaned and duplicated data in your WordPress
|
@@ -11,37 +19,43 @@ class WPSweep_Command extends WP_CLI_Command {
|
|
11 |
*
|
12 |
* Name of the items selected individually
|
13 |
* Available Items =
|
14 |
-
*
|
15 |
-
*
|
16 |
-
*
|
17 |
-
*
|
18 |
-
*
|
19 |
-
*
|
20 |
-
*
|
21 |
-
*
|
22 |
-
*
|
23 |
-
*
|
24 |
-
*
|
25 |
-
*
|
26 |
-
*
|
27 |
-
*
|
28 |
-
*
|
29 |
-
*
|
30 |
-
*
|
31 |
-
*
|
32 |
-
*
|
33 |
*
|
34 |
* ## EXAMPLES
|
35 |
*
|
36 |
* 1. wp sweep --all
|
37 |
-
*
|
38 |
* 2. wp sweep revisions
|
39 |
-
*
|
40 |
* 3. wp sweep revisions auto_drafts deleted_posts unapproved_comments spam_comments deleted_comments transient_options orphan_postmeta orphan_commentmeta orphan_usermeta orphan_termmeta orphan_term_relationships unused_terms duplicated_postmeta duplicated_commentmeta duplicated_usermeta duplicated_termmeta optimize_database oembed_postmet
|
41 |
-
*
|
42 |
*
|
|
|
43 |
*
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
45 |
public function __invoke( $args, $assoc_args ) {
|
46 |
|
47 |
$items = array();
|
@@ -68,14 +82,14 @@ class WPSweep_Command extends WP_CLI_Command {
|
|
68 |
'18' => 'oembed_postmeta',
|
69 |
);
|
70 |
|
71 |
-
if ( isset( $assoc_args['all'] ) && true
|
72 |
$this->run_sweep( $default_items );
|
73 |
WP_CLI::success( 'Sweep Complete' );
|
74 |
|
75 |
return;
|
76 |
} else {
|
77 |
foreach ( $default_items as $key => $item ) {
|
78 |
-
if ( in_array( $item, $args ) ) {
|
79 |
array_push( $items, $item );
|
80 |
}
|
81 |
}
|
@@ -88,6 +102,16 @@ class WPSweep_Command extends WP_CLI_Command {
|
|
88 |
|
89 |
}
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
public function run_sweep( $items ) {
|
92 |
|
93 |
$sweep = new WPSweep();
|
@@ -99,8 +123,5 @@ class WPSweep_Command extends WP_CLI_Command {
|
|
99 |
WP_CLI::success( $message );
|
100 |
}
|
101 |
}
|
102 |
-
|
103 |
}
|
104 |
}
|
105 |
-
|
106 |
-
WP_CLI::add_command( 'sweep', 'WPSweep_Command' );
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* WP-Sweep WP-CLI
|
4 |
+
*
|
5 |
+
* @package wp-sweep
|
6 |
+
*/
|
7 |
|
8 |
+
/**
|
9 |
+
* Class WPSweep_Command
|
10 |
+
*/
|
11 |
class WPSweep_Command extends WP_CLI_Command {
|
12 |
/**
|
13 |
* Clean up unused, orphaned and duplicated data in your WordPress
|
19 |
*
|
20 |
* Name of the items selected individually
|
21 |
* Available Items =
|
22 |
+
* revisions
|
23 |
+
* auto_drafts
|
24 |
+
* deleted_posts
|
25 |
+
* unapproved_comments
|
26 |
+
* spam_comments
|
27 |
+
* deleted_comments
|
28 |
+
* transient_options
|
29 |
+
* orphan_postmeta
|
30 |
+
* orphan_commentmeta
|
31 |
+
* orphan_usermeta
|
32 |
+
* orphan_termmeta
|
33 |
+
* orphan_term_relationships
|
34 |
+
* unused_terms
|
35 |
+
* duplicated_postmeta
|
36 |
+
* duplicated_commentmeta
|
37 |
+
* duplicated_usermeta
|
38 |
+
* duplicated_termmeta
|
39 |
+
* optimize_database
|
40 |
+
* oembed_postmeta
|
41 |
*
|
42 |
* ## EXAMPLES
|
43 |
*
|
44 |
* 1. wp sweep --all
|
45 |
+
* - Run Sweep for all the items.
|
46 |
* 2. wp sweep revisions
|
47 |
+
* - Sweep only Revision
|
48 |
* 3. wp sweep revisions auto_drafts deleted_posts unapproved_comments spam_comments deleted_comments transient_options orphan_postmeta orphan_commentmeta orphan_usermeta orphan_termmeta orphan_term_relationships unused_terms duplicated_postmeta duplicated_commentmeta duplicated_usermeta duplicated_termmeta optimize_database oembed_postmet
|
49 |
+
* - Sweep the selected items
|
50 |
*
|
51 |
+
* @since 1.0.8
|
52 |
*
|
53 |
+
* @access public
|
54 |
+
*
|
55 |
+
* @param array $args array Arguments passed to command. Generally unused.
|
56 |
+
* @param array $assoc_args Parameters passed to command to be passed to callback.
|
57 |
+
* @return void
|
58 |
+
*/
|
59 |
public function __invoke( $args, $assoc_args ) {
|
60 |
|
61 |
$items = array();
|
82 |
'18' => 'oembed_postmeta',
|
83 |
);
|
84 |
|
85 |
+
if ( isset( $assoc_args['all'] ) && true === $assoc_args['all'] ) {
|
86 |
$this->run_sweep( $default_items );
|
87 |
WP_CLI::success( 'Sweep Complete' );
|
88 |
|
89 |
return;
|
90 |
} else {
|
91 |
foreach ( $default_items as $key => $item ) {
|
92 |
+
if ( in_array( $item, $args, true ) ) {
|
93 |
array_push( $items, $item );
|
94 |
}
|
95 |
}
|
102 |
|
103 |
}
|
104 |
|
105 |
+
/**
|
106 |
+
* Run WP-Sweep
|
107 |
+
*
|
108 |
+
* @since 1.0.8
|
109 |
+
*
|
110 |
+
* @access public
|
111 |
+
*
|
112 |
+
* @param array $items Sweep items.
|
113 |
+
* @return void
|
114 |
+
*/
|
115 |
public function run_sweep( $items ) {
|
116 |
|
117 |
$sweep = new WPSweep();
|
123 |
WP_CLI::success( $message );
|
124 |
}
|
125 |
}
|
|
|
126 |
}
|
127 |
}
|
|
|
|
index.php
CHANGED
@@ -1,2 +1,8 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* WP-Sweep index.php
|
4 |
+
*
|
5 |
+
* @package wp-sweep
|
6 |
+
*/
|
7 |
+
|
8 |
+
// Silence is golden.
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: GamerZ
|
3 |
Donate link: https://lesterchan.net/site/donation/
|
4 |
Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term meta, term relationships, revisions, auto drafts, transient, database, tables, oembed
|
5 |
-
Requires at least: 4.
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 1.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -49,8 +49,42 @@ Following delete functions are used:
|
|
49 |
* delete_transient()
|
50 |
* delete_site_transient()
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
WP-Sweep is not compatible with the following plugins:
|
53 |
* [Meta Slider](https://wordpress.org/support/plugin/ml-slider/)
|
|
|
|
|
|
|
54 |
|
55 |
### Build Status
|
56 |
[![Build Status](https://travis-ci.org/lesterchan/wp-sweep.svg?branch=master)](https://travis-ci.org/lesterchan/wp-sweep) [![Code Climate](https://codeclimate.com/github/lesterchan/wp-sweep/badges/gpa.svg)](https://codeclimate.com/github/lesterchan/wp-sweep) [![Issue Count](https://codeclimate.com/github/lesterchan/wp-sweep/badges/issue_count.svg)](https://codeclimate.com/github/lesterchan/wp-sweep)
|
@@ -65,8 +99,12 @@ WP-Sweep is not compatible with the following plugins:
|
|
65 |
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.
|
66 |
|
67 |
## Changelog
|
|
|
|
|
|
|
|
|
68 |
### 1.0.12
|
69 |
-
*
|
70 |
* NEW: Update README to incompatible plugins
|
71 |
|
72 |
### 1.0.10
|
2 |
Contributors: GamerZ
|
3 |
Donate link: https://lesterchan.net/site/donation/
|
4 |
Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term meta, term relationships, revisions, auto drafts, transient, database, tables, oembed
|
5 |
+
Requires at least: 4.6
|
6 |
+
Tested up to: 5.0
|
7 |
+
Stable tag: 1.1.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
49 |
* delete_transient()
|
50 |
* delete_site_transient()
|
51 |
|
52 |
+
WP-Sweep WP REST API Endpoints
|
53 |
+
* `GET /wp-json/sweep/v1/count/<Name>`. Get the number of items that we will be sweeping.
|
54 |
+
* `GET /wp-json/sweep/v1/details/<Name>`. Get the details of the items that we will be sweeping.
|
55 |
+
* `DELETE /wp-json/sweep/v1/sweep/<Name>`. Runs sweep for that particular item.
|
56 |
+
|
57 |
+
WP-Sweep WP-CLI Commands
|
58 |
+
* `wp sweep --all`. Runs sweep for all items.
|
59 |
+
* `wp sweep <Name>`. Runs sweep for that particular item.
|
60 |
+
* `wp sweep <Name1> <Name2>`. Run sweep for the selected items.
|
61 |
+
|
62 |
+
WP-Sweep Available Items:
|
63 |
+
* revisions
|
64 |
+
* auto_drafts
|
65 |
+
* deleted_posts
|
66 |
+
* unapproved_comments
|
67 |
+
* spam_comments
|
68 |
+
* deleted_comments
|
69 |
+
* transient_options
|
70 |
+
* orphan_postmeta
|
71 |
+
* orphan_commentmeta
|
72 |
+
* orphan_usermeta
|
73 |
+
* orphan_termmeta
|
74 |
+
* orphan_term_relationships
|
75 |
+
* unused_terms
|
76 |
+
* duplicated_postmeta
|
77 |
+
* duplicated_commentmeta
|
78 |
+
* duplicated_usermeta
|
79 |
+
* duplicated_termmeta
|
80 |
+
* optimize_database
|
81 |
+
* oembed_postmeta
|
82 |
+
|
83 |
WP-Sweep is not compatible with the following plugins:
|
84 |
* [Meta Slider](https://wordpress.org/support/plugin/ml-slider/)
|
85 |
+
* [Slider Revolution](https://revolution.themepunch.com/)
|
86 |
+
* [Viba Portfolio](https://codecanyon.net/item/viba-portfolio-wordpress-plugin/9561599)
|
87 |
+
* [MailPress](http://www.mailpress.org/)
|
88 |
|
89 |
### Build Status
|
90 |
[![Build Status](https://travis-ci.org/lesterchan/wp-sweep.svg?branch=master)](https://travis-ci.org/lesterchan/wp-sweep) [![Code Climate](https://codeclimate.com/github/lesterchan/wp-sweep/badges/gpa.svg)](https://codeclimate.com/github/lesterchan/wp-sweep) [![Issue Count](https://codeclimate.com/github/lesterchan/wp-sweep/badges/issue_count.svg)](https://codeclimate.com/github/lesterchan/wp-sweep)
|
99 |
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.
|
100 |
|
101 |
## Changelog
|
102 |
+
### 1.1.0
|
103 |
+
* NEW: Added WP Rest API Endpoint support, `sweep/v1/count/<Name>`, `sweep/v1/details/<Name>`, and `sweep/v1/sweep/<Name>`
|
104 |
+
* FIXED: Follow as close as possible to WordPress Coding Standards
|
105 |
+
|
106 |
### 1.0.12
|
107 |
+
* NEW: Bump to WordPress 4.9
|
108 |
* NEW: Update README to incompatible plugins
|
109 |
|
110 |
### 1.0.10
|
uninstall.php
CHANGED
@@ -1,20 +1,20 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
*
|
|
|
|
|
4 |
*/
|
|
|
5 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
6 |
exit;
|
7 |
}
|
8 |
|
9 |
-
|
10 |
-
|
11 |
if ( is_multisite() ) {
|
12 |
-
$ms_sites =
|
13 |
|
14 |
-
if ( 0 <
|
15 |
foreach ( $ms_sites as $ms_site ) {
|
16 |
-
|
17 |
-
switch_to_blog( $blog_id );
|
18 |
plugin_uninstalled();
|
19 |
}
|
20 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* WP-Sweep uninstall.php
|
4 |
+
*
|
5 |
+
* @package wp-sweep
|
6 |
*/
|
7 |
+
|
8 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
9 |
exit;
|
10 |
}
|
11 |
|
|
|
|
|
12 |
if ( is_multisite() ) {
|
13 |
+
$ms_sites = get_sites();
|
14 |
|
15 |
+
if ( 0 < count( $ms_sites ) ) {
|
16 |
foreach ( $ms_sites as $ms_site ) {
|
17 |
+
switch_to_blog( $ms_site->blog_id );
|
|
|
18 |
plugin_uninstalled();
|
19 |
}
|
20 |
}
|
wp-sweep.php
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/*
|
3 |
Plugin Name: WP-Sweep
|
4 |
Plugin URI: https://lesterchan.net/portfolio/programming/php/
|
5 |
Description: WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It cleans up revisions, auto drafts, unapproved comments, spam comments, trashed comments, orphan post meta, orphan comment meta, orphan user meta, orphan term relationships, unused terms, duplicated post meta, duplicated comment meta, duplicated user meta and transient options. It also optimizes your database tables.
|
6 |
-
Version: 1.0
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: https://lesterchan.net
|
9 |
Text Domain: wp-sweep
|
@@ -11,7 +17,7 @@ License: GPL2
|
|
11 |
*/
|
12 |
|
13 |
/*
|
14 |
-
Copyright
|
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
|
@@ -32,7 +38,13 @@ License: GPL2
|
|
32 |
*
|
33 |
* @since 1.0.0
|
34 |
*/
|
35 |
-
define( 'WP_SWEEP_VERSION', '1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
/**
|
38 |
* WP-Sweep class
|
@@ -56,7 +68,7 @@ class WPSweep {
|
|
56 |
* @since 1.0.0
|
57 |
*
|
58 |
* @access private
|
59 |
-
* @var $instance
|
60 |
*/
|
61 |
private static $instance;
|
62 |
|
@@ -68,13 +80,13 @@ class WPSweep {
|
|
68 |
* @access public
|
69 |
*/
|
70 |
public function __construct() {
|
71 |
-
// Add Plugin Hooks
|
72 |
add_action( 'plugins_loaded', array( $this, 'add_hooks' ) );
|
73 |
|
74 |
-
// Load Translation
|
75 |
load_plugin_textdomain( 'wp-sweep' );
|
76 |
|
77 |
-
// Plugin Activation/Deactivation
|
78 |
register_activation_hook( __FILE__, array( $this, 'plugin_activation' ) );
|
79 |
register_deactivation_hook( __FILE__, array( $this, 'plugin_deactivation' ) );
|
80 |
}
|
@@ -103,9 +115,10 @@ class WPSweep {
|
|
103 |
* @return void
|
104 |
*/
|
105 |
public function init() {
|
106 |
-
// include class for WP CLI command
|
107 |
if ( defined( 'WP_CLI' ) ) {
|
108 |
-
require __DIR__ . '/class-command.php';
|
|
|
109 |
}
|
110 |
}
|
111 |
|
@@ -118,7 +131,7 @@ class WPSweep {
|
|
118 |
* @return void
|
119 |
*/
|
120 |
public function add_hooks() {
|
121 |
-
// Actions
|
122 |
add_action( 'init', array( $this, 'init' ) );
|
123 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
124 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
@@ -132,7 +145,7 @@ class WPSweep {
|
|
132 |
* @since 1.0.3
|
133 |
*
|
134 |
* @access public
|
135 |
-
* @param string $hook
|
136 |
* @return void
|
137 |
*/
|
138 |
public function admin_enqueue_scripts( $hook ) {
|
@@ -141,18 +154,20 @@ class WPSweep {
|
|
141 |
}
|
142 |
|
143 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
144 |
-
wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.js' ), array( 'jquery' )
|
145 |
} else {
|
146 |
-
wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.min.js' ), array( 'jquery' )
|
147 |
}
|
148 |
|
149 |
-
wp_localize_script(
|
150 |
-
'
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
156 |
}
|
157 |
|
158 |
/**
|
@@ -164,7 +179,7 @@ class WPSweep {
|
|
164 |
* @return void
|
165 |
*/
|
166 |
public function admin_menu() {
|
167 |
-
add_management_page(
|
168 |
}
|
169 |
|
170 |
|
@@ -178,16 +193,17 @@ class WPSweep {
|
|
178 |
*/
|
179 |
public function ajax_sweep_details() {
|
180 |
if ( ! empty( $_GET['action'] )
|
181 |
-
&& 'sweep_details' === $_GET['action']
|
182 |
&& ! empty( $_GET['sweep_name'] )
|
183 |
&& ! empty( $_GET['sweep_type'] )
|
184 |
) {
|
185 |
-
// Verify Referer
|
186 |
if ( ! check_admin_referer( 'wp_sweep_details_' . $_GET['sweep_name'] ) ) {
|
187 |
-
wp_send_json_error(
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
|
|
191 |
wp_send_json_success( $this->details( $_GET['sweep_name'] ) );
|
192 |
}
|
193 |
}
|
@@ -203,38 +219,53 @@ class WPSweep {
|
|
203 |
*/
|
204 |
public function ajax_sweep() {
|
205 |
if ( ! empty( $_GET['action'] )
|
206 |
-
&& 'sweep' === $_GET['action']
|
207 |
&& ! empty( $_GET['sweep_name'] )
|
208 |
&& ! empty( $_GET['sweep_type'] )
|
209 |
) {
|
210 |
-
// Verify Referer
|
211 |
if ( ! check_admin_referer( 'wp_sweep_' . $_GET['sweep_name'] ) ) {
|
212 |
-
wp_send_json_error(
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
218 |
$total_count = $this->total_count( $_GET['sweep_type'] );
|
219 |
$total_stats = array();
|
220 |
switch ( $_GET['sweep_type'] ) {
|
221 |
case 'posts':
|
222 |
case 'postmeta':
|
223 |
-
$total_stats = array(
|
|
|
|
|
|
|
224 |
break;
|
225 |
case 'comments':
|
226 |
case 'commentmeta':
|
227 |
-
$total_stats = array(
|
|
|
|
|
|
|
228 |
break;
|
229 |
case 'users':
|
230 |
case 'usermeta':
|
231 |
-
$total_stats = array(
|
|
|
|
|
|
|
232 |
break;
|
233 |
case 'term_relationships':
|
234 |
case 'term_taxonomy':
|
235 |
case 'terms':
|
236 |
case 'termmeta':
|
237 |
-
$total_stats = array(
|
|
|
|
|
|
|
|
|
|
|
238 |
break;
|
239 |
case 'options':
|
240 |
$total_stats = array( 'options' => $this->total_count( 'options' ) );
|
@@ -244,13 +275,15 @@ class WPSweep {
|
|
244 |
break;
|
245 |
}
|
246 |
|
247 |
-
wp_send_json_success(
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
254 |
}
|
255 |
}
|
256 |
}
|
@@ -261,7 +294,7 @@ class WPSweep {
|
|
261 |
* @since 1.0.0
|
262 |
*
|
263 |
* @access public
|
264 |
-
* @param string $name
|
265 |
* @return int Number of items belonging to each sweep
|
266 |
*/
|
267 |
public function total_count( $name ) {
|
@@ -304,7 +337,7 @@ class WPSweep {
|
|
304 |
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->options" );
|
305 |
break;
|
306 |
case 'tables':
|
307 |
-
$count =
|
308 |
break;
|
309 |
}
|
310 |
|
@@ -317,7 +350,7 @@ class WPSweep {
|
|
317 |
* @since 1.0.0
|
318 |
*
|
319 |
* @access public
|
320 |
-
* @param string $name
|
321 |
* @return int Number of items belonging to each sweep
|
322 |
*/
|
323 |
public function count( $name ) {
|
@@ -360,10 +393,11 @@ class WPSweep {
|
|
360 |
$count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
|
361 |
break;
|
362 |
case 'orphan_term_relationships':
|
363 |
-
$
|
|
|
364 |
break;
|
365 |
case 'unused_terms':
|
366 |
-
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(t.term_id) FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ')', 0 ) );
|
367 |
break;
|
368 |
case 'duplicated_postmeta':
|
369 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT COUNT(meta_id) AS count FROM $wpdb->postmeta GROUP BY post_id, meta_key, meta_value HAVING count > %d", 1 ) );
|
@@ -390,7 +424,7 @@ class WPSweep {
|
|
390 |
}
|
391 |
break;
|
392 |
case 'optimize_database':
|
393 |
-
$count =
|
394 |
break;
|
395 |
case 'oembed_postmeta':
|
396 |
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_id) FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
|
@@ -406,8 +440,8 @@ class WPSweep {
|
|
406 |
* @since 1.0.3
|
407 |
*
|
408 |
* @access public
|
409 |
-
* @param string $name
|
410 |
-
* @return
|
411 |
*/
|
412 |
public function details( $name ) {
|
413 |
global $wpdb;
|
@@ -449,13 +483,14 @@ class WPSweep {
|
|
449 |
$details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms) LIMIT %d", $this->limit_details ) );
|
450 |
break;
|
451 |
case 'orphan_term_relationships':
|
452 |
-
$
|
|
|
453 |
break;
|
454 |
case 'unused_terms':
|
455 |
-
$details = $wpdb->get_col( $wpdb->prepare( "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ') LIMIT %d', 0, $this->limit_details ) );
|
456 |
break;
|
457 |
case 'duplicated_postmeta':
|
458 |
-
$query
|
459 |
$details = array();
|
460 |
if ( $query ) {
|
461 |
foreach ( $query as $meta ) {
|
@@ -464,7 +499,7 @@ class WPSweep {
|
|
464 |
}
|
465 |
break;
|
466 |
case 'duplicated_commentmeta':
|
467 |
-
$query
|
468 |
$details = array();
|
469 |
if ( $query ) {
|
470 |
foreach ( $query as $meta ) {
|
@@ -473,7 +508,7 @@ class WPSweep {
|
|
473 |
}
|
474 |
break;
|
475 |
case 'duplicated_usermeta':
|
476 |
-
$query
|
477 |
$details = array();
|
478 |
if ( $query ) {
|
479 |
foreach ( $query as $meta ) {
|
@@ -482,7 +517,7 @@ class WPSweep {
|
|
482 |
}
|
483 |
break;
|
484 |
case 'duplicated_termmeta':
|
485 |
-
$query
|
486 |
$details = array();
|
487 |
if ( $query ) {
|
488 |
foreach ( $query as $meta ) {
|
@@ -507,7 +542,7 @@ class WPSweep {
|
|
507 |
* @since 1.0.0
|
508 |
*
|
509 |
* @access public
|
510 |
-
* @param string $name
|
511 |
* @return string Processed message
|
512 |
*/
|
513 |
public function sweep( $name ) {
|
@@ -520,20 +555,22 @@ class WPSweep {
|
|
520 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s", 'revision' ) );
|
521 |
if ( $query ) {
|
522 |
foreach ( $query as $id ) {
|
523 |
-
wp_delete_post_revision(
|
524 |
}
|
525 |
|
526 |
-
|
|
|
527 |
}
|
528 |
break;
|
529 |
case 'auto_drafts':
|
530 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s", 'auto-draft' ) );
|
531 |
if ( $query ) {
|
532 |
foreach ( $query as $id ) {
|
533 |
-
wp_delete_post(
|
534 |
}
|
535 |
|
536 |
-
|
|
|
537 |
}
|
538 |
break;
|
539 |
case 'deleted_posts':
|
@@ -543,37 +580,41 @@ class WPSweep {
|
|
543 |
wp_delete_post( $id, true );
|
544 |
}
|
545 |
|
546 |
-
|
|
|
547 |
}
|
548 |
break;
|
549 |
case 'unapproved_comments':
|
550 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", '0' ) );
|
551 |
if ( $query ) {
|
552 |
foreach ( $query as $id ) {
|
553 |
-
wp_delete_comment(
|
554 |
}
|
555 |
|
556 |
-
|
|
|
557 |
}
|
558 |
break;
|
559 |
case 'spam_comments':
|
560 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", 'spam' ) );
|
561 |
if ( $query ) {
|
562 |
foreach ( $query as $id ) {
|
563 |
-
wp_delete_comment(
|
564 |
}
|
565 |
|
566 |
-
|
|
|
567 |
}
|
568 |
break;
|
569 |
case 'deleted_comments':
|
570 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed' ) );
|
571 |
if ( $query ) {
|
572 |
foreach ( $query as $id ) {
|
573 |
-
wp_delete_comment(
|
574 |
}
|
575 |
|
576 |
-
|
|
|
577 |
}
|
578 |
break;
|
579 |
case 'transient_options':
|
@@ -587,14 +628,15 @@ class WPSweep {
|
|
587 |
}
|
588 |
}
|
589 |
|
590 |
-
|
|
|
591 |
}
|
592 |
break;
|
593 |
case 'orphan_postmeta':
|
594 |
$query = $wpdb->get_results( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)" );
|
595 |
if ( $query ) {
|
596 |
foreach ( $query as $meta ) {
|
597 |
-
$post_id =
|
598 |
if ( 0 === $post_id ) {
|
599 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
|
600 |
} else {
|
@@ -602,14 +644,15 @@ class WPSweep {
|
|
602 |
}
|
603 |
}
|
604 |
|
605 |
-
|
|
|
606 |
}
|
607 |
break;
|
608 |
case 'orphan_commentmeta':
|
609 |
$query = $wpdb->get_results( "SELECT comment_id, meta_key FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)" );
|
610 |
if ( $query ) {
|
611 |
foreach ( $query as $meta ) {
|
612 |
-
$comment_id =
|
613 |
if ( 0 === $comment_id ) {
|
614 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s", $comment_id, $meta->meta_key ) );
|
615 |
} else {
|
@@ -617,14 +660,15 @@ class WPSweep {
|
|
617 |
}
|
618 |
}
|
619 |
|
620 |
-
|
|
|
621 |
}
|
622 |
break;
|
623 |
case 'orphan_usermeta':
|
624 |
$query = $wpdb->get_results( "SELECT user_id, meta_key FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)" );
|
625 |
if ( $query ) {
|
626 |
foreach ( $query as $meta ) {
|
627 |
-
$user_id =
|
628 |
if ( 0 === $user_id ) {
|
629 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta->meta_key ) );
|
630 |
} else {
|
@@ -632,14 +676,15 @@ class WPSweep {
|
|
632 |
}
|
633 |
}
|
634 |
|
635 |
-
|
|
|
636 |
}
|
637 |
break;
|
638 |
case 'orphan_termmeta':
|
639 |
$query = $wpdb->get_results( "SELECT term_id, meta_key FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
|
640 |
if ( $query ) {
|
641 |
foreach ( $query as $meta ) {
|
642 |
-
$term_id =
|
643 |
if ( 0 === $term_id ) {
|
644 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE term_id = %d AND meta_key = %s", $term_id, $meta->meta_key ) );
|
645 |
} else {
|
@@ -647,40 +692,43 @@ class WPSweep {
|
|
647 |
}
|
648 |
}
|
649 |
|
650 |
-
|
|
|
651 |
}
|
652 |
break;
|
653 |
case 'orphan_term_relationships':
|
654 |
-
$query = $wpdb->get_results( "SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode( '\',\'', $this->get_excluded_taxonomies() ) . "') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" );
|
655 |
if ( $query ) {
|
656 |
foreach ( $query as $tax ) {
|
657 |
-
$wp_remove_object_terms = wp_remove_object_terms(
|
658 |
if ( true !== $wp_remove_object_terms ) {
|
659 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $tax->object_id, $tax->term_taxonomy_id ) );
|
660 |
}
|
661 |
}
|
662 |
|
663 |
-
|
|
|
664 |
}
|
665 |
break;
|
666 |
case 'unused_terms':
|
667 |
-
$query = $wpdb->get_results( $wpdb->prepare( "SELECT tt.term_taxonomy_id, t.term_id, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ')', 0 ) );
|
668 |
if ( $query ) {
|
669 |
$check_wp_terms = false;
|
670 |
foreach ( $query as $tax ) {
|
671 |
if ( taxonomy_exists( $tax->taxonomy ) ) {
|
672 |
-
wp_delete_term(
|
673 |
} else {
|
674 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d",
|
675 |
$check_wp_terms = true;
|
676 |
}
|
677 |
}
|
678 |
-
// We need this for invalid taxonomies
|
679 |
if ( $check_wp_terms ) {
|
680 |
$wpdb->get_results( "DELETE FROM $wpdb->terms WHERE term_id NOT IN (SELECT term_id FROM $wpdb->term_taxonomy)" );
|
681 |
}
|
682 |
|
683 |
-
|
|
|
684 |
}
|
685 |
break;
|
686 |
case 'duplicated_postmeta':
|
@@ -689,10 +737,11 @@ class WPSweep {
|
|
689 |
foreach ( $query as $meta ) {
|
690 |
$ids = array_map( 'intval', explode( ',', $meta->ids ) );
|
691 |
array_pop( $ids );
|
692 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND post_id = %d',
|
693 |
}
|
694 |
|
695 |
-
|
|
|
696 |
}
|
697 |
break;
|
698 |
case 'duplicated_commentmeta':
|
@@ -701,10 +750,11 @@ class WPSweep {
|
|
701 |
foreach ( $query as $meta ) {
|
702 |
$ids = array_map( 'intval', explode( ',', $meta->ids ) );
|
703 |
array_pop( $ids );
|
704 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND comment_id = %d',
|
705 |
}
|
706 |
|
707 |
-
|
|
|
708 |
}
|
709 |
break;
|
710 |
case 'duplicated_usermeta':
|
@@ -713,10 +763,11 @@ class WPSweep {
|
|
713 |
foreach ( $query as $meta ) {
|
714 |
$ids = array_map( 'intval', explode( ',', $meta->ids ) );
|
715 |
array_pop( $ids );
|
716 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE umeta_id IN (" . implode( ',', $ids ) . ') AND user_id = %d',
|
717 |
}
|
718 |
|
719 |
-
|
|
|
720 |
}
|
721 |
break;
|
722 |
case 'duplicated_termmeta':
|
@@ -725,33 +776,36 @@ class WPSweep {
|
|
725 |
foreach ( $query as $meta ) {
|
726 |
$ids = array_map( 'intval', explode( ',', $meta->ids ) );
|
727 |
array_pop( $ids );
|
728 |
-
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND term_id = %d',
|
729 |
}
|
730 |
|
731 |
-
|
|
|
732 |
}
|
733 |
break;
|
734 |
case 'optimize_database':
|
735 |
$query = $wpdb->get_col( 'SHOW TABLES' );
|
736 |
if ( $query ) {
|
737 |
$tables = implode( ',', $query );
|
738 |
-
$wpdb->query( "OPTIMIZE TABLE $tables" );
|
739 |
-
|
|
|
|
|
740 |
}
|
741 |
break;
|
742 |
case 'oembed_postmeta':
|
743 |
$query = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
|
744 |
if ( $query ) {
|
745 |
foreach ( $query as $meta ) {
|
746 |
-
$post_id =
|
747 |
if ( 0 === $post_id ) {
|
748 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
|
749 |
} else {
|
750 |
delete_post_meta( $post_id, $meta->meta_key );
|
751 |
}
|
752 |
}
|
753 |
-
|
754 |
-
$message = sprintf( __( '%s oEmbed Caches In Post Meta Processed', 'wp-sweep' ), number_format_i18n(
|
755 |
}
|
756 |
break;
|
757 |
}
|
@@ -766,8 +820,8 @@ class WPSweep {
|
|
766 |
* @since 1.0.2
|
767 |
*
|
768 |
* @access public
|
769 |
-
* @param int $current
|
770 |
-
* @param int $total
|
771 |
* @return string Number in percentage
|
772 |
*/
|
773 |
public function format_percentage( $current, $total ) {
|
@@ -783,7 +837,7 @@ class WPSweep {
|
|
783 |
* @return array Excluded taxonomies
|
784 |
*/
|
785 |
private function get_excluded_taxonomies() {
|
786 |
-
$excluded_taxonomies
|
787 |
$excluded_taxonomies[] = 'link_category';
|
788 |
|
789 |
return apply_filters( 'wp_sweep_excluded_taxonomies', $excluded_taxonomies );
|
@@ -818,13 +872,13 @@ class WPSweep {
|
|
818 |
* @return array Default taxonomy term IDs
|
819 |
*/
|
820 |
private function get_default_taxonomy_termids() {
|
821 |
-
$taxonomies
|
822 |
$default_term_ids = array();
|
823 |
if ( $taxonomies ) {
|
824 |
$tax = array_keys( $taxonomies );
|
825 |
if ( $tax ) {
|
826 |
foreach ( $tax as $t ) {
|
827 |
-
$term_id =
|
828 |
if ( $term_id > 0 ) {
|
829 |
$default_term_ids[] = $term_id;
|
830 |
}
|
@@ -847,47 +901,22 @@ class WPSweep {
|
|
847 |
return $wpdb->get_col( $wpdb->prepare( "SELECT tt.parent FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.parent > %d", 0 ) );
|
848 |
}
|
849 |
|
850 |
-
/**
|
851 |
-
* Wrapper to get WordPress Multisite
|
852 |
-
*
|
853 |
-
* @since 1.0.9
|
854 |
-
*
|
855 |
-
* @access private
|
856 |
-
* @return array
|
857 |
-
*/
|
858 |
-
private function get_sites() {
|
859 |
-
return function_exists( 'get_sites' ) ? get_sites() : wp_get_sites();
|
860 |
-
}
|
861 |
-
|
862 |
-
/**
|
863 |
-
* Wrapper to get WordPress Multisite ID
|
864 |
-
*
|
865 |
-
* @since 1.0.9
|
866 |
-
*
|
867 |
-
* @access private
|
868 |
-
* @param WP_Site $ms_site
|
869 |
-
* @return int
|
870 |
-
*/
|
871 |
-
private function get_site_blog_id( $ms_site ) {
|
872 |
-
return class_exists( 'WP_Site' ) ? $ms_site->blog_id : $ms_site['blog_id'];
|
873 |
-
}
|
874 |
-
|
875 |
/**
|
876 |
* What to do when the plugin is being deactivated
|
877 |
*
|
878 |
* @since 1.0.0
|
879 |
*
|
880 |
* @access public
|
881 |
-
* @param boolean $network_wide
|
882 |
* @return void
|
883 |
*/
|
884 |
public function plugin_activation( $network_wide ) {
|
885 |
if ( is_multisite() && $network_wide ) {
|
886 |
-
$ms_sites =
|
887 |
|
888 |
-
if ( 0 <
|
889 |
foreach ( $ms_sites as $ms_site ) {
|
890 |
-
switch_to_blog( $
|
891 |
$this->plugin_activated();
|
892 |
restore_current_blog();
|
893 |
}
|
@@ -914,16 +943,16 @@ class WPSweep {
|
|
914 |
* @since 1.0.0
|
915 |
*
|
916 |
* @access public
|
917 |
-
* @param boolean $network_wide
|
918 |
* @return void
|
919 |
*/
|
920 |
public function plugin_deactivation( $network_wide ) {
|
921 |
if ( is_multisite() && $network_wide ) {
|
922 |
-
$ms_sites =
|
923 |
|
924 |
-
if ( 0 <
|
925 |
foreach ( $ms_sites as $ms_site ) {
|
926 |
-
switch_to_blog( $
|
927 |
$this->plugin_deactivated();
|
928 |
restore_current_blog();
|
929 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* WP-Sweep wp-sweep.php
|
4 |
+
*
|
5 |
+
* @package wp-sweep
|
6 |
+
*/
|
7 |
+
|
8 |
/*
|
9 |
Plugin Name: WP-Sweep
|
10 |
Plugin URI: https://lesterchan.net/portfolio/programming/php/
|
11 |
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.
|
12 |
+
Version: 1.1.0
|
13 |
Author: Lester 'GaMerZ' Chan
|
14 |
Author URI: https://lesterchan.net
|
15 |
Text Domain: wp-sweep
|
17 |
*/
|
18 |
|
19 |
/*
|
20 |
+
Copyright 2018 Lester Chan (email : lesterchan@gmail.com)
|
21 |
|
22 |
This program is free software; you can redistribute it and/or modify
|
23 |
it under the terms of the GNU General Public License, version 2, as
|
38 |
*
|
39 |
* @since 1.0.0
|
40 |
*/
|
41 |
+
define( 'WP_SWEEP_VERSION', '1.1.0' );
|
42 |
+
|
43 |
+
/**
|
44 |
+
* WP Rest API
|
45 |
+
*/
|
46 |
+
require __DIR__ . '/inc/class-wpsweep-api.php';
|
47 |
+
new WPSweep_Api();
|
48 |
|
49 |
/**
|
50 |
* WP-Sweep class
|
68 |
* @since 1.0.0
|
69 |
*
|
70 |
* @access private
|
71 |
+
* @var WPSweep $instance
|
72 |
*/
|
73 |
private static $instance;
|
74 |
|
80 |
* @access public
|
81 |
*/
|
82 |
public function __construct() {
|
83 |
+
// Add Plugin Hooks.
|
84 |
add_action( 'plugins_loaded', array( $this, 'add_hooks' ) );
|
85 |
|
86 |
+
// Load Translation.
|
87 |
load_plugin_textdomain( 'wp-sweep' );
|
88 |
|
89 |
+
// Plugin Activation/Deactivation.
|
90 |
register_activation_hook( __FILE__, array( $this, 'plugin_activation' ) );
|
91 |
register_deactivation_hook( __FILE__, array( $this, 'plugin_deactivation' ) );
|
92 |
}
|
115 |
* @return void
|
116 |
*/
|
117 |
public function init() {
|
118 |
+
// include class for WP CLI command.
|
119 |
if ( defined( 'WP_CLI' ) ) {
|
120 |
+
require __DIR__ . '/inc/class-wpsweep-command.php';
|
121 |
+
WP_CLI::add_command( 'sweep', 'WPSweep_Command' );
|
122 |
}
|
123 |
}
|
124 |
|
131 |
* @return void
|
132 |
*/
|
133 |
public function add_hooks() {
|
134 |
+
// Actions.
|
135 |
add_action( 'init', array( $this, 'init' ) );
|
136 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
137 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
145 |
* @since 1.0.3
|
146 |
*
|
147 |
* @access public
|
148 |
+
* @param string $hook Page hook.
|
149 |
* @return void
|
150 |
*/
|
151 |
public function admin_enqueue_scripts( $hook ) {
|
154 |
}
|
155 |
|
156 |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
157 |
+
wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.js' ), array( 'jquery' ), WP_SWEEP_VERSION, true );
|
158 |
} else {
|
159 |
+
wp_enqueue_script( 'wp-sweep', plugins_url( 'wp-sweep/js/wp-sweep.min.js' ), array( 'jquery' ), WP_SWEEP_VERSION, true );
|
160 |
}
|
161 |
|
162 |
+
wp_localize_script(
|
163 |
+
'wp-sweep', 'wp_sweep', array(
|
164 |
+
'text_close_warning' => __( 'Sweeping is in progress. If you leave now, the process won\'t be completed.', 'wp-sweep' ),
|
165 |
+
'text_sweep' => __( 'Sweep', 'wp-sweep' ),
|
166 |
+
'text_sweep_all' => __( 'Sweep All', 'wp-sweep' ),
|
167 |
+
'text_sweeping' => __( 'Sweeping...', 'wp-sweep' ),
|
168 |
+
'text_na' => __( 'N/A', 'wp-sweep' ),
|
169 |
+
)
|
170 |
+
);
|
171 |
}
|
172 |
|
173 |
/**
|
179 |
* @return void
|
180 |
*/
|
181 |
public function admin_menu() {
|
182 |
+
add_management_page( _x( 'Sweep', 'Page title', 'wp-sweep' ), _x( 'Sweep', 'Menu title', 'wp-sweep' ), 'manage_options', 'wp-sweep/admin.php' );
|
183 |
}
|
184 |
|
185 |
|
193 |
*/
|
194 |
public function ajax_sweep_details() {
|
195 |
if ( ! empty( $_GET['action'] )
|
|
|
196 |
&& ! empty( $_GET['sweep_name'] )
|
197 |
&& ! empty( $_GET['sweep_type'] )
|
198 |
) {
|
199 |
+
// Verify Referer.
|
200 |
if ( ! check_admin_referer( 'wp_sweep_details_' . $_GET['sweep_name'] ) ) {
|
201 |
+
wp_send_json_error(
|
202 |
+
array(
|
203 |
+
'error' => __( 'Failed to verify referrer.', 'wp-sweep' ),
|
204 |
+
)
|
205 |
+
);
|
206 |
+
} elseif ( 'sweep_details' === $_GET['action'] ) {
|
207 |
wp_send_json_success( $this->details( $_GET['sweep_name'] ) );
|
208 |
}
|
209 |
}
|
219 |
*/
|
220 |
public function ajax_sweep() {
|
221 |
if ( ! empty( $_GET['action'] )
|
|
|
222 |
&& ! empty( $_GET['sweep_name'] )
|
223 |
&& ! empty( $_GET['sweep_type'] )
|
224 |
) {
|
225 |
+
// Verify Referer.
|
226 |
if ( ! check_admin_referer( 'wp_sweep_' . $_GET['sweep_name'] ) ) {
|
227 |
+
wp_send_json_error(
|
228 |
+
array(
|
229 |
+
'error' => __( 'Failed to verify referrer.', 'wp-sweep' ),
|
230 |
+
)
|
231 |
+
);
|
232 |
+
} elseif ( 'sweep' === $_GET['action'] ) {
|
233 |
+
$sweep = $this->sweep( $_GET['sweep_name'] );
|
234 |
+
$count = $this->count( $_GET['sweep_name'] );
|
235 |
$total_count = $this->total_count( $_GET['sweep_type'] );
|
236 |
$total_stats = array();
|
237 |
switch ( $_GET['sweep_type'] ) {
|
238 |
case 'posts':
|
239 |
case 'postmeta':
|
240 |
+
$total_stats = array(
|
241 |
+
'posts' => $this->total_count( 'posts' ),
|
242 |
+
'postmeta' => $this->total_count( 'postmeta' ),
|
243 |
+
);
|
244 |
break;
|
245 |
case 'comments':
|
246 |
case 'commentmeta':
|
247 |
+
$total_stats = array(
|
248 |
+
'comments' => $this->total_count( 'comments' ),
|
249 |
+
'commentmeta' => $this->total_count( 'commentmeta' ),
|
250 |
+
);
|
251 |
break;
|
252 |
case 'users':
|
253 |
case 'usermeta':
|
254 |
+
$total_stats = array(
|
255 |
+
'users' => $this->total_count( 'users' ),
|
256 |
+
'usermeta' => $this->total_count( 'usermeta' ),
|
257 |
+
);
|
258 |
break;
|
259 |
case 'term_relationships':
|
260 |
case 'term_taxonomy':
|
261 |
case 'terms':
|
262 |
case 'termmeta':
|
263 |
+
$total_stats = array(
|
264 |
+
'term_relationships' => $this->total_count( 'term_relationships' ),
|
265 |
+
'term_taxonomy' => $this->total_count( 'term_taxonomy' ),
|
266 |
+
'terms' => $this->total_count( 'terms' ),
|
267 |
+
'termmeta' => $this->total_count( 'termmeta' ),
|
268 |
+
);
|
269 |
break;
|
270 |
case 'options':
|
271 |
$total_stats = array( 'options' => $this->total_count( 'options' ) );
|
275 |
break;
|
276 |
}
|
277 |
|
278 |
+
wp_send_json_success(
|
279 |
+
array(
|
280 |
+
'sweep' => $sweep,
|
281 |
+
'count' => $count,
|
282 |
+
'total' => $total_count,
|
283 |
+
'percentage' => $this->format_percentage( $count, $total_count ),
|
284 |
+
'stats' => $total_stats,
|
285 |
+
)
|
286 |
+
);
|
287 |
}
|
288 |
}
|
289 |
}
|
294 |
* @since 1.0.0
|
295 |
*
|
296 |
* @access public
|
297 |
+
* @param string $name Sweep name.
|
298 |
* @return int Number of items belonging to each sweep
|
299 |
*/
|
300 |
public function total_count( $name ) {
|
337 |
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->options" );
|
338 |
break;
|
339 |
case 'tables':
|
340 |
+
$count = count( $wpdb->get_col( 'SHOW TABLES' ) );
|
341 |
break;
|
342 |
}
|
343 |
|
350 |
* @since 1.0.0
|
351 |
*
|
352 |
* @access public
|
353 |
+
* @param string $name Sweep name.
|
354 |
* @return int Number of items belonging to each sweep
|
355 |
*/
|
356 |
public function count( $name ) {
|
393 |
$count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
|
394 |
break;
|
395 |
case 'orphan_term_relationships':
|
396 |
+
$orphan_term_relationships_sql = implode( "','", array_map( 'esc_sql', $this->get_excluded_taxonomies() ) );
|
397 |
+
$count = $wpdb->get_var( "SELECT COUNT(object_id) FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('$orphan_term_relationships_sql') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" ); // WPCS: unprepared SQL ok.
|
398 |
break;
|
399 |
case 'unused_terms':
|
400 |
+
$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 ) ); // WPCS: unprepared SQL ok.
|
401 |
break;
|
402 |
case 'duplicated_postmeta':
|
403 |
$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 ) );
|
424 |
}
|
425 |
break;
|
426 |
case 'optimize_database':
|
427 |
+
$count = count( $wpdb->get_col( 'SHOW TABLES' ) );
|
428 |
break;
|
429 |
case 'oembed_postmeta':
|
430 |
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(meta_id) FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
|
440 |
* @since 1.0.3
|
441 |
*
|
442 |
* @access public
|
443 |
+
* @param string $name Sweep name.
|
444 |
+
* @return array Details of items belonging to each sweep
|
445 |
*/
|
446 |
public function details( $name ) {
|
447 |
global $wpdb;
|
483 |
$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 ) );
|
484 |
break;
|
485 |
case 'orphan_term_relationships':
|
486 |
+
$orphan_term_relationships_sql = implode( "','", array_map( 'esc_sql', $this->get_excluded_taxonomies() ) );
|
487 |
+
$details = $wpdb->get_col( $wpdb->prepare( "SELECT tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('$orphan_term_relationships_sql') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts) LIMIT %d", $this->limit_details ) ); // WPCS: unprepared SQL ok.
|
488 |
break;
|
489 |
case 'unused_terms':
|
490 |
+
$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 ) ); // WPCS: unprepared SQL ok.
|
491 |
break;
|
492 |
case 'duplicated_postmeta':
|
493 |
+
$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 ) );
|
494 |
$details = array();
|
495 |
if ( $query ) {
|
496 |
foreach ( $query as $meta ) {
|
499 |
}
|
500 |
break;
|
501 |
case 'duplicated_commentmeta':
|
502 |
+
$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 ) );
|
503 |
$details = array();
|
504 |
if ( $query ) {
|
505 |
foreach ( $query as $meta ) {
|
508 |
}
|
509 |
break;
|
510 |
case 'duplicated_usermeta':
|
511 |
+
$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 ) );
|
512 |
$details = array();
|
513 |
if ( $query ) {
|
514 |
foreach ( $query as $meta ) {
|
517 |
}
|
518 |
break;
|
519 |
case 'duplicated_termmeta':
|
520 |
+
$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 ) );
|
521 |
$details = array();
|
522 |
if ( $query ) {
|
523 |
foreach ( $query as $meta ) {
|
542 |
* @since 1.0.0
|
543 |
*
|
544 |
* @access public
|
545 |
+
* @param string $name Sweep name.
|
546 |
* @return string Processed message
|
547 |
*/
|
548 |
public function sweep( $name ) {
|
555 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = %s", 'revision' ) );
|
556 |
if ( $query ) {
|
557 |
foreach ( $query as $id ) {
|
558 |
+
wp_delete_post_revision( (int) $id );
|
559 |
}
|
560 |
|
561 |
+
// translators: %s is Revisions count.
|
562 |
+
$message = sprintf( __( '%s Revisions Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
563 |
}
|
564 |
break;
|
565 |
case 'auto_drafts':
|
566 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s", 'auto-draft' ) );
|
567 |
if ( $query ) {
|
568 |
foreach ( $query as $id ) {
|
569 |
+
wp_delete_post( (int) $id, true );
|
570 |
}
|
571 |
|
572 |
+
// translators: %s is the Auto Drafts count.
|
573 |
+
$message = sprintf( __( '%s Auto Drafts Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
574 |
}
|
575 |
break;
|
576 |
case 'deleted_posts':
|
580 |
wp_delete_post( $id, true );
|
581 |
}
|
582 |
|
583 |
+
// translators: %s is the Deleted Posts count.
|
584 |
+
$message = sprintf( __( '%s Deleted Posts Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
585 |
}
|
586 |
break;
|
587 |
case 'unapproved_comments':
|
588 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", '0' ) );
|
589 |
if ( $query ) {
|
590 |
foreach ( $query as $id ) {
|
591 |
+
wp_delete_comment( (int) $id, true );
|
592 |
}
|
593 |
|
594 |
+
// translators: %s is the Unapproved Comments count.
|
595 |
+
$message = sprintf( __( '%s Unapproved Comments Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
596 |
}
|
597 |
break;
|
598 |
case 'spam_comments':
|
599 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s", 'spam' ) );
|
600 |
if ( $query ) {
|
601 |
foreach ( $query as $id ) {
|
602 |
+
wp_delete_comment( (int) $id, true );
|
603 |
}
|
604 |
|
605 |
+
// translators: %s is the Spam Comments count.
|
606 |
+
$message = sprintf( __( '%s Spam Comments Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
607 |
}
|
608 |
break;
|
609 |
case 'deleted_comments':
|
610 |
$query = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE (comment_approved = %s OR comment_approved = %s)", 'trash', 'post-trashed' ) );
|
611 |
if ( $query ) {
|
612 |
foreach ( $query as $id ) {
|
613 |
+
wp_delete_comment( (int) $id, true );
|
614 |
}
|
615 |
|
616 |
+
// translators: %s is the Trash Comments count.
|
617 |
+
$message = sprintf( __( '%s Trash Comments Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
618 |
}
|
619 |
break;
|
620 |
case 'transient_options':
|
628 |
}
|
629 |
}
|
630 |
|
631 |
+
// translators: %s is the Transient Options count.
|
632 |
+
$message = sprintf( __( '%s Transient Options Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
633 |
}
|
634 |
break;
|
635 |
case 'orphan_postmeta':
|
636 |
$query = $wpdb->get_results( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)" );
|
637 |
if ( $query ) {
|
638 |
foreach ( $query as $meta ) {
|
639 |
+
$post_id = (int) $meta->post_id;
|
640 |
if ( 0 === $post_id ) {
|
641 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
|
642 |
} else {
|
644 |
}
|
645 |
}
|
646 |
|
647 |
+
// translators: %s is the Orphaned Post Meta count.
|
648 |
+
$message = sprintf( __( '%s Orphaned Post Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
649 |
}
|
650 |
break;
|
651 |
case 'orphan_commentmeta':
|
652 |
$query = $wpdb->get_results( "SELECT comment_id, meta_key FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)" );
|
653 |
if ( $query ) {
|
654 |
foreach ( $query as $meta ) {
|
655 |
+
$comment_id = (int) $meta->comment_id;
|
656 |
if ( 0 === $comment_id ) {
|
657 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s", $comment_id, $meta->meta_key ) );
|
658 |
} else {
|
660 |
}
|
661 |
}
|
662 |
|
663 |
+
// translators: %s is the Orphaned Comment Meta count.
|
664 |
+
$message = sprintf( __( '%s Orphaned Comment Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
665 |
}
|
666 |
break;
|
667 |
case 'orphan_usermeta':
|
668 |
$query = $wpdb->get_results( "SELECT user_id, meta_key FROM $wpdb->usermeta WHERE user_id NOT IN (SELECT ID FROM $wpdb->users)" );
|
669 |
if ( $query ) {
|
670 |
foreach ( $query as $meta ) {
|
671 |
+
$user_id = (int) $meta->user_id;
|
672 |
if ( 0 === $user_id ) {
|
673 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta->meta_key ) );
|
674 |
} else {
|
676 |
}
|
677 |
}
|
678 |
|
679 |
+
// translators: %s is the Orphaned User Meta count.
|
680 |
+
$message = sprintf( __( '%s Orphaned User Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
681 |
}
|
682 |
break;
|
683 |
case 'orphan_termmeta':
|
684 |
$query = $wpdb->get_results( "SELECT term_id, meta_key FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
|
685 |
if ( $query ) {
|
686 |
foreach ( $query as $meta ) {
|
687 |
+
$term_id = (int) $meta->term_id;
|
688 |
if ( 0 === $term_id ) {
|
689 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE term_id = %d AND meta_key = %s", $term_id, $meta->meta_key ) );
|
690 |
} else {
|
692 |
}
|
693 |
}
|
694 |
|
695 |
+
// translators: %s is the Orphaned Term Meta count.
|
696 |
+
$message = sprintf( __( '%s Orphaned Term Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
697 |
}
|
698 |
break;
|
699 |
case 'orphan_term_relationships':
|
700 |
+
$query = $wpdb->get_results( "SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy NOT IN ('" . implode( '\',\'', $this->get_excluded_taxonomies() ) . "') AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" ); // WPCS: unprepared SQL ok.
|
701 |
if ( $query ) {
|
702 |
foreach ( $query as $tax ) {
|
703 |
+
$wp_remove_object_terms = wp_remove_object_terms( (int) $tax->object_id, (int) $tax->term_id, $tax->taxonomy );
|
704 |
if ( true !== $wp_remove_object_terms ) {
|
705 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $tax->object_id, $tax->term_taxonomy_id ) );
|
706 |
}
|
707 |
}
|
708 |
|
709 |
+
// translators: %s is the Orphaned Term Relationships count.
|
710 |
+
$message = sprintf( __( '%s Orphaned Term Relationships Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
711 |
}
|
712 |
break;
|
713 |
case 'unused_terms':
|
714 |
+
$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 ) ); // WPCS: unprepared SQL ok.
|
715 |
if ( $query ) {
|
716 |
$check_wp_terms = false;
|
717 |
foreach ( $query as $tax ) {
|
718 |
if ( taxonomy_exists( $tax->taxonomy ) ) {
|
719 |
+
wp_delete_term( (int) $tax->term_id, $tax->taxonomy );
|
720 |
} else {
|
721 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", (int) $tax->term_taxonomy_id ) );
|
722 |
$check_wp_terms = true;
|
723 |
}
|
724 |
}
|
725 |
+
// We need this for invalid taxonomies.
|
726 |
if ( $check_wp_terms ) {
|
727 |
$wpdb->get_results( "DELETE FROM $wpdb->terms WHERE term_id NOT IN (SELECT term_id FROM $wpdb->term_taxonomy)" );
|
728 |
}
|
729 |
|
730 |
+
// translators: %s is the Unused Terms count.
|
731 |
+
$message = sprintf( __( '%s Unused Terms Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
732 |
}
|
733 |
break;
|
734 |
case 'duplicated_postmeta':
|
737 |
foreach ( $query as $meta ) {
|
738 |
$ids = array_map( 'intval', explode( ',', $meta->ids ) );
|
739 |
array_pop( $ids );
|
740 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND post_id = %d', (int) $meta->post_id ) ); // WPCS: unprepared SQL ok.
|
741 |
}
|
742 |
|
743 |
+
// translators: %s is the Duplicated Post Meta count.
|
744 |
+
$message = sprintf( __( '%s Duplicated Post Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
745 |
}
|
746 |
break;
|
747 |
case 'duplicated_commentmeta':
|
750 |
foreach ( $query as $meta ) {
|
751 |
$ids = array_map( 'intval', explode( ',', $meta->ids ) );
|
752 |
array_pop( $ids );
|
753 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND comment_id = %d', (int) $meta->comment_id ) ); // WPCS: unprepared SQL ok.
|
754 |
}
|
755 |
|
756 |
+
// translators: %s is the Duplicated Comment Meta count.
|
757 |
+
$message = sprintf( __( '%s Duplicated Comment Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
758 |
}
|
759 |
break;
|
760 |
case 'duplicated_usermeta':
|
763 |
foreach ( $query as $meta ) {
|
764 |
$ids = array_map( 'intval', explode( ',', $meta->ids ) );
|
765 |
array_pop( $ids );
|
766 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE umeta_id IN (" . implode( ',', $ids ) . ') AND user_id = %d', (int) $meta->user_id ) ); // WPCS: unprepared SQL ok.
|
767 |
}
|
768 |
|
769 |
+
// translators: %s is the Duplicated User Meta count.
|
770 |
+
$message = sprintf( __( '%s Duplicated User Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
771 |
}
|
772 |
break;
|
773 |
case 'duplicated_termmeta':
|
776 |
foreach ( $query as $meta ) {
|
777 |
$ids = array_map( 'intval', explode( ',', $meta->ids ) );
|
778 |
array_pop( $ids );
|
779 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->termmeta WHERE meta_id IN (" . implode( ',', $ids ) . ') AND term_id = %d', (int) $meta->term_id ) ); // WPCS: unprepared SQL ok.
|
780 |
}
|
781 |
|
782 |
+
// translators: %s is the Duplicated Term Meta count.
|
783 |
+
$message = sprintf( __( '%s Duplicated Term Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
784 |
}
|
785 |
break;
|
786 |
case 'optimize_database':
|
787 |
$query = $wpdb->get_col( 'SHOW TABLES' );
|
788 |
if ( $query ) {
|
789 |
$tables = implode( ',', $query );
|
790 |
+
$wpdb->query( "OPTIMIZE TABLE $tables" ); // WPCS: unprepared SQL ok.
|
791 |
+
|
792 |
+
// translators: %s is the Tables count.
|
793 |
+
$message = sprintf( __( '%s Tables Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
794 |
}
|
795 |
break;
|
796 |
case 'oembed_postmeta':
|
797 |
$query = $wpdb->get_results( $wpdb->prepare( "SELECT post_id, meta_key FROM $wpdb->postmeta WHERE meta_key LIKE(%s)", '%_oembed_%' ) );
|
798 |
if ( $query ) {
|
799 |
foreach ( $query as $meta ) {
|
800 |
+
$post_id = (int) $meta->post_id;
|
801 |
if ( 0 === $post_id ) {
|
802 |
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta->meta_key ) );
|
803 |
} else {
|
804 |
delete_post_meta( $post_id, $meta->meta_key );
|
805 |
}
|
806 |
}
|
807 |
+
// translators: %s is the oEmbed Caches count.
|
808 |
+
$message = sprintf( __( '%s oEmbed Caches In Post Meta Processed', 'wp-sweep' ), number_format_i18n( count( $query ) ) );
|
809 |
}
|
810 |
break;
|
811 |
}
|
820 |
* @since 1.0.2
|
821 |
*
|
822 |
* @access public
|
823 |
+
* @param int $current Current number.
|
824 |
+
* @param int $total Total number.
|
825 |
* @return string Number in percentage
|
826 |
*/
|
827 |
public function format_percentage( $current, $total ) {
|
837 |
* @return array Excluded taxonomies
|
838 |
*/
|
839 |
private function get_excluded_taxonomies() {
|
840 |
+
$excluded_taxonomies = array();
|
841 |
$excluded_taxonomies[] = 'link_category';
|
842 |
|
843 |
return apply_filters( 'wp_sweep_excluded_taxonomies', $excluded_taxonomies );
|
872 |
* @return array Default taxonomy term IDs
|
873 |
*/
|
874 |
private function get_default_taxonomy_termids() {
|
875 |
+
$taxonomies = get_taxonomies();
|
876 |
$default_term_ids = array();
|
877 |
if ( $taxonomies ) {
|
878 |
$tax = array_keys( $taxonomies );
|
879 |
if ( $tax ) {
|
880 |
foreach ( $tax as $t ) {
|
881 |
+
$term_id = (int) get_option( 'default_' . $t );
|
882 |
if ( $term_id > 0 ) {
|
883 |
$default_term_ids[] = $term_id;
|
884 |
}
|
901 |
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 ) );
|
902 |
}
|
903 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
904 |
/**
|
905 |
* What to do when the plugin is being deactivated
|
906 |
*
|
907 |
* @since 1.0.0
|
908 |
*
|
909 |
* @access public
|
910 |
+
* @param boolean $network_wide Is network wide.
|
911 |
* @return void
|
912 |
*/
|
913 |
public function plugin_activation( $network_wide ) {
|
914 |
if ( is_multisite() && $network_wide ) {
|
915 |
+
$ms_sites = (array) get_sites();
|
916 |
|
917 |
+
if ( 0 < count( $ms_sites ) ) {
|
918 |
foreach ( $ms_sites as $ms_site ) {
|
919 |
+
switch_to_blog( $ms_site->blog_id );
|
920 |
$this->plugin_activated();
|
921 |
restore_current_blog();
|
922 |
}
|
943 |
* @since 1.0.0
|
944 |
*
|
945 |
* @access public
|
946 |
+
* @param boolean $network_wide Is network wide.
|
947 |
* @return void
|
948 |
*/
|
949 |
public function plugin_deactivation( $network_wide ) {
|
950 |
if ( is_multisite() && $network_wide ) {
|
951 |
+
$ms_sites = (array) get_sites();
|
952 |
|
953 |
+
if ( 0 < count( $ms_sites ) ) {
|
954 |
foreach ( $ms_sites as $ms_site ) {
|
955 |
+
switch_to_blog( $ms_site->blog_id );
|
956 |
$this->plugin_deactivated();
|
957 |
restore_current_blog();
|
958 |
}
|