Optimize Database after Deleting Revisions - Version 2.7.8

Version Description

[05/01/2014] = * CHANGE: replaced depreciated MySQL queries (from WP 3.9 / PHP 5.5)

Download this release

Release Info

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

Code changes from version 2.7.7 to 2.7.8

Files changed (2) hide show
  1. readme.txt +6 -3
  2. rvg-optimize-db.php +49 -22
readme.txt CHANGED
@@ -7,9 +7,9 @@ Tags: database, delete, revisions, optimize, post, posts, page, pages, clean, cl
7
  Author URI: http://cagewebdev.com
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
  Requires at least: 2.0
10
- Tested up to: 3.8.1
11
- Stable tag: 2.7.7
12
- Version: 2.7.7
13
 
14
  == Description ==
15
 
@@ -54,6 +54,9 @@ No warranty, use at own risk!
54
 
55
  == Changelog ==
56
 
 
 
 
57
  = 2.7.7 [02/16/2014] =
58
  * BUG FIX: made jQuery also https compatible
59
 
7
  Author URI: http://cagewebdev.com
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
  Requires at least: 2.0
10
+ Tested up to: 3.9
11
+ Stable tag: 2.7.8
12
+ Version: 2.7.8
13
 
14
  == Description ==
15
 
54
 
55
  == Changelog ==
56
 
57
+ = 2.7.8 [05/01/2014] =
58
+ * CHANGE: replaced depreciated MySQL queries (from WP 3.9 / PHP 5.5)
59
+
60
  = 2.7.7 [02/16/2014] =
61
  * BUG FIX: made jQuery also https compatible
62
 
rvg-optimize-db.php CHANGED
@@ -1,16 +1,16 @@
1
  <?php
2
- $odb_version = '2.7.7';
3
- $odb_release_date = '02/16/2014';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
- * @version 2.7.7
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.7.7
14
  Author URI: http://cagewebdev.com
15
  */
16
 
@@ -26,6 +26,7 @@ function optimize_db_main()
26
  }
27
  add_action('admin_menu', 'optimize_db_main');
