Version Description
[08/02/2013] * Bug fix: fixed an (innocent) PHP warning (in error.log)
Download this release
Release Info
Developer | cageehv |
Plugin | Optimize Database after Deleting Revisions |
Version | 2.2.3 |
Comparing to | |
See all releases |
Code changes from version 2.2.2 to 2.2.3
- readme.txt +7 -4
- rvg-optimize-db.php +7 -7
- trunk/readme.txt +138 -0
- trunk/rvg-optimize-db.php +1264 -0
readme.txt
CHANGED
@@ -3,13 +3,13 @@ Contributors: CAGE Web Design | Rolf van Gelder
|
|
3 |
Donate link: http://cagewebdev.com
|
4 |
Plugin Name: Optimize Database after Deleting Revisions
|
5 |
Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin
|
6 |
-
Tags: database, delete, revisions, optimize, post, posts, page, pages, clean, clean up, trash, spam, trashed, spammed, database size
|
7 |
Author URI: http://cagewebdev.com
|
8 |
Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
|
9 |
-
Requires at least: 2.2.
|
10 |
Tested up to: 3.5
|
11 |
-
Stable tag: 2.2.
|
12 |
-
Version: 2.2.
|
13 |
|
14 |
== Description ==
|
15 |
|
@@ -48,6 +48,9 @@ http://wordpress.org/extend/plugins/rvg-optimize-database/
|
|
48 |
|
49 |
== Changelog ==
|
50 |
|
|
|
|
|
|
|
51 |
= 2.2.2 [01/20/2013] =
|
52 |
* Bug fix: deleting of postmeta orphans didn't work correctly
|
53 |
|
3 |
Donate link: http://cagewebdev.com
|
4 |
Plugin Name: Optimize Database after Deleting Revisions
|
5 |
Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin
|
6 |
+
Tags: database, delete, revisions, optimize, post, posts, page, pages, clean, clean up, trash, spam, trashed, spammed, database size, scheduler
|
7 |
Author URI: http://cagewebdev.com
|
8 |
Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
|
9 |
+
Requires at least: 2.2.3
|
10 |
Tested up to: 3.5
|
11 |
+
Stable tag: 2.2.3
|
12 |
+
Version: 2.2.3
|
13 |
|
14 |
== Description ==
|
15 |
|
48 |
|
49 |
== Changelog ==
|
50 |
|
51 |
+
= 2.2.3 [08/02/2013]
|
52 |
+
* Bug fix: fixed an (innocent) PHP warning (in error.log)
|
53 |
+
|
54 |
= 2.2.2 [01/20/2013] =
|
55 |
* Bug fix: deleting of postmeta orphans didn't work correctly
|
56 |
|
rvg-optimize-db.php
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
<?php
|
2 |
-
$odb_version = '2.2.
|
3 |
-
$odb_release_date = '
|
4 |
/**
|
5 |
* @package Optimize Database after Deleting Revisions
|
6 |
-
* @version 2.2.
|
7 |
*/
|
8 |
/*
|
9 |
Plugin Name: Optimize Database after Deleting Revisions
|
10 |
Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/
|
11 |
Description: Optimizes the Wordpress Database after Cleaning it out - <a href="options-general.php?page=rvg_odb_admin"><strong>plug in options</strong></a>
|
12 |
-
Author: Rolf van Gelder, Eindhoven, The Netherlands
|
13 |
-
Version: 2.2.
|
14 |
Author URI: http://cagewebdev.com
|
15 |
*/
|
16 |
?>
|
@@ -420,7 +420,7 @@ function rvg_optimize_db()
|
|
420 |
?>
|
421 |
|
422 |
<input class="button-primary button-large" type="button" name="start_optimization" value="Start Optimization" onclick="self.location='tools.php?page=rvg-optimize-db.php&action=run'" style="font-weight:bold;" />
|
423 |
-
<?php
|
424 |
}
|
425 |
?>
|
426 |
</p>
|
@@ -736,7 +736,7 @@ function rvg_optimize_db_cron()
|
|
736 |
$total_deleted = 0;
|
737 |
if(count($results)>0)
|
738 |
// WE HAVE REVISIONS TO DELETE!
|
739 |
-
$total_deleted = rvg_delete_revisions($results, false);
|
740 |
|
741 |
// NUMBER OF DELETED REVISIONS FOR LOG FILE
|
742 |
$log_arr["revisions"] = $total_deleted;
|
1 |
<?php
|
2 |
+
$odb_version = '2.2.3';
|
3 |
+
$odb_release_date = '02/08/2013';
|
4 |
/**
|
5 |
* @package Optimize Database after Deleting Revisions
|
6 |
+
* @version 2.2.3
|
7 |
*/
|
8 |
/*
|
9 |
Plugin Name: Optimize Database after Deleting Revisions
|
10 |
Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/
|
11 |
Description: Optimizes the Wordpress Database after Cleaning it out - <a href="options-general.php?page=rvg_odb_admin"><strong>plug in options</strong></a>
|
12 |
+
Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
|
13 |
+
Version: 2.2.3
|
14 |
Author URI: http://cagewebdev.com
|
15 |
*/
|
16 |
?>
|
420 |
?>
|
421 |
|
422 |
<input class="button-primary button-large" type="button" name="start_optimization" value="Start Optimization" onclick="self.location='tools.php?page=rvg-optimize-db.php&action=run'" style="font-weight:bold;" />
|
423 |
+
<?php
|
424 |
}
|
425 |
?>
|
426 |
</p>
|
736 |
$total_deleted = 0;
|
737 |
if(count($results)>0)
|
738 |
// WE HAVE REVISIONS TO DELETE!
|
739 |
+
$total_deleted = rvg_delete_revisions($results, false, $max_revisions);
|
740 |
|
741 |
// NUMBER OF DELETED REVISIONS FOR LOG FILE
|
742 |
$log_arr["revisions"] = $total_deleted;
|
trunk/readme.txt
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Optimize Database after Deleting Revisions ===
|
2 |
+
Contributors: CAGE Web Design | Rolf van Gelder
|
3 |
+
Donate link: http://cagewebdev.com
|
4 |
+
Plugin Name: Optimize Database after Deleting Revisions
|
5 |
+
Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin
|
6 |
+
Tags: database, delete, revisions, optimize, post, posts, page, pages, clean, clean up, trash, spam, trashed, spammed, database size, scheduler
|
7 |
+
Author URI: http://cagewebdev.com
|
8 |
+
Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
|
9 |
+
Requires at least: 2.2.3
|
10 |
+
Tested up to: 3.5
|
11 |
+
Stable tag: 2.2.3
|
12 |
+
Version: 2.2.3
|
13 |
+
|
14 |
+
== Description ==
|
15 |
+
|
16 |
+
This plugin is a 'One Click' WordPress Database Cleaner / Optimizer.
|
17 |
+
|
18 |
+
= Main Features =
|
19 |
+
* Deletes redundant revisions of posts and pages (you optionally can keep an 'x'-amount of the most recent revisions)
|
20 |
+
* Deletes trashed posts, pages and comments (optional)
|
21 |
+
* Deletes spammed comments (optional)
|
22 |
+
* Deletes 'orphan postmeta items'
|
23 |
+
* Optimizes the database tables (optionally you can exclude certain tables from optimization)
|
24 |
+
* Creates a log file of the optimizations (optional)
|
25 |
+
* Optimization can be scheduled to automatically run once hourly, twice daily, once daily or once weekly (optional)
|
26 |
+
|
27 |
+
= Settings =
|
28 |
+
You can find the settings page in the WP Admin Panel » Settings » Optimize DB Options.
|
29 |
+
|
30 |
+
= Starting the Optimization =
|
31 |
+
You can start the Optimization in the WP Admin Panel » Tools » Optimize Database.
|
32 |
+
Note: if you use the Scheduler the Optimization will run automatically!
|
33 |
+
|
34 |
+
= Author =
|
35 |
+
CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands - http://cagewebdev.com - http://cage.nl
|
36 |
+
|
37 |
+
= Plugin URL =
|
38 |
+
http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin
|
39 |
+
|
40 |
+
= Download URL =
|
41 |
+
http://wordpress.org/extend/plugins/rvg-optimize-database/
|
42 |
+
|
43 |
+
== Installation ==
|
44 |
+
|
45 |
+
* Upload the Plugin to the `/wp-content/plugins/` directory
|
46 |
+
* Activate the plugin in the WP Admin Panel » Plugins
|
47 |
+
* Change the settings (if needed) in the WP Admin Panel » Settings » Optimize DB Options.
|
48 |
+
|
49 |
+
== Changelog ==
|
50 |
+
|
51 |
+
= 2.2.3 [09/02/2013] =
|
52 |
+
* Bug fix: fixed an (innocent) PHP warning (in error.log)
|
53 |
+
|
54 |
+
= 2.2.2 [01/20/2013] =
|
55 |
+
* Bug fix: deleting of postmeta orphans didn't work correctly
|
56 |
+
|
57 |
+
= 2.2.1 [01/17/2013] =
|
58 |
+
* Bug fix: fixed some debug warnings
|
59 |
+
|
60 |
+
= 2.2 [01/11/2013] =
|
61 |
+
* NEW: 'Orphan Postmeta items' will be automatically deleted
|
62 |
+
* NEW: the possibility to exclude tables from Optimization (for instance for 'heavy traffic' tables)
|
63 |
+
|
64 |
+
= 2.1 [01/04/2013] =
|
65 |
+
* Bug fix: keeping a maximum number of revisions didn't work correctly
|
66 |
+
|
67 |
+
= 2.0 [12/18/2012] =
|
68 |
+
* NEW: Logging of the Optimizations (optional)
|
69 |
+
* NEW: Scheduling Optimizations for Automatic Execution (optional)
|
70 |
+
* Many other (technical and cosmetical) changes and improvements
|
71 |
+
|
72 |
+
= 1.3.4 [12/14/2012] =
|
73 |
+
* Changed the buttons for WP 3.5
|
74 |
+
|
75 |
+
= 1.3.3 [12/01/2012] =
|
76 |
+
* Some layout changes
|
77 |
+
|
78 |
+
= 1.3.2 [11/14/2012] =
|
79 |
+
* Shows more information about the optimized tables + other minor changes
|
80 |
+
|
81 |
+
= 1.3.1 [10/07/2012] =
|
82 |
+
* Minor changes
|
83 |
+
|
84 |
+
= 1.3 [10/06/2012] =
|
85 |
+
* Extra button for starting optimization, shows savings (in bytes) now
|
86 |
+
|
87 |
+
= 1.2 [10/03/2012] =
|
88 |
+
* Major update: new options 'delete trash', 'delete spam', 'only optimize WordPress tables'
|
89 |
+
|
90 |
+
= 1.1.9 [09/27/2012] =
|
91 |
+
* Using a different method for retrieving database table names
|
92 |
+
|
93 |
+
= 1.1.8 [09/08/2012] =
|
94 |
+
* Another link fix
|
95 |
+
|
96 |
+
= 1.1.7 [09/03/2012] =
|
97 |
+
* Some textual and link fixes
|
98 |
+
|
99 |
+
= 1.1.6 [09/01/2012] =
|
100 |
+
* Fixed the link to the options page
|
101 |
+
|
102 |
+
= 1.1.3 [09/01/2012] =
|
103 |
+
* Moved the 'Optimize DB Options' item to Dashboard 'Settings' Menu and the 'Optimize Database' item to the Dashboard 'Tools' Menu. That makes more sense!
|
104 |
+
|
105 |
+
= 1.1.2 [08/30/2012] =
|
106 |
+
* Minor bug fix for the new option page
|
107 |
+
|
108 |
+
= 1.1 [08/29/2012] =
|
109 |
+
* Added: a new option page, in de plugins section, where you can define the maximum number of - most recent - revisions you want to keep per post or page
|
110 |
+
|
111 |
+
= 1.0.5 [08/21/2012] =
|
112 |
+
* Depreciated item ('has_cap') replaced, abandoned line of code removed
|
113 |
+
|
114 |
+
= 1.0.4 [06/06/2012] =
|
115 |
+
* Now also works with non short_open_tag's
|
116 |
+
|
117 |
+
= 1.0.3 [12/15/2011] =
|
118 |
+
* Some minor layout updates
|
119 |
+
|
120 |
+
= 1.0.2 [12/02/2011] =
|
121 |
+
* Some minor updates
|
122 |
+
|
123 |
+
= 1.0.1 [11/24/2011] =
|
124 |
+
* A few updates for the readme.txt file
|
125 |
+
|
126 |
+
= 1.0 [11/22/2011] =
|
127 |
+
* Initial release
|
128 |
+
|
129 |
+
== Frequently Asked Questions ==
|
130 |
+
|
131 |
+
= How can I change the settings of this plugin? =
|
132 |
+
* WP Admin Panel » Settings » Optimize DB Options'. There you can define the maximum number of - most recent - revisions you want to keep per post or page and some more options.
|
133 |
+
|
134 |
+
= How do I run this plugin? =
|
135 |
+
* WP Admin Panel » Tools » Optimize Database. Then click the 'Start Optimization'-button. Et voila!
|
136 |
+
|
137 |
+
= Why do I see 'Table does not support optimize, doing recreate + analyze instead' while optimizing my database? =
|
138 |
+
* That is because the table type of that table is not 'MyISAM'
|
trunk/rvg-optimize-db.php
ADDED
@@ -0,0 +1,1264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$odb_version = '2.2.3';
|
3 |
+
$odb_release_date = '02/08/2013';
|
4 |
+
/**
|
5 |
+
* @package Optimize Database after Deleting Revisions
|
6 |
+
* @version 2.2.3
|
7 |
+
*/
|
8 |
+
/*
|
9 |
+
Plugin Name: Optimize Database after Deleting Revisions
|
10 |
+
Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/
|
11 |
+
Description: Optimizes the Wordpress Database after Cleaning it out - <a href="options-general.php?page=rvg_odb_admin"><strong>plug in options</strong></a>
|
12 |
+
Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
|
13 |
+
Version: 2.2.3
|
14 |
+
Author URI: http://cagewebdev.com
|
15 |
+
*/
|
16 |
+
?>
|
17 |
+
<?php
|
18 |
+
/********************************************************************************************
|
19 |
+
|
20 |
+
ADD THE 'OPTIMIZE DATABASE' ITEM TO THE TOOLS MENU
|
21 |
+
|
22 |
+
*********************************************************************************************/
|
23 |
+
function optimize_db_main()
|
24 |
+
{ if (function_exists('add_management_page'))
|
25 |
+
{ add_management_page(__('Optimize Database'), __('Optimize Database'),'administrator' ,'rvg-optimize-db.php', 'rvg_optimize_db');
|
26 |
+
}
|
27 |
+
}
|
28 |
+
add_action('admin_menu', 'optimize_db_main');
|
29 |
+
|
30 |
+
|
31 |
+
/********************************************************************************************
|
32 |
+
|
33 |
+
ADD THE 'OPTIMIZE DB OPTIONS' ITEM TO THE SETTINGS MENU
|
34 |
+
|
35 |
+
*********************************************************************************************/
|
36 |
+
function rvg_odb_admin_menu()
|
37 |
+
{
|
38 |
+
if (function_exists('add_options_page'))
|
39 |
+
{ add_options_page(__('Optimize DB Options'), __('Optimize DB Options'), 'manage_options', 'rvg_odb_admin', 'rvg_odb_options_page');
|
40 |
+
}
|
41 |
+
}
|
42 |
+
add_action( 'admin_menu', 'rvg_odb_admin_menu' );
|
43 |
+
|
44 |
+
|
45 |
+
/********************************************************************************************
|
46 |
+
|
47 |
+
ACTIONS FOR THE SCHEDULER
|
48 |
+
|
49 |
+
*********************************************************************************************/
|
50 |
+
add_filter('cron_schedules', 'rvg_extra_schedules');
|
51 |
+
function rvg_extra_schedules(){
|
52 |
+
return array(
|
53 |
+
'weekly' => array(
|
54 |
+
'interval' => 604800,
|
55 |
+
'display' => 'Once weekly'
|
56 |
+
)
|
57 |
+
);
|
58 |
+
}
|
59 |
+
add_action( 'rvg_optimize_database', 'rvg_optimize_db_cron' );
|
60 |
+
|
61 |
+
// REMOVE SCHEDULED TASK WHEN DEACTIVATED
|
62 |
+
register_deactivation_hook( __FILE__, 'rvg_deactivate_plugin' );
|
63 |
+
function rvg_deactivate_plugin()
|
64 |
+
{ // CLEAR CURRENT SCHEDULE (IF ANY)
|
65 |
+
wp_clear_scheduled_hook('rvg_optimize_database');
|
66 |
+
}
|
67 |
+
|
68 |
+
// RE-SCHEDULE TASK WHEN RE-ACTIVATED (OR AFTER UPDATE)
|
69 |
+
register_activation_hook( __FILE__, 'rvg_activate_plugin' );
|
70 |
+
function rvg_activate_plugin()
|
71 |
+
{ $rvg_odb_schedule = get_option('rvg_odb_schedule');
|
72 |
+
if($rvg_odb_schedule)
|
73 |
+
{ // PLUGIN RE-ACTIVATED: START SCHEDULER
|
74 |
+
if( !wp_next_scheduled( 'rvg_optimize_database' ))
|
75 |
+
wp_schedule_event( time(), $rvg_odb_schedule, 'rvg_optimize_database' );
|
76 |
+
}
|
77 |
+
} # rvg_activate_plugin()
|
78 |
+
|
79 |
+
|
80 |
+
/********************************************************************************************
|
81 |
+
|
82 |
+
CREATE THE OPTIONS PAGE
|
83 |
+
|
84 |
+
*********************************************************************************************/
|
85 |
+
function rvg_odb_options_page() {
|
86 |
+
global $odb_version, $odb_release_date, $wpdb, $table_prefix;
|
87 |
+
|
88 |
+
# jQuery FRAMEWORK
|
89 |
+
echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>';
|
90 |
+
|
91 |
+
# RVG_WP_ONLY IS DEPRECIATED FROM v2.2
|
92 |
+
rvg_fix_wp_only();
|
93 |
+
|
94 |
+
if(isset($_REQUEST['delete_log']))
|
95 |
+
if($_REQUEST['delete_log'] == "Y") @unlink(dirname(__FILE__).'/rvg-optimize-db-log.html');
|
96 |
+
|
97 |
+
// SAVE THE OPTIONS
|
98 |
+
if (isset($_POST['info_update']))
|
99 |
+
{
|
100 |
+
check_admin_referer();
|
101 |
+
|
102 |
+
# DELETE ALL EXCLUDED TABLES
|
103 |
+
$sql = "
|
104 |
+
DELETE FROM $wpdb->options
|
105 |
+
WHERE `option_name` LIKE 'rvg_ex_%'
|
106 |
+
";
|
107 |
+
$wpdb -> get_results($sql);
|
108 |
+
|
109 |
+
# ADD EXCLUDED TABLES
|
110 |
+
foreach ($_POST as $key => $value)
|
111 |
+
{ if(substr($key,0,3) == 'cb_')
|
112 |
+
{ $sql = "
|
113 |
+
INSERT INTO $wpdb->options (option_name, option_value, autoload)
|
114 |
+
VALUES ('rvg_ex_".substr($key,3)."','excluded','yes')
|
115 |
+
";
|
116 |
+
$wpdb -> get_results($sql);
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
if(isset($_POST['rvg_odb_number']))
|
121 |
+
{ $rvg_odb_number = trim($_POST['rvg_odb_number']);
|
122 |
+
update_option('rvg_odb_number', $rvg_odb_number);
|
123 |
+
}
|
124 |
+
|
125 |
+
$rvg_clear_trash = 'N';
|
126 |
+
if(isset($_POST['rvg_clear_trash']))
|
127 |
+
$rvg_clear_trash = $_POST['rvg_clear_trash'];
|
128 |
+
update_option('rvg_clear_trash', $rvg_clear_trash);
|
129 |
+
|
130 |
+
$rvg_clear_spam = 'N';
|
131 |
+
if(isset($_POST['rvg_clear_spam']))
|
132 |
+
$rvg_clear_spam = $_POST['rvg_clear_spam'];
|
133 |
+
update_option('rvg_clear_spam', $rvg_clear_spam);
|
134 |
+
|
135 |
+
$rvg_odb_logging_on = 'N';
|
136 |
+
if(isset($_POST['rvg_odb_logging_on']))
|
137 |
+
$rvg_odb_logging_on = $_POST['rvg_odb_logging_on'];
|
138 |
+
update_option('rvg_odb_logging_on', $rvg_odb_logging_on);
|
139 |
+
|
140 |
+
$rvg_odb_schedule = '';
|
141 |
+
if(isset($_POST['rvg_odb_schedule']))
|
142 |
+
$rvg_odb_schedule = $_POST['rvg_odb_schedule'];
|
143 |
+
update_option('rvg_odb_schedule', $rvg_odb_schedule);
|
144 |
+
|
145 |
+
// CLEAR CURRENT SCHEDULE (IF ANY)
|
146 |
+
wp_clear_scheduled_hook('rvg_optimize_database');
|
147 |
+
|
148 |
+
// HAS TO BE SCHEDULED
|
149 |
+
if($rvg_odb_schedule != '')
|
150 |
+
if( !wp_next_scheduled( 'rvg_optimize_database' ))
|
151 |
+
wp_schedule_event( time(), $rvg_odb_schedule, 'rvg_optimize_database' );
|
152 |
+
|
153 |
+
// UPDATED MESSAGE
|
154 |
+
echo "<div class='updated'><p><strong>Optimize Database after Deleting Revisions OPTIONS UPDATED</strong> - Click <a href='tools.php?page=rvg-optimize-db.php' style='font-weight:bold'>HERE</a> to run the optimization</p></div>";
|
155 |
+
}
|
156 |
+
|
157 |
+
$rvg_odb_number = get_option('rvg_odb_number');
|
158 |
+
if(!$rvg_odb_number) $rvg_odb_number = '0';
|
159 |
+
|
160 |
+
$rvg_clear_trash = get_option('rvg_clear_trash');
|
161 |
+
if(!$rvg_clear_trash) $rvg_clear_trash = 'N';
|
162 |
+
|
163 |
+
$rvg_clear_spam = get_option('rvg_clear_spam');
|
164 |
+
if(!$rvg_clear_spam) $rvg_clear_spam = 'N';
|
165 |
+
|
166 |
+
$rvg_odb_logging_on = get_option('rvg_odb_logging_on');
|
167 |
+
if(!$rvg_odb_logging_on) $rvg_odb_logging_on = 'N';
|
168 |
+
|
169 |
+
$rvg_odb_schedule = get_option('rvg_odb_schedule');
|
170 |
+
if(!$rvg_odb_schedule) $rvg_odb_schedule = '';
|
171 |
+
?>
|
172 |
+
|
173 |
+
<form name="options" method="post" action="">
|
174 |
+
<div class="wrap">
|
175 |
+
<h2>Using Optimize Database after Deleting Revisions</h2>
|
176 |
+
<blockquote>
|
177 |
+
<p><strong>'<em>Optimize Database after Deleting Revisions</em>' is an one-click plugin to clean and optimize your WordPress database.</strong></p>
|
178 |
+
<p>To start the optimization:<br />
|
179 |
+
<strong>WP Admin Panel</strong> » <strong>Tools</strong> » <strong>Optimize Database</strong>. Then click the '<strong>Start Optimization</strong>'-button. Et voila!<br />
|
180 |
+
Note: if you use the Scheduler the Optimization will run automatically!
|
181 |
+
<p>Plugin version:<br />
|
182 |
+
<strong>v<?php echo $odb_version ?> (<?php echo $odb_release_date?>)</strong> </p>
|
183 |
+
<p><strong>Author:</strong><br />
|
184 |
+
<strong><a href="http://cagewebdev.com/" target="_blank">CAGE Web Design</a> | <a href="http://cage.nl/" target="_blank">Rolf van Gelder</a></strong>, Eindhoven, The Netherlands<br />
|
185 |
+
<strong>Plugin URL:</strong><br />
|
186 |
+
<a href="http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/" target="_blank"><strong>http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/</strong></a><br />
|
187 |
+
<strong>Download URL:</strong><br />
|
188 |
+
<strong><a href="http://wordpress.org/extend/plugins/rvg-optimize-database/" target="_blank">http://wordpress.org/extend/plugins/rvg-optimize-database/</a></strong></p>
|
189 |
+
<p> </p>
|
190 |
+
</blockquote>
|
191 |
+
<h2>Optimize Database after Deleting Revisions - Options</h2>
|
192 |
+
<?php
|
193 |
+
if($rvg_clear_trash == 'Y') $rvg_clear_trash_checked = ' checked="checked"'; else $rvg_clear_trash_checked = '';
|
194 |
+
if($rvg_clear_spam == 'Y') $rvg_clear_spam_checked = ' checked="checked"'; else $rvg_clear_spam_checked = '';
|
195 |
+
if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checked"'; else $rvg_odb_logging_on_checked = '';
|
196 |
+
?>
|
197 |
+
<blockquote>
|
198 |
+
<fieldset class='options'>
|
199 |
+
<table class="editform" cellspacing="2" cellpadding="5" width="100%">
|
200 |
+
<tr>
|
201 |
+
<td colspan="3" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="4">
|
202 |
+
<tr>
|
203 |
+
<td width="50%" align="right" valign="top"><span style="font-weight:bold;">Maximum number of - most recent - revisions to keep per post / page<br />
|
204 |
+
('0' means: delete <u>ALL</u> revisions)</span></td>
|
205 |
+
<td width="50%" valign="top"><input type="text" size="5" name="rvg_odb_number" id="rvg_odb_number" value="<?php echo $rvg_odb_number?>" style="font-weight:bold;color:#00F;" /></td>
|
206 |
+
</tr>
|
207 |
+
<tr>
|
208 |
+
<td width="50%" align="right" valign="top"><span style="font-weight:bold;">Delete all trashed items</span></td>
|
209 |
+
<td width="50%" valign="top"><input name="rvg_clear_trash" type="checkbox" value="Y" <?php echo $rvg_clear_trash_checked?> /></td>
|
210 |
+
</tr>
|
211 |
+
<tr>
|
212 |
+
<td width="50%" align="right" valign="top"><span style="font-weight:bold;">Delete all spammed items</span></td>
|
213 |
+
<td width="50%" valign="top"><input name="rvg_clear_spam" type="checkbox" value="Y" <?php echo $rvg_clear_spam_checked?> /></td>
|
214 |
+
</tr>
|
215 |
+
<tr>
|
216 |
+
<td width="50%" align="right" valign="top"><span style="font-weight:bold;">Logging on</span></td>
|
217 |
+
<td width="50%" valign="top"><input name="rvg_odb_logging_on" type="checkbox" value="Y" <?php echo $rvg_odb_logging_on_checked?> /></td>
|
218 |
+
</tr>
|
219 |
+
<tr>
|
220 |
+
<td width="50%" align="right" valign="top"><span style="font-weight:bold;">Scheduler</span></td>
|
221 |
+
<td width="50%" valign="top"><select name="rvg_odb_schedule" id="rvg_odb_schedule">
|
222 |
+
<option selected="selected" value="">NOT SCHEDULED</option>
|
223 |
+
<option value="hourly">run optimization HOURLY</option>
|
224 |
+
<option value="twicedaily">run optimization TWICE A DAY</option>
|
225 |
+
<option value="daily">run optimization DAILY</option>
|
226 |
+
<option value="weekly">run optimization WEEKLY</option>
|
227 |
+
</select>
|
228 |
+
<script type="text/javascript">
|
229 |
+
document.options.rvg_odb_schedule.value = '<?php echo $rvg_odb_schedule; ?>';
|
230 |
+
</script></td>
|
231 |
+
</tr>
|
232 |
+
</table></td>
|
233 |
+
</tr>
|
234 |
+
<?php
|
235 |
+
$names = mysql_list_tables(DB_NAME);
|
236 |
+
?>
|
237 |
+
<tr>
|
238 |
+
<td colspan="4" valign="top"><table id="table_list" width="100%" border="0" cellspacing="0" cellpadding="4" style="display:block;">
|
239 |
+
<tr>
|
240 |
+
<td colspan="4" align="center"><span style="font-weight:bold;">EXCLUDE DATABASE TABLES FROM OPTIMIZATION: CHECKED TABLES <u>WON'T</u> BE OPTIMIZED!</span><br />
|
241 |
+
<a href="javascript:;" onclick="$('[id^=cb_]').attr('checked',true);">check all tables</a> | <a href="javascript:;" onclick="$('[id^=cb_]').attr('checked',false);">uncheck all tables</a> | <a href="javascript:;" onclick="$(':not([id^=cb_<?php echo $table_prefix; ?>])').attr('checked',true);">check all NON-WordPress tables</a></td>
|
242 |
+
</tr>
|
243 |
+
<tr>
|
244 |
+
<?php
|
245 |
+
$c = 0;
|
246 |
+
$t = 0;
|
247 |
+
while($row = mysql_fetch_row($names))
|
248 |
+
{ $t++;
|
249 |
+
$c++;
|
250 |
+
if($c>4)
|
251 |
+
{ $c = 1;
|
252 |
+
echo '</tr>';
|
253 |
+
echo '<tr>';
|
254 |
+
}
|
255 |
+
$style = 'normal';
|
256 |
+
// WORDPRESS TABLE?
|
257 |
+
if(substr($row[0],0,strlen($table_prefix)) == $table_prefix) $style = 'bold;color:#00F;';
|
258 |
+
|
259 |
+
$cb_checked = '';
|
260 |
+
$sql = "
|
261 |
+
SELECT `option_value`
|
262 |
+
FROM $wpdb->options
|
263 |
+
WHERE `option_name` = 'rvg_ex_".$row[0]."'
|
264 |
+
";
|
265 |
+
$results = $wpdb -> get_results($sql);
|
266 |
+
if(isset($results[0]->option_value))
|
267 |
+
if($results[0]->option_value == 'excluded') $cb_checked = ' checked';
|
268 |
+
echo '<td width="25%" style="font-weight:'.$style.'"><input id="cb_'.$row[0].'" name="cb_'.$row[0].'" type="checkbox" value="1" '.$cb_checked.' /> '.$row[0].'</td>'."\n";
|
269 |
+
} # while($row = mysql_fetch_row($names))
|
270 |
+
?>
|
271 |
+
</tr>
|
272 |
+
</table></td>
|
273 |
+
</tr>
|
274 |
+
</table>
|
275 |
+
</fieldset>
|
276 |
+
</blockquote>
|
277 |
+
<p class="submit">
|
278 |
+
<input class="button-primary button-large" type='submit' name='info_update' value='Save Options' style="font-weight:bold;" />
|
279 |
+
</p>
|
280 |
+
</div>
|
281 |
+
</form>
|
282 |
+
<?php
|
283 |
+
}
|
284 |
+
|
285 |
+
|
286 |
+
/********************************************************************************************
|
287 |
+
|
288 |
+
MAIN FUNCTION FOR DELETING REVISIONS, TRASH, SPAM AND OPTIMIZING DATABASE TABLES
|
289 |
+
|
290 |
+
*********************************************************************************************/
|
291 |
+
function rvg_optimize_db()
|
292 |
+
{
|
293 |
+
global $wpdb, $odb_version, $table_prefix;
|
294 |
+
|
295 |
+
if(isset($_REQUEST['action']))
|
296 |
+
if($_REQUEST['action'] == "delete_log")
|
297 |
+
@unlink(dirname(__FILE__).'/rvg-optimize-db-log.html');
|
298 |
+
|
299 |
+
/****************************************************************************************
|
300 |
+
|
301 |
+
DELETE REVISIONS
|
302 |
+
|
303 |
+
******************************************************************************************/
|
304 |
+
|
305 |
+
// GET OPTIONS AND SET DEFAULT VALUES
|
306 |
+
$max_revisions = get_option('rvg_odb_number');
|
307 |
+
if(!$max_revisions)
|
308 |
+
{ $max_revisions = 0;
|
309 |
+
update_option('rvg_odb_number', $max_revisions);
|
310 |
+
}
|
311 |
+
|
312 |
+
$clear_trash = get_option('rvg_clear_trash');
|
313 |
+
if(!$clear_trash)
|
314 |
+
{ $clear_trash = 'N';
|
315 |
+
update_option('rvg_clear_trash', $clear_trash);
|
316 |
+
}
|
317 |
+
$clear_trash_yn = ($clear_trash == 'N') ? 'NO' : 'YES';
|
318 |
+
|
319 |
+
$clear_spam = get_option('rvg_clear_spam');
|
320 |
+
if(!$clear_spam)
|
321 |
+
{ $clear_spam = 'N';
|
322 |
+
update_option('rvg_clear_spam', $clear_spam);
|
323 |
+
}
|
324 |
+
$clear_spam_yn = ($clear_spam == 'N') ? 'NO' : 'YES';
|
325 |
+
|
326 |
+
$rvg_odb_logging_on = get_option('rvg_odb_logging_on');
|
327 |
+
if(!$rvg_odb_logging_on)
|
328 |
+
{ $rvg_odb_logging_on = 'N';
|
329 |
+
update_option('rvg_odb_logging_on', $rvg_odb_logging_on);
|
330 |
+
}
|
331 |
+
$rvg_odb_logging_on_yn = ($rvg_odb_logging_on == 'N') ? 'NO' : 'YES';
|
332 |
+
|
333 |
+
$rvg_odb_schedule = get_option('rvg_odb_schedule');
|
334 |
+
if(!$rvg_odb_schedule)
|
335 |
+
{ $rvg_odb_schedule = '';
|
336 |
+
update_option('rvg_odb_schedule', $rvg_odb_schedule);
|
337 |
+
}
|
338 |
+
|
339 |
+
if($rvg_odb_schedule == 'hourly')
|
340 |
+
$rvg_odb_schedule_txt = 'ONCE HOURLY';
|
341 |
+
else if($rvg_odb_schedule == 'twicedaily')
|
342 |
+
$rvg_odb_schedule_txt = 'TWICE DAILY';
|
343 |
+
else if($rvg_odb_schedule == 'daily')
|
344 |
+
$rvg_odb_schedule_txt = 'ONCE DAILY';
|
345 |
+
else if($rvg_odb_schedule == 'weekly')
|
346 |
+
$rvg_odb_schedule_txt = 'ONCE WEEKLY';
|
347 |
+
else if($rvg_odb_schedule == 'once_per_5_minutes')
|
348 |
+
$rvg_odb_schedule_txt = 'EVERY FIVE MINUTES';
|
349 |
+
|
350 |
+
$nextrun = '';
|
351 |
+
if(!isset($rvg_odb_schedule_txt))
|
352 |
+
{ $rvg_odb_schedule_txt = 'NOT SCHEDULED';
|
353 |
+
}
|
354 |
+
else
|
355 |
+
{ $timestamp = wp_next_scheduled('rvg_optimize_database');
|
356 |
+
$nextrun = date_i18n('M j, Y @ G:i', $timestamp);
|
357 |
+
}
|
358 |
+
|
359 |
+
$total_savings = get_option('rvg_odb_total_savings');
|
360 |
+
|
361 |
+
$log_url = plugins_url().'/rvg-optimize-database/rvg-optimize-db-log.html';
|
362 |
+
|
363 |
+
$sql = "
|
364 |
+
SELECT COUNT(*) cnt
|
365 |
+
FROM $wpdb->options op
|
366 |
+
WHERE op.option_name LIKE 'rvg_ex_%'
|
367 |
+
";
|
368 |
+
$results = $wpdb -> get_results($sql);
|
369 |
+
$number_excluded = $results[0] -> cnt;
|
370 |
+
?>
|
371 |
+
<div style="padding-left:8px;">
|
372 |
+
<h2>Optimize your WordPress Database</h2>
|
373 |
+
<?php
|
374 |
+
if(isset($_REQUEST['action']))
|
375 |
+
if($_REQUEST['action'] == "delete_log")
|
376 |
+
echo '<div class="updated" style="position:relative;left:-15px;"><p><strong>Optimize Database after Deleting Revisions - LOG FILE DELETED</strong></p></div>';
|
377 |
+
?>
|
378 |
+
<p><span style="font-style:italic;"><a href="http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/" target="_blank" style="font-weight:bold;">Optimize Database after Deleting Revisions v<?php echo $odb_version?></a> - A WordPress Plugin by <a href="http://cagewebdev.com/" target="_blank" style="font-weight:bold;">CAGE Web Design</a> | <a href="http://cage.nl/" target="_blank" style="font-weight:bold;">Rolf van Gelder</a>, Eindhoven, The Netherlands</span></p>
|
379 |
+
<p>Current options:<br />
|
380 |
+
<strong>Maximum number of - most recent - revisions to keep per post / page:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $max_revisions?></span><br />
|
381 |
+
<strong>Delete trashed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_trash_yn?></span><br />
|
382 |
+
<strong>Delete spammed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_spam_yn?></span><br />
|
383 |
+
<strong>Logging on:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $rvg_odb_logging_on_yn?></span><br />
|
384 |
+
<strong>Number of excluded tables:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $number_excluded?></span><br />
|
385 |
+
<strong>Scheduler:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $rvg_odb_schedule_txt?></span>
|
386 |
+
<?php
|
387 |
+
if($nextrun)
|
388 |
+
{
|
389 |
+
?>
|
390 |
+
<br />
|
391 |
+
<strong>Next scheduled run:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $nextrun?></span>
|
392 |
+
<?php
|
393 |
+
}
|
394 |
+
if($total_savings)
|
395 |
+
{
|
396 |
+
?>
|
397 |
+
<br />
|
398 |
+
<strong>Total savings so far:</strong> <span style="font-weight:bold;color:#00F;"><?php echo rvg_format_size($total_savings); ?></span>
|
399 |
+
<?php
|
400 |
+
}
|
401 |
+
?>
|
402 |
+
<p class="submit">
|
403 |
+
<input class="button" type="button" name="change_options" value="Change Options" onclick="self.location='options-general.php?page=rvg_odb_admin'" style="font-weight:normal;" />
|
404 |
+
<?php
|
405 |
+
if(file_exists(dirname(__FILE__).'/rvg-optimize-db-log.html'))
|
406 |
+
{
|
407 |
+
?>
|
408 |
+
|
409 |
+
<input class="button" type="button" name="view_log" value="View Log File" onclick="window.open('<?php echo $log_url?>','log','width=800,height=800,scrollbars=1')" style="font-weight:normal;" />
|
410 |
+
|
411 |
+
<input class="button" type="button" name="delete_log" value="Delete Log File" onclick="self.location='tools.php?page=rvg-optimize-db.php&action=delete_log'" style="font-weight:normal;" />
|
412 |
+
<?php
|
413 |
+
}
|
414 |
+
?>
|
415 |
+
<?php
|
416 |
+
$action = '';
|
417 |
+
if(isset($_REQUEST['action'])) $action = $_REQUEST['action'];
|
418 |
+
if($action != 'run')
|
419 |
+
{
|
420 |
+
?>
|
421 |
+
|
422 |
+
<input class="button-primary button-large" type="button" name="start_optimization" value="Start Optimization" onclick="self.location='tools.php?page=rvg-optimize-db.php&action=run'" style="font-weight:bold;" />
|
423 |
+
<?php
|
424 |
+
}
|
425 |
+
?>
|
426 |
+
</p>
|
427 |
+
</div>
|
428 |
+
<?php
|
429 |
+
$action = '';
|
430 |
+
if(isset($_REQUEST['action'])) $action = $_REQUEST['action'];
|
431 |
+
if($action != 'run') return;
|
432 |
+
?>
|
433 |
+
<h2 style="padding-left:8px;">Starting Optimization...</h2>
|
434 |
+
<?php
|
435 |
+
// GET THE SIZE OF THE DATABASE BEFORE OPTIMIZATION
|
436 |
+
$start_size = rvg_get_db_size();
|
437 |
+
|
438 |
+
// TIMESTAMP FOR LOG FILE
|
439 |
+
$log_arr = array("time" => date("m/d/Y").'<br />'.date("H:i:s"));
|
440 |
+
|
441 |
+
// FIND REVISIONS
|
442 |
+
$results = rvg_get_revisions($max_revisions);
|
443 |
+
|
444 |
+
$total_deleted = 0;
|
445 |
+
if(count($results)>0)
|
446 |
+
{ // WE HAVE REVISIONS TO DELETE!
|
447 |
+
?>
|
448 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
449 |
+
<tr>
|
450 |
+
<td colspan="4" style="font-weight:bold;color:#00F;">DELETING REVISIONS:</td>
|
451 |
+
</tr>
|
452 |
+
<tr>
|
453 |
+
<th align="right" style="border-bottom:solid 1px #999;">#</th>
|
454 |
+
<th align="left" style="border-bottom:solid 1px #999;">post / page</th>
|
455 |
+
<th align="left" style="border-bottom:solid 1px #999;">revision date</th>
|
456 |
+
<th align="right" style="border-bottom:solid 1px #999;">revisions deleted</th>
|
457 |
+
</tr>
|
458 |
+
<?php
|
459 |
+
// LOOP THROUGH THE REVISIONS AND DELETE THEM
|
460 |
+
$total_deleted = rvg_delete_revisions($results, true, $max_revisions);
|
461 |
+
?>
|
462 |
+
<tr>
|
463 |
+
<td colspan="3" align="right" style="border-top:solid 1px #999;font-weight:bold;">total number of revisions deleted</td>
|
464 |
+
<td align="right" style="border-top:solid 1px #999;font-weight:bold;"><?php echo $total_deleted?></td>
|
465 |
+
</tr>
|
466 |
+
</table>
|
467 |
+
<?php
|
468 |
+
}
|
469 |
+
else
|
470 |
+
{
|
471 |
+
?>
|
472 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
473 |
+
<tr>
|
474 |
+
<td style="font-weight:bold;color:#21759b;">No REVISIONS found to delete...</td>
|
475 |
+
</tr>
|
476 |
+
</table>
|
477 |
+
<?php
|
478 |
+
} // if(count($results)>0)
|
479 |
+
|
480 |
+
// NUMBER OF DELETED REVISIONS FOR LOG FILE
|
481 |
+
$log_arr["revisions"] = $total_deleted;
|
482 |
+
?>
|
483 |
+
<?php
|
484 |
+
/****************************************************************************************
|
485 |
+
|
486 |
+
DELETE TRASHED ITEMS
|
487 |
+
|
488 |
+
******************************************************************************************/
|
489 |
+
?>
|
490 |
+
<?php
|
491 |
+
if($clear_trash == 'Y')
|
492 |
+
{
|
493 |
+
// GET TRASHED POSTS / PAGES AND COMMENTS
|
494 |
+
$results = rvg_get_trash();
|
495 |
+
|
496 |
+
$total_deleted = 0;
|
497 |
+
if(count($results)>0)
|
498 |
+
{ // WE HAVE TRASH TO DELETE!
|
499 |
+
?>
|
500 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
|
501 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
502 |
+
<tr>
|
503 |
+
<td colspan="4" style="font-weight:bold;color:#00F;">DELETING TRASHED ITEMS:</td>
|
504 |
+
</tr>
|
505 |
+
<tr>
|
506 |
+
<th align="right" style="border-bottom:solid 1px #999;">#</th>
|
507 |
+
<th align="left" style="border-bottom:solid 1px #999;">type</th>
|
508 |
+
<th align="left" style="border-bottom:solid 1px #999;">IP address / title</th>
|
509 |
+
<th align="left" nowrap="nowrap" style="border-bottom:solid 1px #999;">date</th>
|
510 |
+
</tr>
|
511 |
+
<?php
|
512 |
+
// LOOP THROUGH THE TRASHED ITEMS AND DELETE THEM
|
513 |
+
$total_deleted = rvg_delete_trash($results, true);
|
514 |
+
?>
|
515 |
+
</table>
|
516 |
+
<?php
|
517 |
+
}
|
518 |
+
else
|
519 |
+
{
|
520 |
+
?>
|
521 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
|
522 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
523 |
+
<tr>
|
524 |
+
<td style="font-weight:bold;color:#21759b;">No TRASHED ITEMS found to delete...</td>
|
525 |
+
</tr>
|
526 |
+
</table>
|
527 |
+
<?php
|
528 |
+
} // if(count($results)>0)
|
529 |
+
|
530 |
+
// NUMBER OF DELETED TRASH FOR LOG FILE
|
531 |
+
$log_arr["trash"] = $total_deleted;
|
532 |
+
|
533 |
+
} // if($clear_trash == 'Y')
|
534 |
+
?>
|
535 |
+
<?php
|
536 |
+
/****************************************************************************************
|
537 |
+
|
538 |
+
DELETE SPAMMED ITEMS
|
539 |
+
|
540 |
+
******************************************************************************************/
|
541 |
+
?>
|
542 |
+
<?php
|
543 |
+
if($clear_spam == 'Y')
|
544 |
+
{
|
545 |
+
// GET SPAMMED COMMENTS
|
546 |
+
$results = rvg_get_spam();
|
547 |
+
|
548 |
+
$total_deleted = 0;
|
549 |
+
if(count($results)>0)
|
550 |
+
{ // WE HAVE SPAM TO DELETE!
|
551 |
+
?>
|
552 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
|
553 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
554 |
+
<tr>
|
555 |
+
<td colspan="4" style="font-weight:bold;color:#00F;">DELETING SPAMMED ITEMS:</td>
|
556 |
+
</tr>
|
557 |
+
<tr>
|
558 |
+
<th align="right" style="border-bottom:solid 1px #999;">#</th>
|
559 |
+
<th align="left" style="border-bottom:solid 1px #999;">comment author</th>
|
560 |
+
<th align="left" style="border-bottom:solid 1px #999;">comment author email</th>
|
561 |
+
<th align="left" nowrap="nowrap" style="border-bottom:solid 1px #999;">comment date</th>
|
562 |
+
</tr>
|
563 |
+
<?php
|
564 |
+
// LOOP THROUGH SPAMMED ITEMS AND DELETE THEM
|
565 |
+
$total_deleted = rvg_delete_spam($results, true);
|
566 |
+
?>
|
567 |
+
</table>
|
568 |
+
<?php
|
569 |
+
}
|
570 |
+
else
|
571 |
+
{
|
572 |
+
?>
|
573 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
|
574 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
575 |
+
<tr>
|
576 |
+
<td style="font-weight:bold;color:#21759b;">No SPAMMED ITEMS found to delete...</td>
|
577 |
+
</tr>
|
578 |
+
</table>
|
579 |
+
<?php
|
580 |
+
} // if(count($results)>0)
|
581 |
+
|
582 |
+
} // if($clear_spam == 'Y')
|
583 |
+
|
584 |
+
// NUMBER OF SPAM DELETED FOR LOG FILE
|
585 |
+
$log_arr["spam"] = $total_deleted;
|
586 |
+
?>
|
587 |
+
<?php
|
588 |
+
$total_deleted = rvg_delete_orphans(true);
|
589 |
+
if($total_deleted)
|
590 |
+
{
|
591 |
+
?>
|
592 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
|
593 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
594 |
+
<tr>
|
595 |
+
<td colspan="4"><span style="font-weight:bold;color:#00F;">NUMBER POSTMETA ORPHANS DELETED:</span> <span style="font-weight:bold;"><?php echo $total_deleted;?></span></td>
|
596 |
+
</tr>
|
597 |
+
</table>
|
598 |
+
<?php
|
599 |
+
}
|
600 |
+
else
|
601 |
+
{
|
602 |
+
?>
|
603 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
|
604 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
605 |
+
<tr>
|
606 |
+
<td style="font-weight:bold;color:#21759b;">No POSTMETA ORPHANS found to delete...</td>
|
607 |
+
</tr>
|
608 |
+
</table>
|
609 |
+
<?php
|
610 |
+
}
|
611 |
+
?>
|
612 |
+
<?php
|
613 |
+
/****************************************************************************************
|
614 |
+
|
615 |
+
OPTIMIZE DATABASE TABLES
|
616 |
+
|
617 |
+
******************************************************************************************/
|
618 |
+
?>
|
619 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
|
620 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
621 |
+
<tr>
|
622 |
+
<td colspan="4" style="font-weight:bold;color:#00F;">OPTIMIZING DATABASE TABLES:</td>
|
623 |
+
</tr>
|
624 |
+
<tr>
|
625 |
+
<th style="border-bottom:solid 1px #999;" align="right">#</th>
|
626 |
+
<th style="border-bottom:solid 1px #999;" align="left">table name</th>
|
627 |
+
<th style="border-bottom:solid 1px #999;" align="left">optimization result</th>
|
628 |
+
<th style="border-bottom:solid 1px #999;" align="left">engine</th>
|
629 |
+
<th style="border-bottom:solid 1px #999;" align="right">table rows</th>
|
630 |
+
<th style="border-bottom:solid 1px #999;" align="right">table size</th>
|
631 |
+
</tr>
|
632 |
+
<?php
|
633 |
+
# OPTIMIZE THE DATABASE TABLES
|
634 |
+
$cnt = rvg_optimize_tables(true);
|
635 |
+
?>
|
636 |
+
</table>
|
637 |
+
<?php
|
638 |
+
// NUMBER OF TABLES
|
639 |
+
$log_arr["tables"] = $cnt;
|
640 |
+
// DATABASE SIZE BEFORE OPTIMIZATION
|
641 |
+
$log_arr["before"] = rvg_format_size($start_size,3);
|
642 |
+
// DATABASE SIZE AFTER OPTIMIZATION
|
643 |
+
$end_size = rvg_get_db_size();
|
644 |
+
$log_arr["after"] = rvg_format_size($end_size,3);
|
645 |
+
// TOTAL SAVING
|
646 |
+
$log_arr["savings"] = rvg_format_size(($start_size - $end_size),3);
|
647 |
+
// WRITE RESULTS TO LOG FILE
|
648 |
+
rvg_write_log($log_arr);
|
649 |
+
|
650 |
+
$total_savings = get_option('rvg_odb_total_savings');
|
651 |
+
$total_savings += ($start_size - $end_size);
|
652 |
+
update_option('rvg_odb_total_savings',$total_savings);
|
653 |
+
?>
|
654 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
|
655 |
+
<table border="0" cellspacing="8" cellpadding="2">
|
656 |
+
<tr>
|
657 |
+
<td colspan="2" style="font-weight:bold;color:#00F;">SAVINGS:</td>
|
658 |
+
</tr>
|
659 |
+
<tr>
|
660 |
+
<th> </th>
|
661 |
+
<th style="border-bottom:solid 1px #999;">size of the database</th>
|
662 |
+
</tr>
|
663 |
+
<tr>
|
664 |
+
<td align="right">BEFORE optimization</td>
|
665 |
+
<td align="right" style="font-weight:bold;"><?php echo rvg_format_size($start_size,3); ?></td>
|
666 |
+
</tr>
|
667 |
+
<tr>
|
668 |
+
<td align="right">AFTER optimization</td>
|
669 |
+
<td align="right" style="font-weight:bold;"><?php echo rvg_format_size($end_size,3); ?></td>
|
670 |
+
</tr>
|
671 |
+
<tr>
|
672 |
+
<td align="right" style="font-weight:bold;">SAVINGS THIS TIME</td>
|
673 |
+
<td align="right" style="font-weight:bold;border-top:solid 1px #999;"><?php echo rvg_format_size(($start_size - $end_size),3); ?></td>
|
674 |
+
</tr>
|
675 |
+
<tr>
|
676 |
+
<td align="right" style="font-weight:bold;">TOTAL SAVINGS SO FAR</td>
|
677 |
+
<td align="right" style="font-weight:bold;border-top:solid 1px #999;"><?php echo rvg_format_size($total_savings,3); ?></td>
|
678 |
+
</tr>
|
679 |
+
</table>
|
680 |
+
<span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span><br />
|
681 |
+
<br />
|
682 |
+
<span style="font-weight:bold;color:#00F;padding-left:8px;">DONE!</span><br />
|
683 |
+
<br />
|
684 |
+
<?php
|
685 |
+
if(file_exists(dirname(__FILE__).'/rvg-optimize-db-log.html'))
|
686 |
+
{
|
687 |
+
?>
|
688 |
+
|
689 |
+
<input class="button" type="button" name="view_log" value="View Log File" onclick="window.open('<?php echo $log_url?>','log','width=800,height=800,scrollbars=1')" style="font-weight:normal;" />
|
690 |
+
|
691 |
+
<input class="button" type="button" name="delete_log" value="Delete Log File" onclick="self.location='tools.php?page=rvg-optimize-db.php&action=delete_log'" style="font-weight:normal;" />
|
692 |
+
<?php
|
693 |
+
}
|
694 |
+
?>
|
695 |
+
<?php
|
696 |
+
} // rvg_optimize_db()
|
697 |
+
?>
|
698 |
+
<?php
|
699 |
+
/********************************************************************************************
|
700 |
+
|
701 |
+
EXECUTE OPTIMIZATION VIA CRON JOB
|
702 |
+
|
703 |
+
*********************************************************************************************/
|
704 |
+
function rvg_optimize_db_cron()
|
705 |
+
{
|
706 |
+
global $wpdb, $odb_version, $table_prefix;
|
707 |
+
|
708 |
+
// GET OPTIONS AND SET DEFAULT VALUES
|
709 |
+
$max_revisions = get_option('rvg_odb_number');
|
710 |
+
if(!$max_revisions)
|
711 |
+
{ $max_revisions = 0;
|
712 |
+
update_option('rvg_odb_number', $max_revisions);
|
713 |
+
}
|
714 |
+
|
715 |
+
$clear_trash = get_option('rvg_clear_trash');
|
716 |
+
if(!$clear_trash)
|
717 |
+
{ $clear_trash = 'N';
|
718 |
+
update_option('rvg_clear_trash', $clear_trash);
|
719 |
+
}
|
720 |
+
|
721 |
+
$clear_spam = get_option('rvg_clear_spam');
|
722 |
+
if(!$clear_spam)
|
723 |
+
{ $clear_spam = 'N';
|
724 |
+
update_option('rvg_clear_spam', $clear_spam);
|
725 |
+
}
|
726 |
+
|
727 |
+
// GET THE SIZE OF THE DATABASE BEFORE OPTIMIZATION
|
728 |
+
$start_size = rvg_get_db_size();
|
729 |
+
|
730 |
+
// TIMESTAMP FOR LOG FILE
|
731 |
+
$log_arr = array("time" => date("m/d/Y").'<br />'.date("H:i:s"));
|
732 |
+
|
733 |
+
// FIND THE REVISIONS
|
734 |
+
$results = rvg_get_revisions($max_revisions);
|
735 |
+
|
736 |
+
$total_deleted = 0;
|
737 |
+
if(count($results)>0)
|
738 |
+
// WE HAVE REVISIONS TO DELETE!
|
739 |
+
$total_deleted = rvg_delete_revisions($results, false, $max_revisions);
|
740 |
+
|
741 |
+
// NUMBER OF DELETED REVISIONS FOR LOG FILE
|
742 |
+
$log_arr["revisions"] = $total_deleted;
|
743 |
+
|
744 |
+
$total_deleted = 0;
|
745 |
+
if($clear_trash == 'Y')
|
746 |
+
{
|
747 |
+
// GET TRASHED POSTS / PAGES AND COMMENTS
|
748 |
+
$results = rvg_get_trash();
|
749 |
+
|
750 |
+
if(count($results)>0)
|
751 |
+
// WE HAVE TRASH TO DELETE!
|
752 |
+
$total_deleted = rvg_delete_trash($results, false, $max_revisions);
|
753 |
+
|
754 |
+
} // if($clear_trash == 'Y')
|
755 |
+
|
756 |
+
// NUMBER OF DELETED TRASH FOR LOG FILE
|
757 |
+
$log_arr["trash"] = $total_deleted;
|
758 |
+
|
759 |
+
$total_deleted = 0;
|
760 |
+
if($clear_spam == 'Y')
|
761 |
+
{
|
762 |
+
// GET SPAMMED COMMENTS
|
763 |
+
$results = rvg_get_spam();
|
764 |
+
|
765 |
+
if(count($results)>0)
|
766 |
+
// WE HAVE SPAM TO DELETE!
|
767 |
+
$total_deleted = rvg_delete_spam($results, false);
|
768 |
+
|
769 |
+
} // if($clear_spam == 'Y')
|
770 |
+
|
771 |
+
// NUMBER OF SPAM DELETED FOR LOG FILE
|
772 |
+
$log_arr["spam"] = $total_deleted;
|
773 |
+
|
774 |
+
// OPTIMIZE DATABASE TABLES
|
775 |
+
$cnt = rvg_optimize_tables(false);
|
776 |
+
|
777 |
+
// NUMBER OF TABLES
|
778 |
+
$log_arr["tables"] = $cnt;
|
779 |
+
// DATABASE SIZE BEFORE OPTIMIZATION
|
780 |
+
$log_arr["before"] = rvg_format_size($start_size,3);
|
781 |
+
// DATABASE SIZE AFTER OPTIMIZATION
|
782 |
+
$end_size = rvg_get_db_size();
|
783 |
+
$log_arr["after"] = rvg_format_size($end_size,3);
|
784 |
+
// TOTAL SAVING
|
785 |
+
$log_arr["savings"] = rvg_format_size(($start_size - $end_size),3);
|
786 |
+
// WRITE RESULTS TO LOG FILE
|
787 |
+
rvg_write_log($log_arr);
|
788 |
+
|
789 |
+
$total_savings = get_option('rvg_odb_total_savings');
|
790 |
+
$total_savings += ($start_size - $end_size);
|
791 |
+
update_option('rvg_odb_total_savings',$total_savings);
|
792 |
+
|
793 |
+
} // rvg_optimize_db_cron()
|
794 |
+
?>
|
795 |
+
<?php
|
796 |
+
/********************************************************************************************
|
797 |
+
|
798 |
+
DELETE THE REVISIONS
|
799 |
+
|
800 |
+
*********************************************************************************************/
|
801 |
+
function rvg_delete_revisions($results, $display, $max_revisions)
|
802 |
+
{
|
803 |
+
global $wpdb;
|
804 |
+
|
805 |
+
$nr = 1;
|
806 |
+
$total_deleted = 0;
|
807 |
+
|
808 |
+
for($i=0; $i<count($results); $i++)
|
809 |
+
{ $nr_to_delete = $results[$i]->cnt - $max_revisions;
|
810 |
+
$total_deleted += $nr_to_delete;
|
811 |
+
if($display)
|
812 |
+
{
|
813 |
+
?>
|
814 |
+
<tr>
|
815 |
+
<td align="right" valign="top"><?php echo $nr?>.</td>
|
816 |
+
<td valign="top" style="font-weight:bold;"><?php echo $results[$i]->post_title?></td>
|
817 |
+
<td valign="top"><?php
|
818 |
+
} // if($display)
|
819 |
+
|
820 |
+
$sql_get_posts = "
|
821 |
+
SELECT `ID`, `post_modified`
|
822 |
+
FROM $wpdb->posts
|
823 |
+
WHERE `post_parent`=".$results[$i]->post_parent."
|
824 |
+
AND `post_type`='revision'
|
825 |
+
ORDER BY `post_modified` ASC
|
826 |
+
";
|
827 |
+
$results_get_posts = $wpdb -> get_results($sql_get_posts);
|
828 |
+
|
829 |
+
for($j=0; $j<$nr_to_delete; $j++)
|
830 |
+
{
|
831 |
+
if($display) echo $results_get_posts[$j]->post_modified.'<br />';
|
832 |
+
|
833 |
+
$sql_delete = "
|
834 |
+
DELETE FROM $wpdb->posts
|
835 |
+
WHERE `ID` = ".$results_get_posts[$j]->ID."
|
836 |
+
";
|
837 |
+
$wpdb -> get_results($sql_delete);
|
838 |
+
|
839 |
+
} // for($j=0; $j<$nr_to_delete; $j++)
|
840 |
+
|
841 |
+
$nr++;
|
842 |
+
if($display)
|
843 |
+
{
|
844 |
+
?></td>
|
845 |
+
<td align="right" valign="top" style="font-weight:bold;"><?php echo $nr_to_delete?></td>
|
846 |
+
</tr>
|
847 |
+
<?php
|
848 |
+
} // if($display)
|
849 |
+
} // for($i=0; $i<count($results); $i++)
|
850 |
+
return $total_deleted;
|
851 |
+
} // rvg_delete_revisions()
|
852 |
+
?>
|
853 |
+
<?php
|
854 |
+
/********************************************************************************************
|
855 |
+
|
856 |
+
DELETE TRASHED POSTS AND PAGES
|
857 |
+
|
858 |
+
*********************************************************************************************/
|
859 |
+
function rvg_delete_trash($results, $display)
|
860 |
+
{
|
861 |
+
global $wpdb;
|
862 |
+
|
863 |
+
$nr = 1;
|
864 |
+
$total_deleted = count($results);
|
865 |
+
for($i=0; $i<count($results); $i++)
|
866 |
+
{ if($display)
|
867 |
+
{
|
868 |
+
?>
|
869 |
+
<tr>
|
870 |
+
<td align="right" valign="top"><?php echo $nr; ?></td>
|
871 |
+
<td valign="top"><?php echo $results[$i]->post_type; ?></td>
|
872 |
+
<td valign="top"><?php echo $results[$i]->title; ?></td>
|
873 |
+
<td valign="top" nowrap="nowrap"><?php echo $results[$i]->modified; ?></td>
|
874 |
+
</tr>
|
875 |
+
<?php
|
876 |
+
}
|
877 |
+
if($results[$i]->post_type == 'comment')
|
878 |
+
{ // DELETE META DATA (IF ANY...)
|
879 |
+
$sql_delete = "
|
880 |
+
DELETE FROM $wpdb->commentmeta WHERE `comment_id` = ".$results[$i]->id."
|
881 |
+
";
|
882 |
+
$wpdb -> get_results($sql_delete);
|
883 |
+
}
|
884 |
+
|
885 |
+
$nr++;
|
886 |
+
} // for($i=0; $i<count($results); $i++)
|
887 |
+
|
888 |
+
// DELETE TRASHED POSTS / PAGES
|
889 |
+
$sql_delete = "
|
890 |
+
DELETE FROM $wpdb->posts WHERE `post_status` = 'trash'
|
891 |
+
";
|
892 |
+
$wpdb -> get_results($sql_delete);
|
893 |
+
|
894 |
+
// DELETE TRASHED COMMENTS
|
895 |
+
$sql_delete = "
|
896 |
+
DELETE FROM $wpdb->comments WHERE `comment_approved` = 'trash'
|
897 |
+
";
|
898 |
+
$wpdb -> get_results($sql_delete);
|
899 |
+
|
900 |
+
return $total_deleted;
|
901 |
+
|
902 |
+
} // rvg_delete_trash()
|
903 |
+
?>
|
904 |
+
<?php
|
905 |
+
/********************************************************************************************
|
906 |
+
|
907 |
+
DELETE SPAMMED ITEMS
|
908 |
+
|
909 |
+
*********************************************************************************************/
|
910 |
+
function rvg_delete_spam($results, $display)
|
911 |
+
{
|
912 |
+
global $wpdb;
|
913 |
+
|
914 |
+
$nr = 1;
|
915 |
+
$total_deleted = count($results);
|
916 |
+
for($i=0; $i<count($results); $i++)
|
917 |
+
{ if($display)
|
918 |
+
{
|
919 |
+
?>
|
920 |
+
<tr>
|
921 |
+
<td align="right" valign="top"><?php echo $nr; ?></td>
|
922 |
+
<td valign="top"><?php echo $results[$i]->comment_author; ?></td>
|
923 |
+
<td valign="top"><?php echo $results[$i]->comment_author_email; ?></td>
|
924 |
+
<td valign="top" nowrap="nowrap"><?php echo $results[$i]->comment_date; ?></td>
|
925 |
+
</tr>
|
926 |
+
<?php
|
927 |
+
} // if($display)
|
928 |
+
$sql_delete = "
|
929 |
+
DELETE FROM $wpdb->commentmeta WHERE `comment_id` = ".$results[$i]->comment_ID."
|
930 |
+
";
|
931 |
+
$wpdb -> get_results($sql_delete);
|
932 |
+
$nr++;
|
933 |
+
} // for($i=0; $i<count($results); $i++)
|
934 |
+
|
935 |
+
$sql_delete = "
|
936 |
+
DELETE FROM $wpdb->comments WHERE `comment_approved` = 'spam'
|
937 |
+
";
|
938 |
+
$wpdb -> get_results($sql_delete);
|
939 |
+
|
940 |
+
return $total_deleted;
|
941 |
+
|
942 |
+
} // rvg_delete_spam()
|
943 |
+
?>
|
944 |
+
<?php
|
945 |
+
/********************************************************************************************
|
946 |
+
|
947 |
+
DELETE ORPHAN POSTMETA RECORDS
|
948 |
+
|
949 |
+
*********************************************************************************************/
|
950 |
+
function rvg_delete_orphans($display)
|
951 |
+
{
|
952 |
+
global $wpdb;
|
953 |
+
|
954 |
+
$sql_delete = "
|
955 |
+
SELECT COUNT(*) cnt
|
956 |
+
FROM $wpdb->postmeta
|
957 |
+
WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)
|
958 |
+
";
|
959 |
+
|
960 |
+
$results = $wpdb -> get_results($sql_delete);
|
961 |
+
|
962 |
+
$total_deleted = $results[0] -> cnt;
|
963 |
+
|
964 |
+
if($total_deleted > 0)
|
965 |
+
{ $sql_delete = "
|
966 |
+
DELETE FROM $wpdb->postmeta
|
967 |
+
WHERE post_id NOT IN (SELECT ID FROM $wpdb->posts)
|
968 |
+
";
|
969 |
+
$wpdb -> get_results($sql_delete);
|
970 |
+
}
|
971 |
+
|
972 |
+
return $total_deleted;
|
973 |
+
|
974 |
+
} // rvg_delete_orphans()
|
975 |
+
?>
|
976 |
+
<?php
|
977 |
+
/********************************************************************************************
|
978 |
+
|
979 |
+
OPTIMIZE DATABASE TABLES
|
980 |
+
|
981 |
+
*********************************************************************************************/
|
982 |
+
function rvg_optimize_tables($display)
|
983 |
+
{
|
984 |
+
global $wpdb, $table_prefix;
|
985 |
+
|
986 |
+
# WP_ONLY IS DEPRECIATED FROM v2.2
|
987 |
+
rvg_fix_wp_only();
|
988 |
+
|
989 |
+
$names = mysql_list_tables(DB_NAME);
|
990 |
+
$cnt = 0;
|
991 |
+
while($row = mysql_fetch_row($names))
|
992 |
+
{
|
993 |
+
$excluded = get_option('rvg_ex_'.$row[0]);
|
994 |
+
|
995 |
+
if(!$excluded)
|
996 |
+
{ # TABLE NOT EXCLUDED
|
997 |
+
$cnt++;
|
998 |
+
$query = "OPTIMIZE TABLE ".$row[0];
|
999 |
+
$result = $wpdb -> get_results($query);
|
1000 |
+
|
1001 |
+
$sql = "
|
1002 |
+
SELECT engine, SUM(data_length + index_length) AS size, table_rows
|
1003 |
+
FROM information_schema.TABLES
|
1004 |
+
WHERE table_schema = '".strtolower(DB_NAME)."'
|
1005 |
+
AND table_name = '".$row[0]."'
|
1006 |
+
";
|
1007 |
+
|
1008 |
+
$table_info = $wpdb -> get_results($sql);
|
1009 |
+
|
1010 |
+
if($display)
|
1011 |
+
{
|
1012 |
+
?>
|
1013 |
+
<tr>
|
1014 |
+
<td align="right" valign="top"><?php echo $cnt?>.</td>
|
1015 |
+
<td valign="top" style="font-weight:bold;"><?php echo $row[0] ?></td>
|
1016 |
+
<td valign="top"><?php echo $result[0]->Msg_text ?></td>
|
1017 |
+
<td valign="top"><?php echo $table_info[0]->engine ?></td>
|
1018 |
+
<td align="right" valign="top"><?php echo $table_info[0]->table_rows ?></td>
|
1019 |
+
<td align="right" valign="top"><?php echo rvg_format_size($table_info[0]->size) ?></td>
|
1020 |
+
</tr>
|
1021 |
+
<?php
|
1022 |
+
} // if($display)
|
1023 |
+
} // if($wp_only == 'N' || ($wp_only == 'Y' && substr($row[0],0,strlen($table_prefix)) == $table_prefix))
|
1024 |
+
} // while($row = mysql_fetch_row($names))
|
1025 |
+
|
1026 |
+
return $cnt;
|
1027 |
+
|
1028 |
+
} // rvg_optimize_tables()
|
1029 |
+
?>
|
1030 |
+
<?php
|
1031 |
+
/********************************************************************************************
|
1032 |
+
|
1033 |
+
FIX WP_ONLY (DEPRECIATED FROM v2.2)
|
1034 |
+
|
1035 |
+
*********************************************************************************************/
|
1036 |
+
function rvg_fix_wp_only()
|
1037 |
+
{
|
1038 |
+
global $wpdb, $table_prefix;
|
1039 |
+
|
1040 |
+
$wp_only = get_option('rvg_wp_only');
|
1041 |
+
if($wp_only == 'Y')
|
1042 |
+
{
|
1043 |
+
$names = mysql_list_tables(DB_NAME);
|
1044 |
+
while($row = mysql_fetch_row($names))
|
1045 |
+
{ if(substr($row[0],0,strlen($table_prefix)) != $table_prefix)
|
1046 |
+
{ // NOT A WORDPRESS TABLE: EXLUDE IT
|
1047 |
+
$sql = "
|
1048 |
+
INSERT INTO $wpdb->options (option_name, option_value, autoload)
|
1049 |
+
VALUES ('rvg_ex_".$row[0]."','excluded','yes')
|
1050 |
+
";
|
1051 |
+
$wpdb -> get_results($sql);
|
1052 |
+
}
|
1053 |
+
}
|
1054 |
+
}
|
1055 |
+
$sql = "
|
1056 |
+
DELETE FROM $wpdb->options
|
1057 |
+
WHERE `option_name` = 'rvg_wp_only'
|
1058 |
+
";
|
1059 |
+
$wpdb -> get_results($sql);
|
1060 |
+
|
1061 |
+
} # function rvg_fix_wp_only()
|
1062 |
+
?>
|
1063 |
+
<?php
|
1064 |
+
/********************************************************************************************
|
1065 |
+
|
1066 |
+
WRITE LINE TO LOG FILE
|
1067 |
+
|
1068 |
+
*********************************************************************************************/
|
1069 |
+
function rvg_write_log($log_arr)
|
1070 |
+
{
|
1071 |
+
global $odb_version;
|
1072 |
+
|
1073 |
+
$rvg_odb_logging_on = get_option('rvg_odb_logging_on');
|
1074 |
+
if(!$rvg_odb_logging_on)
|
1075 |
+
{ $rvg_odb_logging_on = 'N';
|
1076 |
+
update_option('rvg_odb_logging_on', $rvg_odb_logging_on);
|
1077 |
+
}
|
1078 |
+
|
1079 |
+
if($rvg_odb_logging_on == "Y")
|
1080 |
+
{ $file = dirname(__FILE__).'/rvg-optimize-db-log.html';
|
1081 |
+
if(!file_exists($file))
|
1082 |
+
{
|
1083 |
+
// NEW LOG FILE
|
1084 |
+
$html = '
|
1085 |
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
1086 |
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
1087 |
+
<head>
|
1088 |
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
1089 |
+
<title>Untitled Document</title>
|
1090 |
+
<style type="text/css">
|
1091 |
+
body, td, th {
|
1092 |
+
font-family: Arial, Helvetica, sans-serif;
|
1093 |
+
font-size: 12px;
|
1094 |
+
}
|
1095 |
+
th {
|
1096 |
+
border-top:solid 1px #000;
|
1097 |
+
border-bottom:solid 1px #000;
|
1098 |
+
}
|
1099 |
+
td {
|
1100 |
+
padding-bottom:4px;
|
1101 |
+
border-bottom:dotted 1px #CCC;
|
1102 |
+
}
|
1103 |
+
#header {
|
1104 |
+
margin-left:6px;
|
1105 |
+
margin-bottom:8px;
|
1106 |
+
}
|
1107 |
+
#header a {
|
1108 |
+
text-decoration:none;
|
1109 |
+
font-weight:bold;
|
1110 |
+
}
|
1111 |
+
</style>
|
1112 |
+
</head>
|
1113 |
+
<body>
|
1114 |
+
<div id="header">
|
1115 |
+
<h2><a href="http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/" target="_blank">Optimize Database after Deleting Revisions v'.$odb_version.'</a></h2>
|
1116 |
+
A WordPress Plugin by <a href="http://cagewebdev.com" target="_blank"><strong>CAGE Web Design | Rolf van Gelder</strong></a>, Eindhoven, The Netherlands</strong>
|
1117 |
+
</div>
|
1118 |
+
<table width="100%" border="0" cellspacing="6" cellpadding="1">
|
1119 |
+
<tr>
|
1120 |
+
<th width="12%" align="left" valign="top">time</th>
|
1121 |
+
<th width="12%" align="right" valign="top">deleted<br />
|
1122 |
+
revisions</th>
|
1123 |
+
<th width="12%" align="right" valign="top">deleted<br />
|
1124 |
+
trash</th>
|
1125 |
+
<th width="12%" align="right" valign="top">deleted<br />
|
1126 |
+
spam</th>
|
1127 |
+
<th width="12%" align="right" valign="top">nr of optimized tables</th>
|
1128 |
+
<th width="12%" align="right" valign="top">database size BEFORE</th>
|
1129 |
+
<th width="12%" align="right" valign="top">database size AFTER</th>
|
1130 |
+
<th width="12%" align="right" valign="top">SAVINGS</th>
|
1131 |
+
</tr>
|
1132 |
+
</table>
|
1133 |
+
';
|
1134 |
+
|
1135 |
+
// file_put_contents($file,'<strong><a href="http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/" target="_blank" style="font-weight:bold;text-decoration:none;">Optimize Database after Deleting Revisions v'.$odb_version.'</a><br />A WordPress Plugin by <a href="http://cagewebdev.com" target="_blank" style="text-decoration:none;">CAGE Web Design | Rolf van Gelder</a>, Eindhoven, The Netherlands</strong><hr noshade="noshade" size="1">');
|
1136 |
+
file_put_contents($file,$html,FILE_APPEND);
|
1137 |
+
}
|
1138 |
+
|
1139 |
+
$html = '
|
1140 |
+
<table width="100%" border="0" cellspacing="6" cellpadding="0">
|
1141 |
+
<tr>
|
1142 |
+
<td width="12%" valign="top"><strong>'.$log_arr["time"].'</strong></td>
|
1143 |
+
<td width="12%" align="right" valign="top">'.$log_arr["revisions"].'</td>
|
1144 |
+
<td width="12%" align="right" valign="top">'.$log_arr["trash"].'</td>
|
1145 |
+
<td width="12%" align="right" valign="top">'.$log_arr["spam"].'</td>
|
1146 |
+
<td width="12%" align="right" valign="top">'.$log_arr["tables"].'</td>
|
1147 |
+
<td width="12%" align="right" valign="top">'.$log_arr["before"].'</td>
|
1148 |
+
<td width="12%" align="right" valign="top">'.$log_arr["after"].'</td>
|
1149 |
+
<td width="12%" align="right" valign="top">'.$log_arr["savings"].'</td>
|
1150 |
+
</tr>
|
1151 |
+
</table>
|
1152 |
+
';
|
1153 |
+
|
1154 |
+
// print_r($log_arr);
|
1155 |
+
file_put_contents($file,$html,FILE_APPEND);
|
1156 |
+
}
|
1157 |
+
|
1158 |
+
} // rvg_write_log
|
1159 |
+
?>
|
1160 |
+
<?php
|
1161 |
+
/********************************************************************************************
|
1162 |
+
|
1163 |
+
GET REVISIONS
|
1164 |
+
|
1165 |
+
*********************************************************************************************/
|
1166 |
+
function rvg_get_revisions($max_revisions)
|
1167 |
+
{
|
1168 |
+
global $wpdb;
|
1169 |
+
|
1170 |
+
$sql = "
|
1171 |
+
SELECT `post_parent`, `post_title`, COUNT(*) cnt
|
1172 |
+
FROM $wpdb->posts
|
1173 |
+
WHERE `post_type` = 'revision'
|
1174 |
+
GROUP BY `post_parent`
|
1175 |
+
HAVING COUNT(*) > ".$max_revisions."
|
1176 |
+
ORDER BY UCASE(`post_title`)
|
1177 |
+
";
|
1178 |
+
// echo $sql.'<br />';
|
1179 |
+
return $wpdb -> get_results($sql);
|
1180 |
+
|
1181 |
+
} // rvg_get_revisions()
|
1182 |
+
?>
|
1183 |
+
<?php
|
1184 |
+
/********************************************************************************************
|
1185 |
+
|
1186 |
+
GET TRASHED POSTS / PAGES AND COMMENTS
|
1187 |
+
|
1188 |
+
*********************************************************************************************/
|
1189 |
+
function rvg_get_trash()
|
1190 |
+
{
|
1191 |
+
global $wpdb;
|
1192 |
+
|
1193 |
+
$sql = "
|
1194 |
+
SELECT `ID` AS id, 'post' AS post_type, `post_title` AS title, `post_modified` AS modified
|
1195 |
+
FROM $wpdb->posts
|
1196 |
+
WHERE `post_status` = 'trash'
|
1197 |
+
UNION ALL
|
1198 |
+
SELECT `comment_ID` AS id, 'comment' AS post_type, `comment_author_IP` AS title, `comment_date` AS modified
|
1199 |
+
FROM $wpdb->comments
|
1200 |
+
WHERE `comment_approved` = 'trash'
|
1201 |
+
ORDER BY post_type, UCASE(title)
|
1202 |
+
";
|
1203 |
+
return $wpdb -> get_results($sql);
|
1204 |
+
|
1205 |
+
} // rvg_get_trash()
|
1206 |
+
?>
|
1207 |
+
<?php
|
1208 |
+
/********************************************************************************************
|
1209 |
+
|
1210 |
+
GET SPAMMED COMMENTS
|
1211 |
+
|
1212 |
+
*********************************************************************************************/
|
1213 |
+
function rvg_get_spam()
|
1214 |
+
{
|
1215 |
+
global $wpdb;
|
1216 |
+
|
1217 |
+
$sql = "
|
1218 |
+
SELECT `comment_ID`, `comment_author`, `comment_author_email`, `comment_date`
|
1219 |
+
FROM $wpdb->comments
|
1220 |
+
WHERE `comment_approved` = 'spam'
|
1221 |
+
ORDER BY UCASE(`comment_author`)
|
1222 |
+
";
|
1223 |
+
return $wpdb -> get_results($sql);
|
1224 |
+
|
1225 |
+
} // rvg_get_trash()
|
1226 |
+
?>
|
1227 |
+
<?php
|
1228 |
+
/********************************************************************************************
|
1229 |
+
|
1230 |
+
CALCULATE THE SIZE OF THE WORDPRESS DATABASE (IN BYTES)
|
1231 |
+
|
1232 |
+
*********************************************************************************************/
|
1233 |
+
function rvg_get_db_size()
|
1234 |
+
{
|
1235 |
+
global $wpdb;
|
1236 |
+
|
1237 |
+
$sql = "
|
1238 |
+
SELECT SUM(data_length + index_length) AS size
|
1239 |
+
FROM information_schema.TABLES
|
1240 |
+
WHERE table_schema = '".strtolower(DB_NAME)."'
|
1241 |
+
";
|
1242 |
+
|
1243 |
+
$res = $wpdb -> get_results($sql);
|
1244 |
+
|
1245 |
+
return $res[0]->size;
|
1246 |
+
|
1247 |
+
} // rvg_get_db_size()
|
1248 |
+
?>
|
1249 |
+
<?php
|
1250 |
+
/********************************************************************************************
|
1251 |
+
|
1252 |
+
FORMAT SIZES FROM BYTES TO KB OR MB
|
1253 |
+
|
1254 |
+
*********************************************************************************************/
|
1255 |
+
function rvg_format_size($size, $precision=1)
|
1256 |
+
{
|
1257 |
+
if($size>1024*1024)
|
1258 |
+
$table_size = (round($size/(1024*1024),$precision)).' MB';
|
1259 |
+
else
|
1260 |
+
$table_size = (round($size/1024,$precision)).' KB';
|
1261 |
+
|
1262 |
+
return $table_size;
|
1263 |
+
} // rvg_format_size()
|
1264 |
+
?>
|