Optimize Database after Deleting Revisions - Version 2.3

Version Description

[04/26/2013] = * BUG FIX: fixed the 'Stealing Cron Schedules' issue

Download this release

Release Info

Developer cageehv
Plugin Icon 128x128 Optimize Database after Deleting Revisions
Version 2.3
Comparing to
See all releases

Code changes from version 2.2.9 to 2.3

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