Optimize Database after Deleting Revisions - Version 1.0

Version Description

No Upgrade Notice available.

Download this release

Release Info

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

Version 1.0

Files changed (2) hide show
  1. readme.txt +38 -0
  2. rvg-optimize-db.php +102 -0
readme.txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+
3
+ Contributors: Rolf van Gelder
4
+ Donate link: http://cagewebdev.com
5
+ Plugin Name: Optimize Database after Deleting Revisions
6
+ Plugin URI: http://cagewebdev.com/wp-plugins
7
+ Tags: wp, database, delete, revisions, optimize, php
8
+ Author URI: http://cagewebdev.com
9
+ Author: Rolf van Gelder
10
+ Requires at least: 2.0
11
+ Tested up to: 3.2.1
12
+ Stable tag: 1.0
13
+ Version: 1.0
14
+
15
+ == Description ==
16
+
17
+ This plugin is a 'one click' database optimizer. It deletes the redundant revisions of posts and pages and then optimizes all Wordpress database tables.
18
+
19
+ == Installation ==
20
+
21
+ 1. Upload `rvg-optimize-db.php` to the `/wp-content/plugins/` directory
22
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
23
+
24
+ == Upgrade Notice ==
25
+
26
+ No Upgrade Notice available.
27
+
28
+ == Screenshots ==
29
+
30
+ No Screenshots available.
31
+
32
+ == Changelog ==
33
+
34
+ 1.0 11/22/2011 Initial release
35
+
36
+ == Frequently Asked Questions ==
37
+
38
+ No FAQ available yet.
rvg-optimize-db.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Optimize Database after Deleting Revisions
4
+ * @version 1.0
5
+ */
6
+ /*
7
+ Plugin Name: Optimize Database after Deleting Revisions
8
+ Plugin URI: http://cagewebdev.com
9
+ Description: Optimizes the Wordpress Database after Deleting Revisions - release: 08-10-2011
10
+ Author: Rolf van Gelder
11
+ Version: 1.0
12
+ Author URI: http://cagewebdev.com
13
+ */
14
+ ?>
15
+ <?php
16
+ function optimize_db_main()
17
+ { if (function_exists('add_options_page')) {
18
+ add_options_page('Optimize Database', 'Optimize Database',8, 'rvg-optimize-db.php', 'rvg_optimize_db');
19
+ }
20
+ }
21
+ add_action('admin_menu', 'optimize_db_main');
22
+
23
+ function rvg_optimize_db()
24
+ {
25
+ global $wpdb;
26
+
27
+ echo '<h2 style="padding-left:5px;">Optimizing your WordPress database</h2>';
28
+ echo '<span style="padding-left:5px;font-style:italic;">rvg-optimize-db v1.0 - A WordPress Plugin by Rolf van Gelder</span><br /><br />';
29
+
30
+ /***********************************
31
+ DELETE REVISIONS
32
+ ***********************************/
33
+ $sql = "SELECT `ID`,`post_date`,`post_title`,`post_modified`
34
+ FROM $wpdb->posts
35
+ WHERE `post_type` = 'revision'
36
+ ORDER BY `ID` DESC";
37
+ $results = $wpdb -> get_results($sql);
38
+ if($results)
39
+ { $cnt = count($results);
40
+ # print_r($results);
41
+ ?>
42
+ <table border="0" cellspacing="5" cellpadding="5">
43
+ <tr>
44
+ <td colspan="3" style="font-weight:bold;color:#00F;">DELETING REVISIONS:</td>
45
+ </tr>
46
+ <?php
47
+ for($i=0;$i<$cnt;$i++)
48
+ { # MULTI LINGUAL?
49
+ $post_title = str_replace('--><!--','--> | <!--',$results[$i]->post_title);
50
+ ?>
51
+ <tr valign="top">
52
+ <td align="right" style="font-weight:bold;"><?=($i+1)?></td>
53
+ <td><?=$results[$i]->post_modified?></td>
54
+ <td style="font-weight:bold;"><?=$post_title?></td>
55
+ </tr>
56
+ <?php
57
+ }
58
+ ?>
59
+ </table>
60
+ <br />
61
+ <?php
62
+ # DELETE THE REVISIONS
63
+ $sql = "DELETE FROM $wpdb->posts WHERE post_type = 'revision'";
64
+ $results = $wpdb -> get_results($sql);
65
+ }
66
+ else
67
+ { echo '<span style="font-weight:bold;color:#00F;padding-left:5px;">NO REVISIONS FOUND!</span><br /><br />';
68
+ } // if($results)
69
+
70
+ /***********************************
71
+ OPTIMIZE TABLES
72
+ ***********************************/
73
+ # GET TABLE NAMES
74
+ $Tables = $wpdb -> get_results('SHOW TABLES IN '.DB_NAME);
75
+ $Tables_in_DB_NAME = 'Tables_in_'.DB_NAME;
76
+ # print_r($Tables);
77
+ ?>
78
+ <table border="0" cellspacing="5" cellpadding="5">
79
+ <tr>
80
+ <td colspan="3" style="font-weight:bold;color:#00F;">OPTIMIZING DATABASE TABLES:</td>
81
+ </tr>
82
+ <?php
83
+ for ($i=0; $i<count($Tables); $i++)
84
+ {
85
+ $query = "OPTIMIZE TABLE ".$Tables[$i]->$Tables_in_DB_NAME;
86
+ $result = $wpdb -> get_results($query);
87
+ # print_r($result);
88
+ ?>
89
+ <tr>
90
+ <td style="font-weight:bold;"><?=$Tables[$i]->$Tables_in_DB_NAME?></td>
91
+ <td style="font-weight:bold;">=&gt;</td>
92
+ <td><?=$result[0]->Msg_text?></td>
93
+ </tr>
94
+ <?php
95
+ }
96
+ $query = "$operation TABLE ";
97
+ ?>
98
+ </table><br />
99
+ <span style="font-weight:bold;color:#00F;padding-left:5px;">DONE!</span>
100
+ <?php
101
+ }
102
+ ?>