Optimize Database after Deleting Revisions - Version 3.4.2

Version Description

[05/10/2015] = * BUG FIX: fixed a bug (options didn't get saved in old multisite installs) Many thanks to Pat who helped me fixing the issue!

Download this release

Release Info

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

Code changes from version 3.4.1 to 3.4.2

Files changed (2) hide show
  1. readme.txt +7 -4
  2. rvg-optimize-db.php +80 -62
readme.txt CHANGED
@@ -1,15 +1,15 @@
1
  === Optimize Database after Deleting Revisions ===
2
  Contributors: CAGE Web Design | Rolf van Gelder
3
- Donate link: http://cagewebdev.com/index.php/donations/
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, transients, unused tags, pingback, trackback
7
  Author URI: http://cagewebdev.com
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
  Requires at least: 2.8
10
- Tested up to: 4.2.1
11
- Stable tag: 3.4.1
12
- Version: 3.4.1
13
  License: GPLv2 or later
14
 
15
  == Description ==
@@ -82,6 +82,9 @@ http://cagewebdev.com/index.php/wordpress-plugins/
82
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
83
 
84
  == Changelog ==
 
 
 
85
  = 3.4.1 [04/26/2015] =
86
  * BUG FIX: fixed a bug for the excluded tables (didn't work anymore)
87
 
1
  === Optimize Database after Deleting Revisions ===
2
  Contributors: CAGE Web Design | Rolf van Gelder
3
+ Donate link: http://cagewebdev.com/index.php/donations-odb/
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, transients, unused tags, pingback, trackback
7
  Author URI: http://cagewebdev.com
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
  Requires at least: 2.8
10
+ Tested up to: 4.2.2
11
+ Stable tag: 3.4.2
12
+ Version: 3.4.2
13
  License: GPLv2 or later
14
 
15
  == Description ==
82
  * If you run the plugin from any of the sites, it will cleanup ALL the sites in the network!
83
 
84
  == Changelog ==
85
+ = 3.4.2 [05/10/2015] =
86
+ * BUG FIX: fixed a bug (options didn't get saved in old multisite installs) Many thanks to Pat who helped me fixing the issue!
87
+
88
  = 3.4.1 [04/26/2015] =
89
  * BUG FIX: fixed a bug for the excluded tables (didn't work anymore)
90
 
rvg-optimize-db.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
- * @version 3.4.1
5
  */
6
  /*
7
  Plugin Name: Optimize Database after Deleting Revisions
@@ -9,11 +9,11 @@ Plugin URI: http://cagewebdev.com/index.php/optimize-database-after-deleting-rev
9
  Description: Optimizes the Wordpress Database after Cleaning it out
10
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
11
  Author URI: http://cagewebdev.com
12
- Version: 3.4.1
13
  */
14
 
15
- $odb_version = '3.4.1';
16
- $odb_release_date = '04/26/2015';
17
 
18
  // v3.3 - MULTISITE
19
  $odb_ms_prefixes = array();
@@ -202,6 +202,31 @@ function rvg_activate_plugin()
202
  }
203
  } // rvg_activate_plugin()
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
  /********************************************************************************************
207
  *
@@ -232,20 +257,20 @@ function rvg_odb_network_info()
232
  *
233
  * GET AN OPTION FROM THE ROOT SITE OPTION TABLE
234
  *
 
 
235
  ********************************************************************************************/
236
- function rvg_odb_get_option($option)
237
  {
238
- global $wpdb;
239
-
240
- $sql = "
241
- SELECT `option_value`
242
- FROM ".$wpdb->base_prefix."options
243
- WHERE `option_name` = '".$option."'
244
- ";
245
- $res = $wpdb->get_results($sql);
246
-
247
- if(isset($res[0]->option_value)) return $res[0]->option_value;
248
- return '';
249
  } // rvg_odb_get_option()
250
 
251
 
@@ -253,41 +278,43 @@ function rvg_odb_get_option($option)
253
  *
254
  * SAVE AN OPTION TO THE ROOT SITE OPTION TABLE
255
  *
 
 
256
  ********************************************************************************************/
257
  function rvg_odb_update_option($option, $value)
258
  {
259
- global $wpdb;
260
-
261
- $sql = "
262
- SELECT COUNT(*) cnt
263
- FROM ".$wpdb->base_prefix."options
264
- WHERE `option_name` = '".$option."'
265
- ";
266
- $res = $wpdb->get_results($sql);
267
-
268
- if(isset($res[0]->cnt) && $res[0]->cnt > 0)
269
- { $sql = "
270
- UPDATE ".$wpdb->base_prefix."options
271
- SET `option_value` = '".$value."'
272
- WHERE `option_name` = '".$option."'
273
- ";
274
- }
275
- else
276
- { $sql = "
277
- INSERT INTO ".$wpdb->base_prefix."options
278
- (option_name, option_value)
279
- VALUES
280
- ( '".$option."',
281
- '".$value."'
282
- )
283
- ";
284
  }
285
- $wpdb->get_results($sql);
286
-
287
- return;
288
  } // rvg_odb_update_option()
289
 
290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  /********************************************************************************************
292
  *
293
  * CREATE THE SETTINGS PAGE
@@ -296,13 +323,13 @@ function rvg_odb_update_option($option, $value)
296
  function rvg_odb_settings_page()
297
  {
298
  global $odb_version, $odb_release_date, $wpdb, $table_prefix, $odb_ms_prefixes;
 
 
299
 
300
  // v3.3 - GET NETWORK INFORMATION (MULTISITE)
301
  rvg_odb_network_info();
302
 
303
  // v3.3 - GET THE OPTIONS FROM THE TABLES OF THE MAIN SITE (IN CASE OF MULTISITE)
304
- // if(function_exists('switch_to_blog')) switch_to_blog(1);
305
-
306
  $current_datetime = Date('YmdHis');
307
  $current_date = substr($current_datetime, 0, 8);
308
  $current_hour = substr($current_datetime, 8, 2);
@@ -315,15 +342,12 @@ function rvg_odb_settings_page()
315
  {
316
  // v2.8.3
317
  check_admin_referer('odb_action', 'odb_nonce');
 
 
 
 
318
 
319
- # DELETE ALL EXCLUDED TABLES (FROM THE ROOT OPTIONS TABLE)
320
- $sql = "
321
- DELETE FROM ".$wpdb->base_prefix."options
322
- WHERE `option_name` LIKE 'rvg_ex_%'
323
- ";
324
- $wpdb->get_results($sql);
325
-
326
- # ADD EXCLUDED TABLES
327
  foreach ($_POST as $key => $value)
328
  { if(substr($key,0,3) == 'cb_')
329
  rvg_odb_update_option('rvg_ex_'.substr($key,3).'', 'excluded');
@@ -638,7 +662,6 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
638
  </a> | <a href="javascript:;" onclick="jQuery(':not([id^=cb_<?php echo $odb_ms_prefixes[0]; ?>])').filter('[id^=cb_]').attr('checked',true);">
639
  <?php _e('check all NON-WordPress tables','rvg-optimize-database');?>
640
  </a></span>
641
- <?php $tables = $wpdb->get_results("SHOW TABLES FROM `".DB_NAME."`", ARRAY_N);?>
642
  <div id="odb-options-tables-container">
643
  <div id="odb-options-tables-wrapper">
644
  <?php
@@ -648,7 +671,7 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
648
  for($j=0; $j<count($odb_ms_prefixes); $j++)
649
  if(substr($tables[$i][0], 0, strlen($odb_ms_prefixes[$j])) == $odb_ms_prefixes[$j]) $class = ' odb-wp-table';
650
  $cb_checked = '';
651
- $excluded = rvg_odb_get_option('rvg_ex_'.$tables[$i][0].'');
652
  if($excluded == 'excluded') $cb_checked = ' checked';
653
  ?>
654
  <div class="odb-options-table<?php echo $class;?>" title="<?php echo $tables[$i][0];?>">
@@ -1627,8 +1650,6 @@ function rvg_delete_tags()
1627
  // LOOP THROUGH THE NETWORK
1628
  for($i=0; $i<count($odb_ms_blogids); $i++)
1629
  {
1630
- if(function_exists('switch_to_blog')) switch_to_blog($odb_ms_blogids[$i]);
1631
-
1632
  $tags = get_terms('post_tag', array('hide_empty' => 0));
1633
  for($j=0; $j<count($tags); $j++)
1634
  {
@@ -1642,9 +1663,6 @@ function rvg_delete_tags()
1642
  }
1643
  } // for($i=0; $i<count($odb_ms_blogids); $i++)
1644
 
1645
- // SWITCH BACK TO MAIN SITE
1646
- // if(function_exists('switch_to_blog')) switch_to_blog(1);
1647
-
1648
  return $total_deleted;
1649
  } // rvg_delete_tags()
1650
 
@@ -1887,7 +1905,7 @@ function rvg_optimize_tables($display)
1887
  for ($i=0; $i<count($tables); $i++)
1888
  {
1889
  $excluded = rvg_odb_get_option('rvg_ex_'.$tables[$i][0]);
1890
-
1891
  if(!$excluded)
1892
  { # TABLE NOT EXCLUDED
1893
  $cnt++;
1
  <?php
2
  /**
3
  * @package Optimize Database after Deleting Revisions
4
+ * @version 3.4.2
5
  */
6
  /*
7
  Plugin Name: Optimize Database after Deleting Revisions
9
  Description: Optimizes the Wordpress Database after Cleaning it out
10
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
11
  Author URI: http://cagewebdev.com
12
+ Version: 3.4.2
13
  */
14
 
15
+ $odb_version = '3.4.2';
16
+ $odb_release_date = '05/10/2015';
17
 
18
  // v3.3 - MULTISITE
19
  $odb_ms_prefixes = array();
202
  }
203
  } // rvg_activate_plugin()
