Version Description
- FIXES: Use custom query to delete Orphaned Term Relationship if wp_remove_object_terms() fails
Download this release
Release Info
Developer | GamerZ |
Plugin | WP-Sweep |
Version | 1.0.7 |
Comparing to | |
See all releases |
Code changes from version 1.0.8 to 1.0.7
- admin.php +3 -5
- class-command.php +0 -106
- readme.txt +2 -6
- wp-sweep.php +6 -26
admin.php
CHANGED
@@ -64,10 +64,8 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
64 |
</style>
|
65 |
<div class="wrap">
|
66 |
<h2><?php _e( 'WP-Sweep', 'wp-sweep' ); ?></h2>
|
67 |
-
<div class="
|
68 |
-
|
69 |
-
<?php printf( __( 'Before you do any sweep, please <a href="%s" target="%s">backup your database</a> first because any sweep done is irreversible.', 'wp-sweep' ), 'https://wordpress.org/plugins/wp-dbmanager/', '_blank' ); ?>
|
70 |
-
</p>
|
71 |
</div>
|
72 |
<p>
|
73 |
<?php printf( __( 'For performance reasons, only %s items will be shown if you click Details', 'wp-sweep' ), number_format_i18n( WPSweep::get_instance()->limit_details ) ); ?>
|
@@ -562,4 +560,4 @@ $transient_options = WPSweep::get_instance()->count( 'transient_options
|
|
562 |
<button class="button button-primary btn-sweep-all"><?php _e( 'Sweep All', 'wp-sweep' ); ?></button>
|
563 |
</p>
|
564 |
</div>
|
565 |
-
</div>
|
64 |
</style>
|
65 |
<div class="wrap">
|
66 |
<h2><?php _e( 'WP-Sweep', 'wp-sweep' ); ?></h2>
|
67 |
+
<div class="update-nag">
|
68 |
+
<?php printf( __( 'Before you do any sweep, please <a href="%s" target="%s">backup your database</a> first because any sweep done is irreversible.', 'wp-sweep' ), 'https://wordpress.org/plugins/wp-dbmanager/', '_blank' ); ?>
|
|
|
|
|
69 |
</div>
|
70 |
<p>
|
71 |
<?php printf( __( 'For performance reasons, only %s items will be shown if you click Details', 'wp-sweep' ), number_format_i18n( WPSweep::get_instance()->limit_details ) ); ?>
|
560 |
<button class="button button-primary btn-sweep-all"><?php _e( 'Sweep All', 'wp-sweep' ); ?></button>
|
561 |
</p>
|
562 |
</div>
|
563 |
+
</div>
|
class-command.php
DELETED
@@ -1,106 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
class WPSweep_Command extends WP_CLI_Command {
|
4 |
-
/**
|
5 |
-
* Clean up unused, orphaned and duplicated data in your WordPress
|
6 |
-
*
|
7 |
-
* ## OPTIONS
|
8 |
-
*
|
9 |
-
* [--all]
|
10 |
-
* Sweep all the orphaned data at once.
|
11 |
-
*
|
12 |
-
* Name of the items selected individually
|
13 |
-
* Available Items =
|
14 |
-
* revisions
|
15 |
-
* auto_drafts
|
16 |
-
* deleted_posts
|
17 |
-
* unapproved_comments
|
18 |
-
* spam_comments
|
19 |
-
* deleted_comments
|
20 |
-
* transient_options
|
21 |
-
* orphan_postmeta
|
22 |
-
* orphan_commentmeta
|
23 |
-
* orphan_usermeta
|
24 |
-
* orphan_termmeta
|
25 |
-
* orphan_term_relationships
|
26 |
-
* unused_terms
|
27 |
-
* duplicated_postmeta
|
28 |
-
* duplicated_commentmeta
|
29 |
-
* duplicated_usermeta
|
30 |
-
* duplicated_termmeta
|
31 |
-
* optimize_database
|
32 |
-
* oembed_postmet
|
33 |
-
*
|
34 |
-
* ## EXAMPLES
|
35 |
-
*
|
36 |
-
* 1. wp sweep --all
|
37 |
-
* - Run Sweep for all the items.
|
38 |
-
* 2. wp sweep revisions
|
39 |
-
* - Sweep only Revision
|
40 |
-
* 3. wp sweep revisions auto_drafts deleted_posts unapproved_comments spam_comments deleted_comments transient_options orphan_postmeta orphan_commentmeta orphan_usermeta orphan_termmeta orphan_term_relationships unused_terms duplicated_postmeta duplicated_commentmeta duplicated_usermeta duplicated_termmeta optimize_database oembed_postmet
|
41 |
-
* - Sweep the selected items
|
42 |
-
*
|
43 |
-
*
|
44 |
-
*/
|
45 |
-
public function __invoke( $args, $assoc_args ) {
|
46 |
-
|
47 |
-
$items = array();
|
48 |
-
|
49 |
-
$default_items = array(
|
50 |
-
"0" => 'revisions',
|
51 |
-
"1" => 'auto_drafts',
|
52 |
-
"2" => 'deleted_posts',
|
53 |
-
"3" => 'unapproved_comments',
|
54 |
-
"4" => 'spam_comments',
|
55 |
-
"5" => 'deleted_comments',
|
56 |
-
"6" => 'transient_options',
|
57 |
-
"7" => 'orphan_postmeta',
|
58 |
-
"8" => 'orphan_commentmeta',
|
59 |
-
"9" => 'orphan_usermeta',
|
60 |
-
"10" => 'orphan_termmeta',
|
61 |
-
"11" => 'orphan_term_relationships',
|
62 |
-
"12" => 'unused_terms',
|
63 |
-
"13" => 'duplicated_postmeta',
|
64 |
-
"14" => 'duplicated_commentmeta',
|
65 |
-
"15" => 'duplicated_usermeta',
|
66 |
-
"16" => 'duplicated_termmeta',
|
67 |
-
"17" => 'optimize_database',
|
68 |
-
"18" => 'oembed_postmeta'
|
69 |
-
);
|
70 |
-
|
71 |
-
if ( isset( $assoc_args['all'] ) && $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 |
-
}
|
82 |
-
|
83 |
-
$this->run_sweep( $items );
|
84 |
-
WP_CLI::success( "Sweep Complete!" );
|
85 |
-
|
86 |
-
return;
|
87 |
-
}
|
88 |
-
|
89 |
-
}
|
90 |
-
|
91 |
-
public function run_sweep( $items ) {
|
92 |
-
|
93 |
-
$sweep = new WPSweep();
|
94 |
-
|
95 |
-
foreach ( $items as $key => $value ) {
|
96 |
-
$count = $sweep->count( $value );
|
97 |
-
if ( $count !== 0 && $count !== "0" ) {
|
98 |
-
$message = $sweep->sweep( $value );
|
99 |
-
WP_CLI::success( $message );
|
100 |
-
}
|
101 |
-
}
|
102 |
-
|
103 |
-
}
|
104 |
-
}
|
105 |
-
|
106 |
-
WP_CLI::add_command( 'sweep', 'WPSweep_Command' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: GamerZ
|
|
3 |
Donate link: http://lesterchan.net/site/donation/
|
4 |
Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term meta, term relationships, revisions, auto drafts, transient, database, tables, oembed
|
5 |
Requires at least: 4.4
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -62,10 +62,6 @@ Following delete functions are used:
|
|
62 |
I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
|
63 |
|
64 |
== Changelog ==
|
65 |
-
= 1.0.8 =
|
66 |
-
* NEW: Added wp_sweep_excluded_taxonomies filter to allow more than just link_category taxonomy
|
67 |
-
* NEW: Support for WP-CLI `wp sweep`
|
68 |
-
|
69 |
= 1.0.7 =
|
70 |
* FIXES: Use custom query to delete Orphaned Term Relationship if wp_remove_object_terms() fails
|
71 |
|
3 |
Donate link: http://lesterchan.net/site/donation/
|
4 |
Tags: sweep, clean, cleanup, clean up, optimize, orphan, unused, duplicated, posts, post meta, comments, comment meta, users, user meta, terms, term meta, term relationships, revisions, auto drafts, transient, database, tables, oembed
|
5 |
Requires at least: 4.4
|
6 |
+
Tested up to: 4.5
|
7 |
+
Stable tag: 1.0.7
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
62 |
I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
|
63 |
|
64 |
== Changelog ==
|
|
|
|
|
|
|
|
|
65 |
= 1.0.7 =
|
66 |
* FIXES: Use custom query to delete Orphaned Term Relationship if wp_remove_object_terms() fails
|
67 |
|
wp-sweep.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: WP-Sweep
|
4 |
Plugin URI: http://lesterchan.net/portfolio/programming/php/
|
5 |
Description: WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It cleans up revisions, auto drafts, unapproved comments, spam comments, trashed comments, orphan post meta, orphan comment meta, orphan user meta, orphan term relationships, unused terms, duplicated post meta, duplicated comment meta, duplicated user meta and transient options. It also optimizes your database tables.
|
6 |
-
Version: 1.0.
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: http://lesterchan.net
|
9 |
Text Domain: wp-sweep
|
@@ -31,7 +31,7 @@ License: GPL2
|
|
31 |
*
|
32 |
* @since 1.0.0
|
33 |
*/
|
34 |
-
define( 'WP_SWEEP_VERSION', '1.0.
|
35 |
|
36 |
/**
|
37 |
* WP-Sweep class
|
@@ -101,12 +101,7 @@ class WPSweep {
|
|
101 |
* @access public
|
102 |
* @return void
|
103 |
*/
|
104 |
-
public function init() {
|
105 |
-
// include class for WP CLI command
|
106 |
-
if ( defined( 'WP_CLI' ) ) {
|
107 |
-
require __DIR__ . '/class-command.php';
|
108 |
-
}
|
109 |
-
}
|
110 |
|
111 |
/**
|
112 |
* Adds all the plugin hooks
|
@@ -351,7 +346,7 @@ class WPSweep {
|
|
351 |
$count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
|
352 |
break;
|
353 |
case 'orphan_term_relationships':
|
354 |
-
$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
|
355 |
break;
|
356 |
case 'unused_terms':
|
357 |
$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 ) );
|
@@ -440,7 +435,7 @@ class WPSweep {
|
|
440 |
$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 ) );
|
441 |
break;
|
442 |
case 'orphan_term_relationships':
|
443 |
-
$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
|
444 |
break;
|
445 |
case 'unused_terms':
|
446 |
$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 ) );
|
@@ -642,7 +637,7 @@ class WPSweep {
|
|
642 |
}
|
643 |
break;
|
644 |
case 'orphan_term_relationships':
|
645 |
-
$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
|
646 |
if( $query ) {
|
647 |
foreach ( $query as $tax ) {
|
648 |
$wp_remove_object_terms = wp_remove_object_terms( intval( $tax->object_id ), intval( $tax->term_id ), $tax->taxonomy );
|
@@ -765,21 +760,6 @@ class WPSweep {
|
|
765 |
return ( $total > 0 ? round( ( $current / $total ) * 100, 2 ) : 0 ) . '%';
|
766 |
}
|
767 |
|
768 |
-
/*
|
769 |
-
* Get excluded taxonomies
|
770 |
-
*
|
771 |
-
* @since 1.0.8
|
772 |
-
*
|
773 |
-
* @access private
|
774 |
-
* @return array Excluded taxonomies
|
775 |
-
*/
|
776 |
-
private function get_excluded_taxonomies() {
|
777 |
-
$excluded_taxonomies = array();
|
778 |
-
$excluded_taxonomies[] = 'link_category';
|
779 |
-
|
780 |
-
return apply_filters( 'wp_sweep_excluded_taxonomies', $excluded_taxonomies );
|
781 |
-
}
|
782 |
-
|
783 |
/*
|
784 |
* Get excluded term IDs
|
785 |
*
|
3 |
Plugin Name: WP-Sweep
|
4 |
Plugin URI: http://lesterchan.net/portfolio/programming/php/
|
5 |
Description: WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It cleans up revisions, auto drafts, unapproved comments, spam comments, trashed comments, orphan post meta, orphan comment meta, orphan user meta, orphan term relationships, unused terms, duplicated post meta, duplicated comment meta, duplicated user meta and transient options. It also optimizes your database tables.
|
6 |
+
Version: 1.0.7
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: http://lesterchan.net
|
9 |
Text Domain: wp-sweep
|
31 |
*
|
32 |
* @since 1.0.0
|
33 |
*/
|
34 |
+
define( 'WP_SWEEP_VERSION', '1.0.6' );
|
35 |
|
36 |
/**
|
37 |
* WP-Sweep class
|
101 |
* @access public
|
102 |
* @return void
|
103 |
*/
|
104 |
+
public function init() {}
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
/**
|
107 |
* Adds all the plugin hooks
|
346 |
$count = $wpdb->get_var( "SELECT COUNT(meta_id) FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms)" );
|
347 |
break;
|
348 |
case 'orphan_term_relationships':
|
349 |
+
$count = $wpdb->get_var( "SELECT COUNT(object_id) FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy != 'link_category' AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" );
|
350 |
break;
|
351 |
case 'unused_terms':
|
352 |
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(t.term_id) FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ")", 0 ) );
|
435 |
$details = $wpdb->get_col( $wpdb->prepare( "SELECT meta_key FROM $wpdb->termmeta WHERE term_id NOT IN (SELECT term_id FROM $wpdb->terms) LIMIT %d", $this->limit_details ) );
|
436 |
break;
|
437 |
case 'orphan_term_relationships':
|
438 |
+
$details = $wpdb->get_col( $wpdb->prepare( "SELECT tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy != 'link_category' AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts) LIMIT %d", $this->limit_details ) );
|
439 |
break;
|
440 |
case 'unused_terms':
|
441 |
$details = $wpdb->get_col( $wpdb->prepare( "SELECT t.name FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.count = %d AND t.term_id NOT IN (" . implode( ',', $this->get_excluded_termids() ) . ") LIMIT %d", 0, $this->limit_details ) );
|
637 |
}
|
638 |
break;
|
639 |
case 'orphan_term_relationships':
|
640 |
+
$query = $wpdb->get_results( "SELECT tr.object_id, tr.term_taxonomy_id, tt.term_id, tt.taxonomy FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy != 'link_category' AND tr.object_id NOT IN (SELECT ID FROM $wpdb->posts)" );
|
641 |
if( $query ) {
|
642 |
foreach ( $query as $tax ) {
|
643 |
$wp_remove_object_terms = wp_remove_object_terms( intval( $tax->object_id ), intval( $tax->term_id ), $tax->taxonomy );
|
760 |
return ( $total > 0 ? round( ( $current / $total ) * 100, 2 ) : 0 ) . '%';
|
761 |
}
|
762 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
763 |
/*
|
764 |
* Get excluded term IDs
|
765 |
*
|