Optimize Database after Deleting Revisions - Version 2.5

Version Description

[05/24/2013] = * NEW: you can set a time (hour) for the scheduler to run (thanks to frekel) * NEW: '1-click run button' in the admin bar (thanks to JB ORSI)

Download this release

Release Info

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

Code changes from version 2.4.2 to 2.5

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