204
 
205
+ register_uninstall_hook( __FILE__, 'rvg_odb_uninstall');
206
+ function rvg_odb_uninstall()
207
+ {
208
+ global $wpdb, $odb_ms_prefixes;
209
+
210
+ $tables = $wpdb->get_results("SHOW TABLES FROM `".DB_NAME."`", ARRAY_N);
211
+
212
+ // DELETE ALL POSSIBLY EXCLUDED TABLES
213
+ for ($i=0; $i<count($tables); $i++) rvg_odb_delete_option('rvg_ex_'.$tables[$i][0].'');
214
+
215
+ // DELETE THE OTHER OPTIONS
216
+ rvg_odb_delete_option('rvg_clear_pingbacks');
217
+ rvg_odb_delete_option('rvg_clear_spam');
218
+ rvg_odb_delete_option('rvg_clear_tags');
219
+ rvg_odb_delete_option('rvg_clear_transients');
220
+ rvg_odb_delete_option('rvg_clear_trash');
221
+ rvg_odb_delete_option('rvg_odb_adminbar');
222
+ rvg_odb_delete_option('rvg_odb_adminmenu');
223
+ rvg_odb_delete_option('rvg_odb_logging_on');
224
+ rvg_odb_delete_option('rvg_odb_number');
225
+ rvg_odb_delete_option('rvg_odb_schedule');
226
+ rvg_odb_delete_option('rvg_odb_schedulehour');
227
+ rvg_odb_delete_option('rvg_odb_total_savings');
228
+ } // rvg_odb_uninstall()
229
+
230
 