28
 
 
29
  /********************************************************************************************
30
 
31
  ADD THE 'OPTIMIZE DB OPTIONS' ITEM TO THE SETTINGS MENU
@@ -39,6 +40,7 @@ function rvg_odb_admin_menu()
39
  }
40
  add_action( 'admin_menu', 'rvg_odb_admin_menu' );
41
 
 
42
  /********************************************************************************************
43
 
44
  ADD THE '1 CLICK OPTIMIZE DATABASE' ITEM TO THE ADMIN BAR (IF ACTIVATED)
@@ -53,6 +55,7 @@ function rvg_odb_admin_bar()
53
  $rvg_odb_adminbar = get_option('rvg_odb_adminbar');
54
  if($rvg_odb_adminbar == "Y") add_action( 'wp_before_admin_bar_render', 'rvg_odb_admin_bar' );
55
 
 
56
  /********************************************************************************************
57
 
58
  ACTIONS FOR THE SCHEDULER
@@ -90,6 +93,7 @@ function rvg_activate_plugin()
90
  }
91
  } # rvg_activate_plugin ()
92
 
 
93
  /********************************************************************************************
94
 
95
  CREATE THE OPTIONS PAGE
@@ -346,7 +350,9 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
346
  </table></td>
347
  </tr>
348
  <?php
349
- $names = mysql_query("SHOW TABLES FROM `".DB_NAME."`");
 
 
350
  ?>
351
  <tr>
352
  <td colspan="4" valign="top"><table id="table_list" width="100%" border="0" cellspacing="0" cellpadding="4" style="display:block;">
@@ -358,7 +364,8 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
358
  <?php
359
  $c = 0;
360
  $t = 0;
361
- while($row = mysql_fetch_row($names))
 
362
  { $t++;
363
  $c++;
364
  if($c>4)
@@ -368,19 +375,19 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
368
  }
369
  $style = 'normal';
370
  // WORDPRESS TABLE?
371
- if(substr($row[0],0,strlen($table_prefix)) == $table_prefix) $style = 'bold;color:#00F;';
372
 
373
  $cb_checked = '';
374
  $sql = "
375
  SELECT `option_value`
376
  FROM $wpdb->options
377
- WHERE `option_name` = 'rvg_ex_".$row[0]."'
378
  ";
379
  $results = $wpdb -> get_results($sql);
380
  if(isset($results[0]->option_value))
381
  if($results[0]->option_value == 'excluded') $cb_checked = ' checked';
382
- 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";
383
- } # while($row = mysql_fetch_row($names))
384
  ?>
385
  </tr>
386
  </table></td>
@@ -398,6 +405,7 @@ if($rvg_odb_logging_on == 'Y') $rvg_odb_logging_on_checked = ' checked="checke
398
  <?php
399
  } // rvg_odb_options_page ()
400
 
 
401
  /********************************************************************************************
402
 
403
  MAIN FUNCTION
@@ -903,6 +911,7 @@ function rvg_optimize_db()
903
  }
904
  } // rvg_optimize_db ()
905
 
 
906
  /********************************************************************************************
907
 
908
  EXECUTE OPTIMIZATION VIA CRON JOB
@@ -1032,6 +1041,7 @@ function rvg_optimize_db_cron()
1032
 
1033
  } // rvg_optimize_db_cron ()
1034
 
 
1035
  /********************************************************************************************
1036
 
1037
  DELETE THE REVISIONS
@@ -1089,6 +1099,7 @@ function rvg_delete_revisions($results, $display, $max_revisions)
1089
  return $total_deleted;
1090
  } // rvg_delete_revisions ()
1091
 
 
1092
  /********************************************************************************************
1093
 
1094
  DELETE TRASHED POSTS AND PAGES
@@ -1139,6 +1150,7 @@ function rvg_delete_trash($results, $display)
1139
 
1140
  } // rvg_delete_trash ()
1141
 
 
1142
  /********************************************************************************************
1143
 
1144
  DELETE SPAMMED ITEMS
@@ -1178,6 +1190,7 @@ function rvg_delete_spam($results, $display)
1178
 
1179
  } // rvg_delete_spam ()
1180
 
 
1181
  /********************************************************************************************
1182
 
1183
  DELETE UNUSED TAGS
@@ -1198,6 +1211,7 @@ function rvg_delete_tags()
1198
  return $total_deleted;
1199
  } // rvg_delete_tags ()
1200
 
 
1201
  /********************************************************************************************
1202
 
1203
  DELETE EXPIRED TRANSIENTS
@@ -1264,6 +1278,7 @@ function rvg_delete_transients()
1264
  return $total_deleted;
1265
  } // rvg_delete_transients ()
1266
 
 
1267
  /********************************************************************************************
1268
 
1269
  DELETE ORPHAN POSTMETA RECORDS
@@ -1321,6 +1336,7 @@ function rvg_delete_orphans($display)
1321
 
1322
  } // rvg_delete_orphans ()
1323
 
 
1324
  /********************************************************************************************
1325
 
1326
  OPTIMIZE DATABASE TABLES
@@ -1333,16 +1349,18 @@ function rvg_optimize_tables($display)
1333
  # WP_ONLY IS DEPRECIATED FROM v2.2
1334
  rvg_fix_wp_only();
1335
 
1336
- $names = mysql_query("SHOW TABLES FROM `".DB_NAME."`");
1337
- $cnt = 0;
1338
- while($row = mysql_fetch_row($names))
 
 
1339
  {
1340
- $excluded = get_option('rvg_ex_'.$row[0]);
1341
 
1342
  if(!$excluded)
1343
  { # TABLE NOT EXCLUDED
1344
  $cnt++;
1345
- $query = "OPTIMIZE TABLE ".$row[0];
1346
  $result = $wpdb -> get_results($query);
1347
 
1348
  // v2.7.5
@@ -1352,7 +1370,7 @@ function rvg_optimize_tables($display)
1352
  ) AS size, table_rows
1353
  FROM information_schema.TABLES
1354
  WHERE table_schema = '".strtolower(DB_NAME)."'
1355
- AND table_name = '".$row[0]."'
1356
  ";
1357
 
1358
  $table_info = $wpdb -> get_results($sql);
@@ -1362,7 +1380,7 @@ function rvg_optimize_tables($display)
1362
  ?>
1363
  <tr>
1364
  <td align="right" valign="top"><?php echo $cnt?>.</td>
1365
- <td valign="top" style="font-weight:bold;"><?php echo $row[0] ?></td>
1366
  <td valign="top"><?php echo $result[0]->Msg_text ?></td>
1367
  <td valign="top"><?php echo $table_info[0]->engine ?></td>
1368
  <td align="right" valign="top"><?php echo $table_info[0]->table_rows ?></td>
@@ -1371,11 +1389,12 @@ function rvg_optimize_tables($display)
1371
  <?php
1372
  } // if($display)
1373
  } // if($wp_only == 'N' || ($wp_only == 'Y' && substr($row[0],0,strlen($table_prefix)) == $table_prefix))
1374
- } // while($row = mysql_fetch_row($names))
1375
  return $cnt;
1376
 
1377
  } // rvg_optimize_tables ()
1378
 
 
1379
  /********************************************************************************************
1380
 
1381
  FIX WP_ONLY (DEPRECIATED FROM v2.2)
@@ -1388,9 +1407,11 @@ function rvg_fix_wp_only()
1388
  $wp_only = get_option('rvg_wp_only');
1389
  if($wp_only == 'Y')
1390
  {
1391
- $names = mysql_query("SHOW TABLES FROM `".DB_NAME."`");
1392
- while($row = mysql_fetch_row($names))
1393
- { if(substr($row[0],0,strlen($table_prefix)) != $table_prefix)
 
 
1394
  { // NOT A WORDPRESS TABLE: EXLUDE IT
1395
  $sql = "
1396
  INSERT INTO $wpdb->options (option_name, option_value, autoload)
@@ -1408,6 +1429,7 @@ function rvg_fix_wp_only()
1408
 
1409
  } # function rvg_fix_wp_only ()
1410
 
 
1411
  /********************************************************************************************
1412
 
1413
  WRITE LINE TO LOG FILE
@@ -1513,6 +1535,7 @@ td {
1513
 
1514
  } // rvg_write_log ()
1515
 
 
1516
  /********************************************************************************************
1517
 
1518
  GET REVISIONS
@@ -1535,6 +1558,7 @@ function rvg_get_revisions($max_revisions)
1535
 
1536
  } // rvg_get_revisions ()
1537
 
 
1538
  /********************************************************************************************
1539
 
1540
  GET TRASHED POSTS / PAGES AND COMMENTS
@@ -1559,6 +1583,7 @@ function rvg_get_trash()
1559
 
1560
  } // rvg_get_trash ()
1561
 
 
1562
  /********************************************************************************************
1563
 
1564
  GET SPAMMED COMMENTS
@@ -1579,6 +1604,7 @@ function rvg_get_spam()
1579
 
1580
  } // rvg_get_trash ()
1581
 
 
1582
  /********************************************************************************************
1583
 
1584
  CALCULATE THE SIZE OF THE WORDPRESS DATABASE (IN BYTES)
@@ -1602,6 +1628,7 @@ function rvg_get_db_size()
1602
 
1603
  } // rvg_get_db_size ()
1604
 
 
1605
  /********************************************************************************************
1606
 
1607
  FORMAT SIZES FROM BYTES TO KB OR MB
@@ -1616,4 +1643,4 @@ function rvg_format_size($size, $precision=1)
1616
 
1617
  return $table_size;
1618
  } // rvg_format_size ()
1619
- ?>
1
  <?php
2
+ $odb_version = '2.7.8';
3
+ $odb_release_date = '05/01/2014';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
+ * @version 2.7.8
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.7.8
14
  Author URI: http://cagewebdev.com
15
  */
