Advanced Database Cleaner - Version 1.3.0

Version Description

  • Some code optimizations
  • New feature: Support multisite. You can now clean and optimize your database in multisite installation.
Download this release

Release Info

Developer symptote
Plugin Icon 128x128 Advanced Database Cleaner
Version 1.3.0
Comparing to
See all releases

Code changes from version 1.2.3 to 1.3.0

README.txt CHANGED
@@ -1,39 +1,51 @@
1
=== Advanced Database Cleaner ===
2
Contributors: symptote
3
Donate Link: https://www.paypal.com/us/cgi-bin/webscr?cmd=_flow&SESSION=Azq_P8u-Dy9AZSB3bmJFsrGWImHWiCoHtSE8KuC2SNdGQpreQxG8dl2tVZK&dispatch=5885d80a13c0db1f8e263663d3faee8d0b9dcb01a9b6dc564e45f62871326a5e
4
- Tags: plugin, plugins, plugin wordpress, wordpress, database cleaner, clean database, database clean, database, clean, cleaner, delete orphan data, orphan data, delete revisions, revision, delete draft, draft, delete trash, trash, delete spam, spam, delete auto drfat, auto draft, delete postmeta, postmeta, delete commentmeta, commentmeta, delete relationships, relationships, delete transient feed, transient feed, optimize database, database optimize, database optimizer, optimize, optimizer, reset database, database reset, reset, admin, schedule, scheduler, schedule clean-up, schedule optimize
5
- Requires at least: 2.7
6
Tested up to: 4.3
7
- Stable tag: 1.2.3
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
11
- Clean up your database by deleting unused data such as 'draft', Optimize your database or reset it to its initial state.
12
13
== Description ==
14
15
- <h4>Description</h4>
16
- <br>
17
- Advanced Database Cleaner is a must-have plugin that cleans your WP database by:<br><br>
18
- 1. Removing unused data such as "revision", "draft", "auto draft", "moderated comments", "spam comments", "trash comments", "orphan postmeta", "orphan commentmeta", "orphan relationships", "dashboard transient feed".
19
- <br><br>
20
- 2. Optimizing your Wordpress database. This will help you reducing storage space and improving efficiency when accessing your tables.
21
- <br><br>
22
- 3. Resetting your database back to its original state. This will help you making a fresh installation and skip the "5 minutes wordpress installation steps".
23
- <br><br>
24
- * It cleans your database by one click.<br>
25
- * The settings page allows you choose what data should be cleaned.<br>
26
- * You can schedule the clean-up and optimization of your database.<br>
27
- * It is a must-have plugin to keep your database clean.<br>
28
29
== Installation ==
30
This section describes how to install the plugin and get it working.
31
32
- 1. Download and extract 'advanced-database-cleaner' to 'wp-content/plugins/'
33
- 2. In wordpress 'Plugins' page, choose 'Activate'
34
- 3. Go to "Dashboard" -> "Settings" -> "Database Cleaner"
35
36
== Screenshots ==
37
1. Example of dirty database
38
2. Example of cleaned database
39
3. Example of dirty tables
@@ -42,6 +54,10 @@ This section describes how to install the plugin and get it working.
42
43
== Changelog ==
44
45
= 1.2.3 =
46
* Some optimizations and style modifications
47
* New feature: Adding the scheduler. You can now schedule the clean-up and optimization of your database.
1
=== Advanced Database Cleaner ===
2
Contributors: symptote
3
Donate Link: https://www.paypal.com/us/cgi-bin/webscr?cmd=_flow&SESSION=Azq_P8u-Dy9AZSB3bmJFsrGWImHWiCoHtSE8KuC2SNdGQpreQxG8dl2tVZK&dispatch=5885d80a13c0db1f8e263663d3faee8d0b9dcb01a9b6dc564e45f62871326a5e
4
+ Tags: plugin, plugins, plugin wordpress, wordpress, database cleaner, clean database, database clean, database, clean, cleaner, delete orphan data, orphan data, delete revisions, revision, delete draft, draft, delete trash, trash, delete spam, spam, delete auto draft, auto draft, delete postmeta, postmeta, delete commentmeta, commentmeta, delete relationships, relationships, delete transient feed, transient feed, optimize database, database optimize, database optimizer, optimize, optimizer, reset database, database reset, reset, admin, widget, schedule, scheduler, schedule clean-up, schedule optimize, multisite, multi-site, network
5
+ Requires at least: 3.0.0
6
Tested up to: 4.3
7
+ Stable tag: 1.3.0
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
11
+ Clean up your database by deleting unused data such as 'revision', optimize your database, or reset it to its initial state, etc.
12
13
== Description ==
14
15
+ Advanced Database Cleaner is a must-have plugin that cleans and optimizes your WP database.
16
+
17
+ = Main Features =
18
+ * Removes unused data such as "revision", "draft", "auto draft", "moderated comments", "spam comments", "trash comments", "orphan postmeta", "orphan commentmeta", "orphan relationships", "dashboard transient feed" [optional]
19
+ * Optimizes your Wordpress database. This will help you reducing storage space and improving efficiency when accessing your tables [optional]
20
+ * Resets your database back to its original state. This will help you making a fresh installation and skip the "5 minutes wordpress installation steps" [optional]
21
+ * Allows you choose what data should be cleaned and what data should not [optional]
22
+ * Schedules the clean-up to run automatically hourly, twice a day, daily, weekly or monthly [optional]
23
+ * Schedules the optimization of database to run automatically hourly, twice a day, daily, weekly or monthly [optional]
24
+ * Supports multisite installation
25
+
26
+ = Multisite Support =
27
+ * The plugin supports multisite wordpress installations
28
+ * You can 'Network Activate' the plugin or activate it in each site separately
29
+ * The main site can clean and optimize all tables for all sites in the network
30
+ * Other sites in the network can only clean and optimize their own tables in the database
31
+ * The reset of the database can be executed from the main site only (we believe that your database is precious)
32
33
== Installation ==
34
+
35
This section describes how to install the plugin and get it working.
36
37
+ = Single site installation =
38
+ * After extraction, upload the Plugin to your `/wp-content/plugins/` directory
39
+ * Go to "Dashboard" &raquo; "Plugins" and choose 'Activate'
40
+ * The plugin page can be accessed via "Dashboard" &raquo; "Settings" &raquo; "Database Cleaner"
41
+
42
+ = Multisite installation =
43
+ * Login to your primary site and go to "My Sites" &raquo; "Network Admin" &raquo; "Plugins"
44
+ * Install the plugin as usual for multisite
45
+ * 'Network Activate' the plugin in "My Sites" &raquo; "Network Admin" &raquo; "Plugins" or let each site activate it separately
46
47
== Screenshots ==
48
+
49
1. Example of dirty database
50
2. Example of cleaned database
51
3. Example of dirty tables
54
55
== Changelog ==
56
57
+ = 1.3.0 =
58
+ * Some code optimizations
59
+ * New feature: Support multisite. You can now clean and optimize your database in multisite installation.
60
+
61
= 1.2.3 =
62
* Some optimizations and style modifications
63
* New feature: Adding the scheduler. You can now schedule the clean-up and optimization of your database.
advanced-db-cleaner.php CHANGED
@@ -1,8 +1,10 @@
1
<?php
2
/*
3
Plugin Name: Advanced Database Cleaner
4
Description: Clean up your database by deleting unused data such as 'draft', Optimize your database or reset it to its initial state.
5
- Version: 1.2.3
6
Author: Younes JFR.
7
Contributors: symptote
8
Text Domain: advanced-db-cleaner
@@ -11,16 +13,19 @@ License: GPLv2 or later
11
License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
*/
13
14
- /*******************************************************************/
15
-
16
- defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
17
18
/********************************************************************
19
* Add 'settings' link under the plugin name in plugins page
20
********************************************************************/
21
- add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'db_cleaner_add_action_links');
22
function db_cleaner_add_action_links($links){
23
- $adc_settings_link = '<a href = "options-general.php?page=' . dirname(plugin_basename(__FILE__)) . '/advanced-db-cleaner.php">' . __('Settings', 'advanced-db-cleaner') . '</a>';
24
array_unshift($links, $adc_settings_link);
25
return $links;
26
}
@@ -39,11 +44,11 @@ function adv_db_cleaner_add_admin_menu() {
39
********************************************************************/
40
add_action('admin_init', 'adv_db_cleaner_register_styles' );
41
function adv_db_cleaner_register_styles() {
42
- wp_register_style('adv_db_cleaner_css', plugins_url() .'/'. dirname(plugin_basename(__FILE__)) . '/css/style.css');
43
}
44
45
/********************************************************************
46
- * nqueue stylesheet
47
********************************************************************/
48
function adv_db_cleaner_enqueue_styles() {
49
wp_enqueue_style( 'adv_db_cleaner_css' );
@@ -68,43 +73,91 @@ function aDBc_additional_schedules($schedules){
68
return $schedules;
69
}
70
71
- // (RE)-schedule tasks after (RE)-activation or update of the plugin
72
register_activation_hook(__FILE__, 'aDBc_activate_plugin');
73
add_action('aDBc_optimize_scheduler', 'adv_db_cleaner_optimize');
74
add_action('aDBc_clean_scheduler', 'aDBc_cleanAll');
75
- function aDBc_activate_plugin(){
76
- $aDBc_optimize_schedule = get_option('aDBc_optimize_schedule');
77
- if($aDBc_optimize_schedule && $aDBc_optimize_schedule != 'no_schedule'){
78
- if(!wp_next_scheduled('aDBc_optimize_scheduler'))
79
- wp_schedule_event(time()+60, $aDBc_optimize_schedule, 'aDBc_optimize_scheduler');
80
}
81
- $aDBc_clean_schedule = get_option('aDBc_clean_schedule');
82
- if($aDBc_clean_schedule && $aDBc_clean_schedule != 'no_schedule'){
83
- if(!wp_next_scheduled('aDBc_clean_scheduler'))
84
- wp_schedule_event(time()+60, $aDBc_clean_schedule, 'aDBc_clean_scheduler');
85
- }
86
}
87
88
- // Clear current scheduled tasks (if any) when deactivated
89
register_deactivation_hook(__FILE__, 'aDBc_deactivate_plugin' );
90
- function aDBc_deactivate_plugin(){
91
- wp_clear_scheduled_hook('aDBc_optimize_scheduler');
92
- wp_clear_scheduled_hook('aDBc_clean_scheduler');
93
}
94
95
register_uninstall_hook(__FILE__, 'aDBc_uninstall');
96
function aDBc_uninstall(){
97
- delete_option('aDBc_optimize_schedule');
98
- delete_option('aDBc_clean_schedule');
99
- wp_clear_scheduled_hook('aDBc_optimize_scheduler');
100
- wp_clear_scheduled_hook('aDBc_clean_scheduler');
101
}
102
103
- /***************************************************************
104
- *
105
* The admin page content
106
- *
107
- ***************************************************************/
108
function adv_db_cleaner_page(){
109
?>
110
<div class="wrap">
@@ -179,7 +232,15 @@ function adv_db_cleaner_page(){
179
<?php include_once 'includes/optimize-db.php'; ?>
180
</div>
181
<div class="tab3">
182
- <?php include_once 'includes/reset-db.php'; ?>
183
</div>
184
</div>
185
<div class="aDBcSidebar">
1
<?php
2
+ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
3
+
4
/*
5
Plugin Name: Advanced Database Cleaner
6
Description: Clean up your database by deleting unused data such as 'draft', Optimize your database or reset it to its initial state.
7
+ Version: 1.3.0
8
Author: Younes JFR.
9
Contributors: symptote
10
Text Domain: advanced-db-cleaner
13
License URI: http://www.gnu.org/licenses/gpl-2.0.html
14
*/
15
16
+ /********************************************************************
17
+ * Define common variables
18
+ ********************************************************************/
19
+ if (!defined("ADB_CLEANER_PLUGIN_VERSION")) define("ADB_CLEANER_PLUGIN_VERSION", "1.3.0");
20
+ if (!defined("ADB_CLEANER_PLUGIN_BASENAME")) define("ADB_CLEANER_PLUGIN_BASENAME", plugin_basename(__FILE__));
21
+ if (!defined("ADB_CLEANER_PLUGIN_DIR")) define("ADB_CLEANER_PLUGIN_DIR", plugins_url() .'/'. dirname(plugin_basename(__FILE__)));
22
23
/********************************************************************
24
* Add 'settings' link under the plugin name in plugins page
25
********************************************************************/
26
+ add_filter('plugin_action_links_' . ADB_CLEANER_PLUGIN_BASENAME, 'db_cleaner_add_action_links');
27
function db_cleaner_add_action_links($links){
28
+ $adc_settings_link = '<a href = "options-general.php?page=' . ADB_CLEANER_PLUGIN_BASENAME . '">' . __('Settings', 'advanced-db-cleaner') . '</a>';
29
array_unshift($links, $adc_settings_link);
30
return $links;
31
}
44
********************************************************************/
45
add_action('admin_init', 'adv_db_cleaner_register_styles' );
46
function adv_db_cleaner_register_styles() {
47
+ wp_register_style('adv_db_cleaner_css', ADB_CLEANER_PLUGIN_DIR . '/css/style.css');
48
}
49
50
/********************************************************************
51
+ * Enqueue stylesheet
52
********************************************************************/
53
function adv_db_cleaner_enqueue_styles() {
54
wp_enqueue_style( 'adv_db_cleaner_css' );
73
return $schedules;
74
}
75
76
+ /********************************************************************
77
+ * (RE)-schedule tasks after (RE)-activation or update of the plugin
78
+ ********************************************************************/
79
register_activation_hook(__FILE__, 'aDBc_activate_plugin');
80
add_action('aDBc_optimize_scheduler', 'adv_db_cleaner_optimize');
81
add_action('aDBc_clean_scheduler', 'aDBc_cleanAll');
82
+ function aDBc_activate_plugin($network_wide){
83
+ global $wpdb;
84
+ if(function_exists('is_multisite') && is_multisite() && $network_wide){
85
+ $blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
86
+ foreach($blogs_ids as $blog_id){
87
+ switch_to_blog($blog_id);
88
+ $aDBc_optimize_schedule = get_option('aDBc_optimize_schedule');
89
+ if($aDBc_optimize_schedule && $aDBc_optimize_schedule != 'no_schedule'){
90
+ if(!wp_next_scheduled('aDBc_optimize_scheduler'))
91
+ wp_schedule_event(time()+60, $aDBc_optimize_schedule, 'aDBc_optimize_scheduler');
92
+ }
93
+ $aDBc_clean_schedule = get_option('aDBc_clean_schedule');
94
+ if($aDBc_clean_schedule && $aDBc_clean_schedule != 'no_schedule'){
95
+ if(!wp_next_scheduled('aDBc_clean_scheduler'))
96
+ wp_schedule_event(time()+60, $aDBc_clean_schedule, 'aDBc_clean_scheduler');
97
+ }
98
+ restore_current_blog();
99
+ }
100
+ }else{
101
+ $aDBc_optimize_schedule = get_option('aDBc_optimize_schedule');
102
+ if($aDBc_optimize_schedule && $aDBc_optimize_schedule != 'no_schedule'){
103
+ if(!wp_next_scheduled('aDBc_optimize_scheduler'))
104
+ wp_schedule_event(time()+60, $aDBc_optimize_schedule, 'aDBc_optimize_scheduler');
105
+ }
106
+ $aDBc_clean_schedule = get_option('aDBc_clean_schedule');
107
+ if($aDBc_clean_schedule && $aDBc_clean_schedule != 'no_schedule'){
108
+ if(!wp_next_scheduled('aDBc_clean_scheduler'))
109
+ wp_schedule_event(time()+60, $aDBc_clean_schedule, 'aDBc_clean_scheduler');
110
+ }
111
}
112
}
113
114
+ /********************************************************************
115
+ * Clear current scheduled tasks (if any) when deactivated
116
+ ********************************************************************/
117
register_deactivation_hook(__FILE__, 'aDBc_deactivate_plugin' );
118
+ function aDBc_deactivate_plugin($network_wide){
119
+ global $wpdb;
120
+ if(function_exists('is_multisite') && is_multisite() && $network_wide){
121
+ $blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
122
+ foreach($blogs_ids as $blog_id){
123
+ switch_to_blog($blog_id);
124
+ wp_clear_scheduled_hook('aDBc_optimize_scheduler');
125
+ wp_clear_scheduled_hook('aDBc_clean_scheduler');
126
+ restore_current_blog();
127
+ }
128
+ }else{
129
+ wp_clear_scheduled_hook('aDBc_optimize_scheduler');
130
+ wp_clear_scheduled_hook('aDBc_clean_scheduler');
131
+ }
132
}
133
134
+ /********************************************************************
135
+ * Clear scheduled tasks + options if UNINSTALL
136
+ ********************************************************************/
137
register_uninstall_hook(__FILE__, 'aDBc_uninstall');
138
function aDBc_uninstall(){
139
+ global $wpdb;
140
+ if(function_exists('is_multisite') && is_multisite()){
141
+ $blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
142
+ foreach($blogs_ids as $blog_id){
143
+ switch_to_blog($blog_id);
144
+ delete_option('aDBc_optimize_schedule');
145
+ delete_option('aDBc_clean_schedule');
146
+ wp_clear_scheduled_hook('aDBc_optimize_scheduler');
147
+ wp_clear_scheduled_hook('aDBc_clean_scheduler');
148
+ restore_current_blog();
149
+ }
150
+ }else{
151
+ delete_option('aDBc_optimize_schedule');
152
+ delete_option('aDBc_clean_schedule');
153
+ wp_clear_scheduled_hook('aDBc_optimize_scheduler');
154
+ wp_clear_scheduled_hook('aDBc_clean_scheduler');
155
+ }
156
}
157
158
+ /********************************************************************
159
* The admin page content
160
+ ********************************************************************/
161
function adv_db_cleaner_page(){
162
?>
163
<div class="wrap">
232
<?php include_once 'includes/optimize-db.php'; ?>
233
</div>
234
<div class="tab3">
235
+ <?php
236
+ if(is_main_site()){
237
+ include_once 'includes/reset-db.php';
238
+ }else{
239
+ echo "<div style='text-align:center; padding-top:100px; color:#777'>";
240
+ _e('Sorry! The reset can be executed from the main site in your Network only!', 'advanced-db-cleaner');
241
+ echo "</div>";
242
+ }
243
+ ?>
244
</div>
245
</div>
246
<div class="aDBcSidebar">
css/style.css CHANGED
@@ -202,5 +202,40 @@ input[type=checkbox] {
202
203
/* Support us like image */
204
.aDBC-supportUs{
205
- background: url("../images/support.png") no-repeat top right;
206
}
202
203
/* Support us like image */
204
.aDBC-supportUs{
205
+ background: url("../images/rate.png") no-repeat center right;
206
+ }
207
+
208
+ /* Tooltip */
209
+ a.tooltips {
210
+ position: relative;
211
+ display: inline;
212
+ }
213
+ a.tooltips span {
214
+ position: absolute;
215
+ width:400px;
216
+ color: #f2f2f2;
217
+ background: #000000;
218
+ padding:10px;
219
+ visibility: hidden;
220
+ border-radius: 5px;
221
+ }
222
+ a.tooltips span:after {
223
+ content: '';
224
+ position: absolute;
225
+ top: 18px;
226
+ right: 100%;
227
+ margin-top: -8px;
228
+ width: 0; height: 0;
229
+ border-right: 8px solid #000000;
230
+ border-top: 8px solid transparent;
231
+ border-bottom: 8px solid transparent;
232
+ }
233
+ a:hover.tooltips span {
234
+ visibility: visible;
235
+ opacity: 0.9;
236
+ left: 100%;
237
+ top: 50%;
238
+ margin-top: -20.5px;
239
+ margin-left: 15px;
240
+ z-index: 999;
241
}
images/about.png ADDED
Binary file
images/rate.png ADDED
Binary file
images/support.png DELETED
Binary file
includes/clean-db.php CHANGED
@@ -4,8 +4,16 @@ $aDBc_count_unused = adv_db_cleaner_count();
4
?>
5
<div class="marginTop20">
6
<div style="float: left; margin-right:25px; margin-bottom:40px">
7
<form action="" method="post">
8
- <table class="widefat" style="width: 400px; border: 1px solid #eee; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; box-shadow: 0 0px 0px #ccc;">
9
<thead style="background:#f0f5fa; border-bottom:1px solid dashed">
10
<tr>
11
<th scope="col" style="font-size:13px; color:#222; border-bottom: 0px;"><?php _e('Elements to clean','advanced-db-cleaner'); ?></th>
@@ -173,10 +181,10 @@ $aDBc_count_unused = adv_db_cleaner_count();
173
<div style="float:left; padding-left:25px; border-left: 1px dashed #ccc; ">
174
<div style="text-align:center; margin-bottom: 30px">
175
<?php if($aDBc_count_unused["total"] == 0){ ?>
176
- <img src="<?php echo plugins_url() .'/'. dirname(dirname(plugin_basename(__FILE__))) . '/images/db_clean.png'?>"/>
177
<div style="font-color:#ccc; color: #999; font-family: tahoma">Your database is clean!</div>
178
<?php } else { ?>
179
- <img src="<?php echo plugins_url() .'/'. dirname(dirname(plugin_basename(__FILE__))) . '/images/db_not_clean.png'?>"/>
180
<div style="font-color:#ccc; color: #999; font-family: tahoma"><b><?php echo $aDBc_count_unused["total"]; ?></b> element(s) should be cleaned!</div>
181
<?php } ?>
182
</div>
4
?>
5
<div class="marginTop20">
6
<div style="float: left; margin-right:25px; margin-bottom:40px">
7
+ <?php if(function_exists('is_multisite') && is_multisite() && is_main_site()){ ?>
8
+ <div style="margin-bottom:15px;">
9
+ <a class="tooltips" href="#">
10
+ <img src="<?php echo ADB_CLEANER_PLUGIN_DIR . '/images/about.png'?>"/>
11
+ <span>The plugin has detected that you use a multisite installation. This is your main site from which you can clean all tables of all sites in your network. Other sites can clean their own tables only.</span>
12
+ </a>
13
+ </div>
14
+ <?php } ?>
15
<form action="" method="post">
16
+ <table class="widefat" style="width: 400px; border: 1px solid #eee; box-shadow: 0 0px 0px #ccc;">
17
<thead style="background:#f0f5fa; border-bottom:1px solid dashed">
18
<tr>
19
<th scope="col" style="font-size:13px; color:#222; border-bottom: 0px;"><?php _e('Elements to clean','advanced-db-cleaner'); ?></th>
181
<div style="float:left; padding-left:25px; border-left: 1px dashed #ccc; ">
182
<div style="text-align:center; margin-bottom: 30px">
183
<?php if($aDBc_count_unused["total"] == 0){ ?>
184
+ <img src="<?php echo ADB_CLEANER_PLUGIN_DIR . '/images/db_clean.png'?>"/>
185
<div style="font-color:#ccc; color: #999; font-family: tahoma">Your database is clean!</div>
186
<?php } else { ?>
187
+ <img src="<?php echo ADB_CLEANER_PLUGIN_DIR . '/images/db_not_clean.png'?>"/>
188
<div style="font-color:#ccc; color: #999; font-family: tahoma"><b><?php echo $aDBc_count_unused["total"]; ?></b> element(s) should be cleaned!</div>
189
<?php } ?>
190
</div>
includes/functions.php CHANGED
@@ -1,126 +1,197 @@
1
<?php
2
-
3
function adv_db_cleaner($type){
4
global $wpdb;
5
- switch($type){
6
- case "revision":
7
- $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
8
- $wpdb->query($adbc_sql);
9
- break;
10
- case "draft":
11
- $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'draft'";
12
- $wpdb->query($adbc_sql);
13
- break;
14
- case "autodraft":
15
- $adbc_sql = "DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'";
16
- $wpdb->query($adbc_sql);
17
- break;
18
- case "moderated":
19
- $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = '0'";
20
- $wpdb->query($adbc_sql);
21
- break;
22
- case "spam":
23
- $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'";
24
- $wpdb->query($adbc_sql);
25
- break;
26
- case "trash":
27
- $adbc_sql = "DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'";
28
- $wpdb->query($adbc_sql);
29
- break;
30
- case "postmeta":
31
- $adbc_sql = "DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
32
- //$adbc_sql = "DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
33
- $wpdb->query($adbc_sql);
34
- break;
35
- case "commentmeta":
36
- $adbc_sql = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
37
- $wpdb->query($adbc_sql);
38
- break;
39
- case "relationships":
40
- $adbc_sql = "DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
41
- $wpdb->query($adbc_sql);
42
- break;
43
- case "feed":
44
- $adbc_sql = "DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
45
- $wpdb->query($adbc_sql);
46
- break;
47
}
48
}
49
50
function aDBc_cleanAll(){
51
global $wpdb;
52
- $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
53
- $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'draft'");
54
- $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
55
- $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = '0'");
56
- $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'");
57
- $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'");
58
- //$adbc_sql = "DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
59
- $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
60
- $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
61
- $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
62
- $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'");
63
}
64
65
function adv_db_cleaner_count(){
66
global $wpdb;
67
$aDBc_count_total_unused = 0;
68
-
69
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'";
70
- $aDBc_count_unused["revision"] = $wpdb->get_var($adbc_sql);
71
- $aDBc_count_total_unused += $aDBc_count_unused["revision"];
72
-
73
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft'";
74
- $aDBc_count_unused["draft"] = $wpdb->get_var($adbc_sql);
75
- $aDBc_count_total_unused += $aDBc_count_unused["draft"];
76
-
77
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'auto-draft'";
78
- $aDBc_count_unused["autodraft"] = $wpdb->get_var($adbc_sql);
79
- $aDBc_count_total_unused += $aDBc_count_unused["autodraft"];
80
-
81
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'";
82
- $aDBc_count_unused["moderated"] = $wpdb->get_var($adbc_sql);
83
- $aDBc_count_total_unused += $aDBc_count_unused["moderated"];
84
-
85
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'";
86
- $aDBc_count_unused["spam"] = $wpdb->get_var($adbc_sql);
87
- $aDBc_count_total_unused += $aDBc_count_unused["spam"];
88
-
89
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'trash'";
90
- $aDBc_count_unused["trash"] = $wpdb->get_var($adbc_sql);
91
- $aDBc_count_total_unused += $aDBc_count_unused["trash"];
92
-
93
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL";
94
- //$adbc_sql = "SELECT COUNT(*) FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
95
- $aDBc_count_unused["postmeta"] = $wpdb->get_var($adbc_sql);
96
- $aDBc_count_total_unused += $aDBc_count_unused["postmeta"];
97
-
98
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)";
99
- $aDBc_count_unused["commentmeta"] = $wpdb->get_var($adbc_sql);
100
- $aDBc_count_total_unused += $aDBc_count_unused["commentmeta"];
101
-
102
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)";
103
- $aDBc_count_unused["relationships"] = $wpdb->get_var($adbc_sql);
104
- $aDBc_count_total_unused += $aDBc_count_unused["relationships"];
105
-
106
- $adbc_sql = "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'";
107
- $aDBc_count_unused["feed"] = $wpdb->get_var($adbc_sql);
108
- $aDBc_count_total_unused += $aDBc_count_unused["feed"];
109
-
110
- $aDBc_count_unused["total"] = $aDBc_count_total_unused;
111
return $aDBc_count_unused;
112
}
113
114
function adv_db_cleaner_optimize(){
115
global $wpdb;
116
- $adbc_sql = 'SHOW TABLE STATUS FROM `'.DB_NAME.'`';
117
$result = $wpdb->get_results($adbc_sql);
118
foreach($result as $row){
119
- $adbc_sql = 'OPTIMIZE TABLE '.$row->Name;
120
$wpdb->query($adbc_sql);
121
}
122
}
123
124
function adv_db_cleaner_reset(){
125
require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
126
global $current_user, $wpdb;
@@ -154,8 +225,6 @@ function adv_db_cleaner_reset(){
154
if ( $get_user_meta( $user_id, $wpdb->prefix . 'default_password_nag' ) ){
155
$update_user_meta( $user_id, $wpdb->prefix . 'default_password_nag', false );
156
}
157
- // Reactivate the plugin (TODO)
158
- //activate_plugin( 'plugins/advanced-db-cleaner/advanced-db-cleaner.php' );
159
// Clear all cookies associated with authentication
160
wp_clear_auth_cookie();
161
// Set the authentication cookies based User ID
@@ -163,6 +232,4 @@ function adv_db_cleaner_reset(){
163
// Redirect user to admin pannel
164
wp_redirect( admin_url());
165
}
166
-
167
-
168
?>
1
<?php
2
+ //This function is used to clean a specific unused element type from the database
3
function adv_db_cleaner($type){
4
global $wpdb;
5
+ // If we are in multi-site installation and in main site then we should process all elements in all tables
6
+ if(function_exists('is_multisite') && is_multisite() && is_main_site()){
7
+ $blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
8
+ foreach($blogs_ids as $blog_id){
9
+ switch_to_blog($blog_id);
10
+ switch($type){
11
+ case "revision":
12
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
13
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
14
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
15
+ break;
16
+ case "draft":
17
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'draft'");
18
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
19
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
20
+ break;
21
+ case "autodraft":
22
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
23
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
24
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
25
+ break;
26
+ case "moderated":
27
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = '0'");
28
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
29
+ break;
30
+ case "spam":
31
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'");
32
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
33
+ break;
34
+ case "trash":
35
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'");
36
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
37
+ break;
38
+ case "postmeta":
39
+ //"DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
40
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
41
+ break;
42
+ case "commentmeta":
43
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
44
+ break;
45
+ case "relationships":
46
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
47
+ break;
48
+ case "feed":
49
+ $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'");
50
+ break;
51
+ }
52
+ restore_current_blog();
53
+ }
54
+ }else{
55
+ // If we are in single site installation or in multi-site but not in main site, then we should process only current tables
56
+ switch($type){
57
+ case "revision":
58
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
59
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
60
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
61
+ break;
62
+ case "draft":
63
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'draft'");
64
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
65
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
66
+ break;
67
+ case "autodraft":
68
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
69
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
70
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
71
+ break;
72
+ case "moderated":
73
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = '0'");
74
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
75
+ break;
76
+ case "spam":
77
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'");
78
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
79
+ break;
80
+ case "trash":
81
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'");
82
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
83
+ break;
84
+ case "postmeta":
85
+ //"DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
86
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
87
+ break;
88
+ case "commentmeta":
89
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
90
+ break;
91
+ case "relationships":
92
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
93
+ break;
94
+ case "feed":
95
+ $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'");
96
+ break;
97
+ }
98
}
99
}
100
101
+ // This function is used by the scheduler to clean all elements
102
function aDBc_cleanAll(){
103
global $wpdb;
104
+ // If we are in multi-site installation and in main site then we should process all elements in all tables
105
+ if(function_exists('is_multisite') && is_multisite() && is_main_site()){
106
+ $blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
107
+ foreach($blogs_ids as $blog_id){
108
+ switch_to_blog($blog_id);
109
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
110
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'draft'");
111
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
112
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = '0'");
113
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'");
114
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'");
115
+ //"DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
116
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
117
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
118
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
119
+ $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'");
120
+ restore_current_blog();
121
+ }
122
+ }else{
123
+ // If we are in single site installation or in multi-site but not in main site, then we should process only current tables
124
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_type = 'revision'");
125
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'draft'");
126
+ $wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'auto-draft'");
127
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = '0'");
128
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'spam'");
129
+ $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_approved = 'trash'");
130
+ //"DELETE FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
131
+ $wpdb->query("DELETE pm FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
132
+ $wpdb->query("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
133
+ $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
134
+ $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'");
135
+ }
136
}
137
138
+ // This function is used to count unused elements
139
function adv_db_cleaner_count(){
140
global $wpdb;
141
$aDBc_count_total_unused = 0;
142
+ // If we are in multi-site installation and in main site then we should process all elements in all tables
143
+ if(function_exists('is_multisite') && is_multisite() && is_main_site()){
144
+ $blogs_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
145
+ foreach($blogs_ids as $blog_id){
146
+ switch_to_blog($blog_id);
147
+ $aDBc_count_unused["revision"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'");
148
+ $aDBc_count_unused["draft"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft'");
149
+ $aDBc_count_unused["autodraft"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'auto-draft'");
150
+ $aDBc_count_unused["moderated"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
151
+ $aDBc_count_unused["spam"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'");
152
+ $aDBc_count_unused["trash"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'trash'");
153
+ //"SELECT COUNT(*) FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
154
+ $aDBc_count_unused["postmeta"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
155
+ $aDBc_count_unused["commentmeta"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
156
+ $aDBc_count_unused["relationships"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
157
+ $aDBc_count_unused["feed"] += $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'");
158
+ restore_current_blog();
159
+ }
160
+ $aDBc_count_unused["total"] = $aDBc_count_unused["revision"] + $aDBc_count_unused["draft"] + $aDBc_count_unused["autodraft"] + $aDBc_count_unused["moderated"] + $aDBc_count_unused["spam"] + $aDBc_count_unused["trash"] + $aDBc_count_unused["postmeta"] + $aDBc_count_unused["commentmeta"] + $aDBc_count_unused["relationships"] + $aDBc_count_unused["feed"];
161
+ }else{
162
+ // If we are in single site installation or in multi-site but not in main site, then we should process only current tables
163
+ $aDBc_count_unused["revision"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'revision'");
164
+ $aDBc_count_unused["draft"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'draft'");
165
+ $aDBc_count_unused["autodraft"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'auto-draft'");
166
+ $aDBc_count_unused["moderated"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'");
167
+ $aDBc_count_unused["spam"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'");
168
+ $aDBc_count_unused["trash"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'trash'");
169
+ //"SELECT COUNT(*) FROM $wpdb->postmeta WHERE NOT EXISTS ( SELECT * FROM $wpdb->posts WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID )";
170
+ $aDBc_count_unused["postmeta"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta pm LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL");
171
+ $aDBc_count_unused["commentmeta"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM $wpdb->comments)");
172
+ $aDBc_count_unused["relationships"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM $wpdb->posts)");
173
+ $aDBc_count_unused["feed"] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '_site_transient_browser_%' OR option_name LIKE '_site_transient_timeout_browser_%' OR option_name LIKE '_transient_feed_%' OR option_name LIKE '_transient_timeout_feed_%'");
174
+ $aDBc_count_unused["total"] = $aDBc_count_unused["revision"] + $aDBc_count_unused["draft"] + $aDBc_count_unused["autodraft"] + $aDBc_count_unused["moderated"] + $aDBc_count_unused["spam"] + $aDBc_count_unused["trash"] + $aDBc_count_unused["postmeta"] + $aDBc_count_unused["commentmeta"] + $aDBc_count_unused["relationships"] + $aDBc_count_unused["feed"];
175
+ }
176
return $aDBc_count_unused;
177
}
178
179
+ // This function optimizes tables containing lost space (data_free > 0)
180
function adv_db_cleaner_optimize(){
181
global $wpdb;
182
+ $prefix = str_replace( '_', '\_', $wpdb->prefix );
183
+ $adbc_sql = "SELECT table_name, data_free FROM information_schema.tables WHERE table_schema = '".DB_NAME."' and data_free > 0";
184
+ if(!is_main_site()){
185
+ $adbc_sql = $adbc_sql . " and table_name LIKE '{$prefix}%'";
186
+ }
187
$result = $wpdb->get_results($adbc_sql);
188
foreach($result as $row){
189
+ $adbc_sql = 'OPTIMIZE TABLE '.$row->table_name;
190
$wpdb->query($adbc_sql);
191
}
192
}
193
194
+ // This function resets the database to its initial state like a fresh installation
195
function adv_db_cleaner_reset(){
196
require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
197
global $current_user, $wpdb;
225
if ( $get_user_meta( $user_id, $wpdb->prefix . 'default_password_nag' ) ){
226
$update_user_meta( $user_id, $wpdb->prefix . 'default_password_nag', false );
227
}
228
// Clear all cookies associated with authentication
229
wp_clear_auth_cookie();
230
// Set the authentication cookies based User ID
232
// Redirect user to admin pannel
233
wp_redirect( admin_url());
234
}
235
?>
includes/optimize-db.php CHANGED
@@ -1,7 +1,15 @@
1
<div class="marginTop20">
2
<div style="float: left; margin-right:25px; margin-bottom:40px">
3
<form action="" method="post">
4
- <table class="widefat" style="width: 400px; border: 1px solid #eee; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; box-shadow: 0 0px 0px #ccc;">
5
<thead style="background:#f0f5fa; border-bottom:1px solid dashed">
6
<tr>
7
<th scope="col" style="font-size:13px; color:#222; border-bottom: 0px;"><?php _e('Tables to optimize','advanced-db-cleaner'); ?></th>
@@ -13,23 +21,23 @@
13
global $wpdb;
14
$total_tables_to_optimize = 0;
15
$total_lost = 0;
16
- $adbc_sql = 'SHOW TABLE STATUS FROM `'.DB_NAME.'`';
17
$result = $wpdb->get_results($adbc_sql);
18
foreach($result as $row){
19
- $table_size = ($row->Data_length + $row->Index_length) / 1024;
20
- if($row->Data_free > 0){
21
- $total_tables_to_optimize += 1;
22
- $total_lost += $row->Data_free;
23
- echo "<tr class=''>
24
- <td class='column-name'>". $row->Name ."</td>
25
- <td class='column-name' style='text-align:right'>". $row->Data_free . ' o' ."</td>
26
- </tr>\n";
27
- }
28
}
29
-
30
if($total_lost == 0){
31
echo "<tr class=''>
32
- <td class='column-name' style='color: #999'>". __('Nothing to do!','advanced-db-cleaner') ."</td>
33
<td class='column-name'></td></tr>";
34
}
35
?>
@@ -43,17 +51,17 @@
43
</table>
44
<p>
45
<input type="hidden" name="aDBc_optimize_form" value="" />
46
- <input type="submit" class="button-primary" value="<?php _e('Optimize database','advanced-db-cleaner'); ?>" <?php echo $total_lost == 0 ? 'disabled' : ''; ?> />
47
</p>
48
</form>
49
</div>
50
<div style="float:left; padding-left:25px; border-left: 1px dashed #ccc; ">
51
<div style="text-align:center; margin-bottom: 30px">
52
<?php if($total_lost == 0){ ?>
53
- <img src="<?php echo plugins_url() .'/'. dirname(dirname(plugin_basename(__FILE__))) . '/images/db_clean.png'?>"/>
54
<div style="font-color:#ccc; color: #999; font-family: tahoma">Your database is optimized!</div>
55
<?php } else { ?>
56
- <img src="<?php echo plugins_url() .'/'. dirname(dirname(plugin_basename(__FILE__))) . '/images/db_not_clean.png'?>"/>
57
<div style="font-color:#ccc; color: #999; font-family: tahoma"><b><?php echo $total_tables_to_optimize; ?></b> table(s) should be optimized!</div>
58
<?php } ?>
59
</div>
1
<div class="marginTop20">
2
<div style="float: left; margin-right:25px; margin-bottom:40px">
3
<form action="" method="post">
4
+ <?php if(function_exists('is_multisite') && is_multisite() && is_main_site()){ ?>
5
+ <div style="margin-bottom:15px;">
6
+ <a class="tooltips" href="#">
7
+ <img src="<?php echo ADB_CLEANER_PLUGIN_DIR . '/images/about.png'?>"/>
8
+ <span>The plugin has detected that you use a multisite installation. This is your main site from which you can optimize all tables of all sites in your network. Other sites can optimize their own tables only.</span>
9
+ </a>
10
+ </div>
11
+ <?php } ?>
12
+ <table class="widefat" style="width: 400px; border: 1px solid #eee; box-shadow: 0 0px 0px #ccc;">
13
<thead style="background:#f0f5fa; border-bottom:1px solid dashed">
14
<tr>
15
<th scope="col" style="font-size:13px; color:#222; border-bottom: 0px;"><?php _e('Tables to optimize','advanced-db-cleaner'); ?></th>
21
global $wpdb;
22
$total_tables_to_optimize = 0;
23
$total_lost = 0;
24
+ $prefix = str_replace( '_', '\_', $wpdb->prefix );
25
+ $adbc_sql = "SELECT table_name, data_free FROM information_schema.tables WHERE table_schema = '".DB_NAME."' and data_free > 0";
26
+ if(!is_main_site()){
27
+ $adbc_sql = $adbc_sql . " and table_name LIKE '{$prefix}%'";
28
+ }
29
$result = $wpdb->get_results($adbc_sql);
30
foreach($result as $row){
31
+ $total_tables_to_optimize += 1;
32
+ $total_lost += $row->data_free;
33
+ echo "<tr class=''>
34
+ <td class='column-name'>". $row->table_name ."</td>
35
+ <td class='column-name' style='text-align:right'>". $row->data_free . ' o' ."</td>
36
+ </tr>\n";
37
}
38
if($total_lost == 0){
39
echo "<tr class=''>
40
+ <td class='column-name' style='color: #999'>". __('All tables are optimized!','advanced-db-cleaner') ."</td>
41
<td class='column-name'></td></tr>";
42
}
43
?>
51
</table>
52
<p>
53
<input type="hidden" name="aDBc_optimize_form" value="" />
54
+ <input type="submit" class="button-primary" value="<?php _e('Optimize tables','advanced-db-cleaner'); ?>" <?php echo $total_lost == 0 ? 'disabled' : ''; ?> />
55
</p>
56
</form>
57
</div>
58
<div style="float:left; padding-left:25px; border-left: 1px dashed #ccc; ">
59
<div style="text-align:center; margin-bottom: 30px">
60
<?php if($total_lost == 0){ ?>
61
+ <img src="<?php echo ADB_CLEANER_PLUGIN_DIR . '/images/db_clean.png'?>"/>
62
<div style="font-color:#ccc; color: #999; font-family: tahoma">Your database is optimized!</div>
63
<?php } else { ?>
64
+ <img src="<?php echo ADB_CLEANER_PLUGIN_DIR . '/images/db_not_clean.png'?>"/>
65
<div style="font-color:#ccc; color: #999; font-family: tahoma"><b><?php echo $total_tables_to_optimize; ?></b> table(s) should be optimized!</div>
66
<?php } ?>
67
</div>
includes/sidebar.php CHANGED
@@ -1,7 +1,5 @@
1
<div>
2
- <center><h2>Advanced Database Cleaner</h2></center>
3
- <!--<p>See what is new in <a href="#">version 1.2.2</a></p>-->
4
-
5
<p style="text-align: justify"><?php _e('If you love this plugin and would like to make a donation, then you\'re awesome.', 'advanced-db-cleaner'); ?></p>
6
<p style="text-align:right"><?php _e('Thank you!', 'advanced-db-cleaner'); ?></p>
7
<center>
@@ -20,17 +18,17 @@
20
</center>
21
</div>
22
23
- <div style="height: 35px; background-color:#f9f9f9;">
24
<a style="text-decoration: none" href="https://wordpress.org/support/view/plugin-reviews/advanced-database-cleaner#postform">
25
- <div class="aDBC-supportUs" style="width:250px; height:35px; padding-top:10px">
26
- <span style="font-size: 13px; color:#777"><?php echo __('Please support us', 'advanced-db-cleaner'); ?></span>
27
</div>
28
</a>
29
</div>
30
31
- <div style="text-align:center; height: 20px; clear:both;">
32
<div style="float:left">
33
- <span style="font-size: 13px; color:#777"><?php echo __('Having any issues?', 'advanced-db-cleaner'); ?></span>
34
35
</div>
36
<div style="float:right">
@@ -38,6 +36,11 @@
38
</div>
39
</div>
40
41
- <div style="text-align: center; color: #000; font-size:12px; border-top:1px dashed #ccc">
42
- &copy; <?php echo date("Y") . " " . __('Created by', 'advanced-db-cleaner') . " <b>Younes JFR</b>"; ?>
43
</div>
1
<div>
2
+ <center><h2 style="color:#c0c0c0; font-size:18px; font-weight: bold">Advanced Database<br/> Cleaner <?php echo ADB_CLEANER_PLUGIN_VERSION; ?></h2></center>
3
<p style="text-align: justify"><?php _e('If you love this plugin and would like to make a donation, then you\'re awesome.', 'advanced-db-cleaner'); ?></p>
4
<p style="text-align:right"><?php _e('Thank you!', 'advanced-db-cleaner'); ?></p>
5
<center>
18
</center>
19
</div>
20
21
+ <div style="height: 20px; background-color:#f9f9f9;">
22
<a style="text-decoration: none" href="https://wordpress.org/support/view/plugin-reviews/advanced-database-cleaner#postform">
23
+ <div class="aDBC-supportUs" style="width:250px; height:20px">
24
+ <span style="font-size: 13px; color:#777"><?php echo __('Please rate us', 'advanced-db-cleaner'); ?></span>
25
</div>
26
</a>
27
</div>
28
29
+ <div style="height: 20px; clear:both;">
30
<div style="float:left">
31
+ <span style="font-size: 13px; color:#777"><?php echo __('Having issues?', 'advanced-db-cleaner'); ?></span>
32
33
</div>
34
<div style="float:right">
36
</div>
37
</div>
38
39
+ <div style=" background-color:#f9f9f9; height: 20px; clear:both;">
40
+ <div style="float:left">
41
+ <span style="font-size: 13px; color:#777"><?php echo __('Developed by:', 'advanced-db-cleaner'); ?></span>
42
+ </div>
43
+ <div style="float:right">
44
+ { <?php _e('Younes JFR', 'advanced-db-cleaner'); ?> }
45
+ </div>
46
</div>