Optimize Database after Deleting Revisions - Version 1.3

Version Description

No Upgrade Notice available.

Download this release

Release Info

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

Code changes from version 1.2 to 1.3

Files changed (2) hide show
  1. readme.txt +5 -4
  2. rvg-optimize-db.php +80 -14
readme.txt CHANGED
@@ -4,13 +4,13 @@ Contributors: Rolf van Gelder
4
  Donate link: http://cagewebdev.com
5
  Plugin Name: Optimize Database after Deleting Revisions
6
  Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin
7
- Tags: wp, database, delete, revisions, optimize, posts, pages, clean up, trash, spam, trashed, spammed
8
  Author URI: http://cagewebdev.com
9
  Author: Rolf van Gelder, Eindhoven, The Netherlands
10
  Requires at least: 2.0
11
  Tested up to: 3.4.2
12
- Stable tag: 1.2
13
- Version: 1.2
14
 
15
  == Description ==
16
 
@@ -53,12 +53,13 @@ No Screenshots available.
53
  <p><b>1.1.8</b> 09/08/2012 Another link fix</p>
54
  <p><b>1.1.9</b> 09/27/2012 Using a different method for retrieving database table names</p>
55
  <p><b>1.2</b> 10/03/2012 Major update: new options 'delete trash', 'delete spam', 'only optimize WordPress tables'</p>
 
56
 
57
  == Frequently Asked Questions ==
58
 
59
  <p><b>Q:</b> <em>How can I change the settings of this plugin?</em></p>
60
  <p><b>A:</b> In the WordPress Dashboard go to '<b>Settings / Optimize DB Options</b>'. There you can define the maximum number of - most recent - revisions you want to keep per post or page.</p>
61
  <p><b>Q:</b> <em>How do I run this plugin?</em></p>
62
- <p><b>A:</b> In the WordPress Dashboard go to '<b>Tools</b>'. Click on '<b>Optimize Database</b>'. Et voila!</p>
63
  <p><b>Q:</b> <em>Why do I see 'Table does not support optimize, doing recreate + analyze instead' while optimizing my database?</em></p>
64
  <p><b>A:</b> That is because the table type of that table is not 'MyISAM'</p>
4
  Donate link: http://cagewebdev.com
5
  Plugin Name: Optimize Database after Deleting Revisions
6
  Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin
7
+ Tags: database, delete, revisions, optimize, post, posts, page, pages, clean up, trash, spam, trashed, spammed
8
  Author URI: http://cagewebdev.com
9
  Author: Rolf van Gelder, Eindhoven, The Netherlands
10
  Requires at least: 2.0
11
  Tested up to: 3.4.2
12
+ Stable tag: 1.3
13
+ Version: 1.3
14
 
15
  == Description ==
16
 
53
  <p><b>1.1.8</b> 09/08/2012 Another link fix</p>
54
  <p><b>1.1.9</b> 09/27/2012 Using a different method for retrieving database table names</p>
55
  <p><b>1.2</b> 10/03/2012 Major update: new options 'delete trash', 'delete spam', 'only optimize WordPress tables'</p>
56
+ <p><b>1.3</b> 10/06/2012 Extra button for starting optimization, shows savings (in bytes) now</p>
57
 
58
  == Frequently Asked Questions ==
59
 
60
  <p><b>Q:</b> <em>How can I change the settings of this plugin?</em></p>
61
  <p><b>A:</b> In the WordPress Dashboard go to '<b>Settings / Optimize DB Options</b>'. There you can define the maximum number of - most recent - revisions you want to keep per post or page.</p>
62
  <p><b>Q:</b> <em>How do I run this plugin?</em></p>
63
+ <p><b>A:</b> In the WordPress Dashboard go to '<b>Tools</b>'. Click on '<b>Optimize Database</b>'. Then click the 'Start Optimization'-button. Et voila!</p>
64
  <p><b>Q:</b> <em>Why do I see 'Table does not support optimize, doing recreate + analyze instead' while optimizing my database?</em></p>
65
  <p><b>A:</b> That is because the table type of that table is not 'MyISAM'</p>
rvg-optimize-db.php CHANGED
@@ -1,16 +1,16 @@
1
  <?php
2
- $version = '1.2';
3
- $release_date = '03/10/2012';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
- * @version 1.2
7
  */