231
  /********************************************************************************************
232
  *
257
  *
258
  * GET AN OPTION FROM THE ROOT SITE OPTION TABLE
259
  *
260
+ * Revision: v3.4.2
261
+ *
262
  ********************************************************************************************/
263
+ function rvg_odb_get_option($option, $default = false)
264
  {
265
+ if(is_multisite() &&
266
+ function_exists('is_plugin_active_for_network') &&
267
+ is_plugin_active_for_network('rvg-optimize-db/rvg-optimize-db.php'))
268
+ {
269
+ return get_site_option($option, $default);
270
+ } else
271
+ {
272
+ return get_option($option, $default);
273
+ }
 
 
274
  } // rvg_odb_get_option()
275
 
276
 
278
  *
279
  * SAVE AN OPTION TO THE ROOT SITE OPTION TABLE
280
  *
281
+ * Revision: v3.4.2
282
+ *
283
  ********************************************************************************************/
284
  function rvg_odb_update_option($option, $value)
285
  {
286
+ if(is_multisite() &&
287
+ function_exists('is_plugin_active_for_network') &&
288
+ is_plugin_active_for_network('rvg-optimize-db/rvg-optimize-db.php'))
289
+ {
290
+ return update_site_option( $option, $value);
291
+ } else
292
+ {
293
+ return update_option( $option, $value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  }
 
 
 
295
  } // rvg_odb_update_option()
296
 
297
 
298
+ /********************************************************************************************
299
+ *
300
+ * DELETE AN OPTION TO THE ROOT SITE OPTION TABLE
301
+ *
302
+ * Since: v3.4.2
303
+ *
304
+ ********************************************************************************************/
305
+ function rvg_odb_delete_option($option)
306
+ {
307
+ if(is_multisite() && function_exists('is_plugin_active_for_network') &&
308
+ is_plugin_active_for_network('rvg-optimize-db/rvg-optimize-db.php'))
309
+ {
310
+ return delete_site_option($option);
311
+ } else
312
+ {
313
+ return delete_option($option);
314
+ }
315
+ } // rvg_odb_delete_option()
316
+
317
+
318
  /********************************************************************************************
319
  *
320
  * CREATE THE SETTINGS PAGE
323
  function rvg_odb_settings_page()
324
  {
325
  global $odb_version, $odb_release_date, $wpdb, $table_prefix, $odb_ms_prefixes;
326
+
327
+ $tables = $wpdb->get_results("SHOW TABLES FROM `".DB_NAME."`", ARRAY_N);
328
 
329
  // v3.3 - GET NETWORK INFORMATION (MULTISITE)
330
  rvg_odb_network_info();
331
 
332
  // v3.3 - GET THE OPTIONS FROM THE TABLES OF THE MAIN SITE (IN CASE OF MULTISITE)
 
 
333
  $current_datetime = Date('YmdHis');
334
  $current_date = substr($current_datetime, 0, 8);
335
  $current_hour = substr($current_datetime, 8, 2);
342
  {
343
  // v2.8.3
344
  check_admin_referer('odb_action', 'odb_nonce');
345
+
346
+ // DELETE ALL EXCLUDED TABLES
347
+ for ($i=0; $i<count($tables); $i++)
348
+ rvg_odb_delete_option('rvg_ex_'.$tables[$i][0].'');
349
 
350
+ // ADD EXCLUDED TABLES
 
 
 
 
 
 
 
351
  foreach ($_POST as $key => $value)
352
  { if(substr($key,0,3) == 'cb_')
353
  rvg_odb_update_option('rvg_ex_'.substr($key,3).'', 'excluded');
662
  </a> | <a href="javascript:;" onclick="jQuery(':not([id^=cb_<?php echo $odb_ms_prefixes[0]; ?>])').filter('[id^=cb_]').attr('checked',true);">
663
  <?php _e('check all NON-WordPress tables','rvg-optimize-database');?>
664
  </a></span>
 
665
  <div id="odb-options-tables-container">
666
  <div id="odb-options-tables-wrapper">
667
  <?php
671
  for($j=0; $j<count($odb_ms_prefixes); $j++)
672
  if(substr($tables[$i][0], 0, strlen($odb_ms_prefixes[$j])) == $odb_ms_prefixes[$j]) $class = ' odb-wp-table';
673
  $cb_checked = '';
674
+ $excluded = rvg_odb_get_option('rvg_ex_'.$tables[$i][0].'');
675
  if($excluded == 'excluded') $cb_checked = ' checked';
676
  ?>
677
  <div class="odb-options-table<?php echo $class;?>" title="<?php echo $tables[$i][0];?>">
1650
  // LOOP THROUGH THE NETWORK
1651
  for($i=0; $i<count($odb_ms_blogids); $i++)
1652
  {
 
 
1653
  $tags = get_terms('post_tag', array('hide_empty' => 0));
1654
  for($j=0; $j<count($tags); $j++)
1655
  {
1663
  }
1664
  } // for($i=0; $i<count($odb_ms_blogids); $i++)
1665
 
 
 
 
1666
  return $total_deleted;
1667
  } // rvg_delete_tags()
1668
 
1905
  for ($i=0; $i<count($tables); $i++)
1906
  {
1907
  $excluded = rvg_odb_get_option('rvg_ex_'.$tables[$i][0]);
1908
+
1909
  if(!$excluded)
1910
  { # TABLE NOT EXCLUDED
1911
  $cnt++;