16
 
26
  }
27
  add_action('admin_menu', 'optimize_db_main');
28
 
29
+
30
  /********************************************************************************************
31
 
32
  ADD THE 'OPTIMIZE DB OPTIONS' ITEM TO THE SETTINGS MENU
40
  }
41
  add_action( 'admin_menu', 'rvg_odb_admin_menu' );
42
 
43
+
44
  /********************************************************************************************
45
 
46
  ADD THE '1 CLICK OPTIMIZE DATABASE' ITEM TO THE ADMIN BAR (IF ACTIVATED)
55
  $rvg_odb_adminbar = get_option('rvg_odb_adminbar');
56
  if($rvg_odb_adminbar == "Y") add_action( 'wp_before_admin_bar_render', 'rvg_odb_admin_bar' );
57
 
58
+
59
  /********************************************************************************************
60
 
61
  ACTIONS FOR THE SCHEDULER
93
  }
94
  } # rvg_activate_plugin ()
95
 
96
+
97
  /********************************************************************************************
98
 
99
  CREATE THE OPTIONS PAGE
350
  </table></td>
351
  </tr>
352
  <?php
353
+ # v2.7.8
354
+ $names = $wpdb->get_results("SHOW TABLES FROM `".DB_NAME."`");
355
+ $dbname = 'Tables_in_'.DB_NAME;
356
  ?>
357
  <tr>
358
  <td colspan="4" valign="top"><table id="table_list" width="100%" border="0" cellspacing="0" cellpadding="4" style="display:block;">
364
  <?php
365
  $c = 0;
366
  $t = 0;
367
+ # v2.7.8
368
+ for ($i=0; $i<count($names); $i++)
369
  { $t++;
370
  $c++;
371
  if($c>4)
375
  }
376
  $style = 'normal';
377
  // WORDPRESS TABLE?
378
+ if(substr($names[$i]->$dbname,0,strlen($table_prefix)) == $table_prefix) $style = 'bold;color:#00F;';
379
 
380
  $cb_checked = '';
381
  $sql = "
382
  SELECT `option_value`
383
  FROM $wpdb->options
384
+ WHERE `option_name` = 'rvg_ex_".$names[$i]->$dbname."'
385
  ";
386
  $results = $wpdb -> get_results($sql);
387
  if(isset($results[0]->option_value))
388
  if($results[0]->option_value == 'excluded') $cb_checked = ' checked';
389
+ echo '<td width="25%" style="font-weight:'.$style.'"><input id="cb_'.$names[$i]->$dbname.'" name="cb_'.$names[$i]->$dbname.'" type="checkbox" value="1" '.$cb_checked.' /> '.$names[$i]->$dbname.'</td>'."\n";
390
+ } # for ($i=0; $i<count($names); $i++)
391
  ?>
392
  </tr>
393
  </table></td>
405
  <?php
406
  } // rvg_odb_options_page ()
407
 
408
+
409
  /********************************************************************************************
410
 
411
  MAIN FUNCTION
911
  }
912
  } // rvg_optimize_db ()
913
 
914
+
915
  /********************************************************************************************
916
 
917
  EXECUTE OPTIMIZATION VIA CRON JOB
1041
 
1042
  } // rvg_optimize_db_cron ()
1043
 
1044
+
1045
  /********************************************************************************************
1046
 
1047
  DELETE THE REVISIONS
1099
  return $total_deleted;
1100
  } // rvg_delete_revisions ()
1101
 
1102
+
1103
  /********************************************************************************************
1104
 
1105
  DELETE TRASHED POSTS AND PAGES
1150
 
1151
  } // rvg_delete_trash ()
1152
 
1153
+
1154
  /********************************************************************************************
1155
 
1156
  DELETE SPAMMED ITEMS
1190
 
1191
  } // rvg_delete_spam ()
1192
 
1193
+
1194
  /********************************************************************************************
1195
 
1196
  DELETE UNUSED TAGS
1211
  return $total_deleted;
1212
  } // rvg_delete_tags ()
1213
 
1214
+
1215
  /********************************************************************************************
1216
 
1217
  DELETE EXPIRED TRANSIENTS
1278
  return $total_deleted;
1279
  } // rvg_delete_transients ()
1280
 
1281
+
1282
  /********************************************************************************************
1283
 
1284
  DELETE ORPHAN POSTMETA RECORDS
1336
 
1337
  } // rvg_delete_orphans ()
1338
 
1339
+
1340
  /********************************************************************************************
1341
 
1342
  OPTIMIZE DATABASE TABLES
1349
  # WP_ONLY IS DEPRECIATED FROM v2.2
1350
  rvg_fix_wp_only();
1351
 
1352
+ # v2.7.8
1353
+ $names = $wpdb->get_results("SHOW TABLES FROM `".DB_NAME."`");
1354
+ $dbname = 'Tables_in_'.DB_NAME;
1355
+ $cnt = 0;
1356
+ for ($i=0; $i<count($names); $i++)
1357
  {
1358
+ $excluded = get_option('rvg_ex_'.$names[$i]->$dbname);
1359
 
1360
  if(!$excluded)
1361
  { # TABLE NOT EXCLUDED
1362
  $cnt++;
1363
+ $query = "OPTIMIZE TABLE ".$names[$i]->$dbname;
1364
  $result = $wpdb -> get_results($query);
1365
 
1366
  // v2.7.5
1370
  ) AS size, table_rows
1371
  FROM information_schema.TABLES
1372
  WHERE table_schema = '".strtolower(DB_NAME)."'
1373
+ AND table_name = '".$names[$i]->$dbname."'
1374
  ";
1375
 
1376
  $table_info = $wpdb -> get_results($sql);
1380
  ?>
1381
  <tr>
1382
  <td align="right" valign="top"><?php echo $cnt?>.</td>
1383
+ <td valign="top" style="font-weight:bold;"><?php echo $names[$i]->$dbname ?></td>
1384
  <td valign="top"><?php echo $result[0]->Msg_text ?></td>
1385
  <td valign="top"><?php echo $table_info[0]->engine ?></td>
1386
  <td align="right" valign="top"><?php echo $table_info[0]->table_rows ?></td>
1389
  <?php
1390
  } // if($display)
1391
  } // if($wp_only == 'N' || ($wp_only == 'Y' && substr($row[0],0,strlen($table_prefix)) == $table_prefix))
1392
+ } // for ($i=0; $i<count($names); $i++)
1393
  return $cnt;
1394
 
1395
  } // rvg_optimize_tables ()
1396
 
1397
+
1398
  /********************************************************************************************
1399
 
1400
  FIX WP_ONLY (DEPRECIATED FROM v2.2)
1407
  $wp_only = get_option('rvg_wp_only');
1408
  if($wp_only == 'Y')
1409
  {
1410
+ # v2.7.8
1411
+ $names = $wpdb->get_results("SHOW TABLES FROM `".DB_NAME."`");
1412
+ $dbname = 'Tables_in_'.DB_NAME;
1413
+ for ($i=0; $i<count($names); $i++)
1414
+ { if(substr($names[$i]->$dbname,0,strlen($table_prefix)) != $table_prefix)
1415
  { // NOT A WORDPRESS TABLE: EXLUDE IT
1416
  $sql = "
1417
  INSERT INTO $wpdb->options (option_name, option_value, autoload)
1429
 
1430
  } # function rvg_fix_wp_only ()
1431
 
1432
+
1433
  /********************************************************************************************
1434
 
1435
  WRITE LINE TO LOG FILE
1535
 
1536
  } // rvg_write_log ()
1537
 
1538
+
1539
  /********************************************************************************************
1540
 
1541
  GET REVISIONS
1558
 
1559
  } // rvg_get_revisions ()
1560
 
1561
+
1562
  /********************************************************************************************
1563
 
1564
  GET TRASHED POSTS / PAGES AND COMMENTS
1583
 
1584
  } // rvg_get_trash ()
1585
 
1586
+
1587
  /********************************************************************************************
1588
 
1589
  GET SPAMMED COMMENTS
1604
 
1605
  } // rvg_get_trash ()
1606
 
1607
+
1608
  /********************************************************************************************
1609
 
1610
  CALCULATE THE SIZE OF THE WORDPRESS DATABASE (IN BYTES)
1628
 
1629
  } // rvg_get_db_size ()
1630
 
1631
+
1632
  /********************************************************************************************
1633
 
1634
  FORMAT SIZES FROM BYTES TO KB OR MB
1643
 
1644
  return $table_size;
1645
  } // rvg_format_size ()
1646
+ ?>