8
  /*
9
  Plugin Name: Optimize Database after Deleting Revisions
10
  Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-revisions-wordpress-plugin/
11
  Description: Optimizes the Wordpress Database after Deleting Revisions - <a href="options-general.php?page=rvg_odb_admin"><strong>plug in options</strong></a>
12
  Author: Rolf van Gelder, Eindhoven, The Netherlands
13
- Version: 1.2
14
  Author URI: http://cagewebdev.com
15
  */
16
  ?>
@@ -69,7 +69,7 @@ function rvg_odb_options_page() {
69
  update_option('rvg_wp_only', $rvg_wp_only);
70
 
71
  // UPDATED MESSAGE
72
- 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>";
73
  }
74
  $rvg_odb_number = get_option('rvg_odb_number');
75
  if(!$rvg_odb_number) $rvg_odb_number = '0';
@@ -97,7 +97,7 @@ function rvg_odb_options_page() {
97
  <p>You also can choose if you want to <u>delete</u> all <u>trashed items</u> and/or <u>spammed items</u> during the optimization.</p>
98
  <p>To start the optimization:<br />
99
  In the WordPress Dashboard go to &lsquo;<strong>Tools</strong>&lsquo;.<br />
100
- Click on &lsquo;<strong>Optimize Database</strong>&lsquo;. Et voila! </p>
101
  <p>Plugin version:<br />
102
  <strong>v<?php echo $version ?> (<?php echo $release_date?>)</strong> </p>
103
  <p>Author:<br />
@@ -144,7 +144,7 @@ if($rvg_wp_only == 'Y') $rvg_wp_only_checked = ' checked="checked"'; els
144
  </fieldset>
145
  </blockquote>
146
  <p class="submit">
147
- <input type='submit' name='info_update' value='Save Options' />
148
  </p>
149
  </div>
150
  </form>
@@ -194,18 +194,37 @@ function rvg_optimize_db()
194
  $wp_only_yn = ($wp_only == 'N') ? 'NO' : 'YES';
195
  ?>
196
  <div style="padding-left:8px;">
197
- <h2>Optimizing your WordPress Database</h2>
198
  <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 $version?></a> - A WordPress Plugin by <a href="http://cagewebdev.com/" target="_blank" style="font-weight:bold;">Rolf van Gelder</a>, Eindhoven, The Netherlands</span></p>
199
- <p><span style="font-style:normal;">Current options:<br />
200
  <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 />
201
  <strong>Delete trashed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_trash_yn?></span><br />
202
  <strong>Delete spammed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_spam_yn?></span><br />
203
- <strong>Only optimize WordPress tables:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $wp_only_yn?></span><br />
204
- <br />
205
- Click <a href="options-general.php?page=rvg_odb_admin" style="font-weight:bold;">HERE</a> to change the above options.</span></p>
206
- </div><br />
207
- <h2 style="padding-left:8px;">Starting optimization...</h2>
 
 
 
 
 
 
 
 
 
208
  <?php
 
 
 
 
 
 
 
 
 
 
209
  $sql = "
210
  SELECT `post_parent`, `post_title`, COUNT(*) cnt
211
  FROM $wpdb->posts
@@ -461,8 +480,55 @@ function rvg_optimize_db()
461
  } // while($row = mysql_fetch_row($names))
462
  ?>
463
  </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  <br />
465
  <span style="font-weight:bold;color:#00F;padding-left:8px;">D O N E !</span>
466
  <?php
467
  }
468
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+ $version = '1.3';
3
+ $release_date = '10/06/2012';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
+ * @version 1.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 Deleting Revisions - <a href="options-general.php?page=rvg_odb_admin"><strong>plug in options</strong></a>
12
  Author: Rolf van Gelder, Eindhoven, The Netherlands
13
+ Version: 1.3
14
  Author URI: http://cagewebdev.com
15
  */
16
  ?>
69
  update_option('rvg_wp_only', $rvg_wp_only);
70
 
71
  // UPDATED MESSAGE
72
+ echo "<div class='updated'><p><strong>Optimize Database after Deleting Revisions options updated</strong> - Click <a href='tools.php?page=rvg-optimize-db.php&action=run' style='font-weight:bold'>HERE</a> to run the optimization</p></div>";
73
  }
74
  $rvg_odb_number = get_option('rvg_odb_number');
75
  if(!$rvg_odb_number) $rvg_odb_number = '0';
97
  <p>You also can choose if you want to <u>delete</u> all <u>trashed items</u> and/or <u>spammed items</u> during the optimization.</p>
98
  <p>To start the optimization:<br />
99
  In the WordPress Dashboard go to &lsquo;<strong>Tools</strong>&lsquo;.<br />
100
+ Click on &lsquo;<strong>Optimize Database</strong>&lsquo;, then click on the '<strong>Start Optimization</strong>'-button. Et voila! </p>
101
  <p>Plugin version:<br />
102
  <strong>v<?php echo $version ?> (<?php echo $release_date?>)</strong> </p>
103
  <p>Author:<br />
144
  </fieldset>
145
  </blockquote>
146
  <p class="submit">
147
+ <input type='submit' name='info_update' value='Save Options' style="font-weight:bold;" />
148
  </p>
149
  </div>
150
  </form>
194
  $wp_only_yn = ($wp_only == 'N') ? 'NO' : 'YES';
195
  ?>
196
  <div style="padding-left:8px;">
197
+ <h2>Optimize your WordPress Database</h2>
198
  <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 $version?></a> - A WordPress Plugin by <a href="http://cagewebdev.com/" target="_blank" style="font-weight:bold;">Rolf van Gelder</a>, Eindhoven, The Netherlands</span></p>
199
+ <p>Current options:<br />
200
  <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 />
201
  <strong>Delete trashed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_trash_yn?></span><br />
202
  <strong>Delete spammed items:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_spam_yn?></span><br />
203
+ <strong>Only optimize WordPress tables:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $wp_only_yn?></span>
204
+ <?php
205
+ if($_REQUEST['action'] != 'run')
206
+ {
207
+ ?>
208
+ <p class="submit">
209
+ <input type='button' name='change_options' value='Change Options' onclick="self.location='options-general.php?page=rvg_odb_admin'" style="font-weight:normal;" />
210
+ &nbsp;
211
+ <input type='button' name='start_optimization' value='Start Optimization' onclick="self.location='tools.php?page=rvg-optimize-db.php&action=run'" style="font-weight:bold;" />
212
+ </p>
213
+ <?php
214
+ }
215
+ ?>
216
+ </div>
217
  <?php
218
+ if($_REQUEST['action'] != 'run')
219
+ { return;
220
+ }
221
+ ?>
222
+ <br />
223
+ <h2 style="padding-left:8px;">Starting Optimization...</h2>
224
+ <?php
225
+ // GET THE SIZE OF THE DATABASE BEFORE OPTIMIZATION
226
+ $start_size = rvg_get_db_size();
227
+
228
  $sql = "
229
  SELECT `post_parent`, `post_title`, COUNT(*) cnt
230
  FROM $wpdb->posts
480
  } // while($row = mysql_fetch_row($names))
481
  ?>
482
  </table>
483
+ <?php
484
+ $end_size = rvg_get_db_size();
485
+ ?>
486
+ <span style="font-weight:bold;color:#000;padding-left:8px;">~~~~~</span>
487
+ <table border="0" cellspacing="8" cellpadding="2">
488
+ <tr>
489
+ <td colspan="2" style="font-weight:bold;color:#00F;">SAVINGS:</td>
490
+ </tr>
491
+ <tr>
492
+ <th style="border-bottom:solid 1px #999;">size of the database</th>
493
+ <th style="border-bottom:solid 1px #999;" align="left">bytes</th>
494
+ </tr>
495
+ <tr>
496
+ <td>BEFORE optimization</td>
497
+ <td style="font-weight:bold;"><?php echo $start_size; ?></td>
498
+ </tr>
499
+ <tr>
500
+ <td>AFTER optimization</td>
501
+ <td style="font-weight:bold;"><?php echo $end_size; ?></td>
502
+ </tr>
503
+ <tr>
504
+ <td>TOTAL BYTES SAVED</td>
505
+ <td style="font-weight:bold;"><?php echo ($start_size - $end_size); ?></td>
506
+ </tr>
507
+ </table>
508
  <br />
509
  <span style="font-weight:bold;color:#00F;padding-left:8px;">D O N E !</span>
510
  <?php
511
  }
512
  ?>
513
+ <?php
514
+ /********************************************************************************************
515
+
516
+ CALCULATE THE SIZE OF THE WORDPRESS DATABASE (IN BYTES)
517
+
518
+ *********************************************************************************************/
519
+ function rvg_get_db_size()
520
+ {
521
+ global $wpdb;
522
+
523
+ $sql = "
524
+ SELECT SUM(data_length + index_length) AS size
525
+ FROM information_schema.TABLES
526
+ WHERE table_schema = '".strtolower(DB_NAME)."'
527
+ ";
528
+
529
+ $res = $wpdb -> get_results($sql);
530
+
531
+ return $res[0]->size;
532
+
533
+ } // rvg_get_db_size()
534
+ ?>