Optimize Database after Deleting Revisions - Version 3.0

Version Description

[12/28/2014] = * BUG FIX: tags only used in scheduled posts won't be deleted anymore (thanks Michael!)

Download this release

Release Info

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

Code changes from version 2.9 to 3.0

Files changed (2) hide show
  1. readme.txt +9 -6
  2. rvg-optimize-db.php +39 -10
readme.txt CHANGED
@@ -8,8 +8,8 @@ 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.1
11
- Stable tag: 2.9
12
- Version: 2.9
13
  License: GPLv2 or later
14
 
15
  == Description ==
@@ -53,13 +53,13 @@ http://wordpress.org/plugins/rvg-optimize-database/
53
  NO WARRANTY, USE IT AT YOUR OWN RISK!
54
 
55
  = Plugins by Rolf van Gelder =
56
- Optimize Database after Deleting Revisions<br />
57
  http://wordpress.org/plugins/rvg-optimize-database/<br />
58
- Rocket Reader (Speed reader)<br />
59
  http://wordpress.org/plugins/rocket-reader-speed-reader/<br />
60
- Order your Posts Manually<br />
61
  http://wordpress.org/plugins/order-your-posts-manually/<br />
62
- Float to Top Button<br />
63
  http://wordpress.org/plugins/float-to-top-button/
64
 
65
  == Installation ==
@@ -70,6 +70,9 @@ http://wordpress.org/plugins/float-to-top-button/
70
 
71
  == Changelog ==
72
 
 
 
 
73
  = 2.9 [10/22/2014] =
74
  * NEW: plugin has been fully localized
75
  * NEW: dutch language support [nl_NL] added
8
  Author: CAGE Web Design | Rolf van Gelder, Eindhoven, The Netherlands
9
  Requires at least: 2.8
10
  Tested up to: 4.1
11
+ Stable tag: 3.0
12
+ Version: 3.0
13
  License: GPLv2 or later
14
 
15
  == Description ==
53
  NO WARRANTY, USE IT AT YOUR OWN RISK!
54
 
55
  = Plugins by Rolf van Gelder =
56
+ <em>Optimize Database after Deleting Revisions</em><br />
57
  http://wordpress.org/plugins/rvg-optimize-database/<br />
58
+ <em>Rocket Reader (Speed reader)</em><br />
59
  http://wordpress.org/plugins/rocket-reader-speed-reader/<br />
60
+ <em>Order your Posts Manually</em><br />
61
  http://wordpress.org/plugins/order-your-posts-manually/<br />
62
+ <em>Float to Top Button</em><br />
63
  http://wordpress.org/plugins/float-to-top-button/
64
 
65
  == Installation ==
70
 
71
  == Changelog ==
72
 
73
+ = 3.0 [12/28/2014] =
74
+ * BUG FIX: tags only used in scheduled posts won't be deleted anymore (thanks Michael!)
75
+
76
  = 2.9 [10/22/2014] =
77
  * NEW: plugin has been fully localized
78
  * NEW: dutch language support [nl_NL] added
rvg-optimize-db.php CHANGED
@@ -1,16 +1,16 @@
1
  <?php
2
- $odb_version = '2.9';
3
- $odb_release_date = '10/22/2014';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
- * @version 2.9
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.9
14
  Author URI: http://cagewebdev.com
15
  */
16
 
@@ -281,7 +281,7 @@ function schedule_changed()
281
  <p><?php echo __('Plugin version:','rvg-optimize-database');?><br />
282
  <strong>v<?php echo $odb_version ?> (<?php echo $odb_release_date?>)</strong> </p>
283
  <p><strong><?php echo __('Author','rvg-optimize-database');?>:</strong><br />
284
- <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, <?php echo __('The Netherlands','rvg-optimize-database');?><br />
285
  <strong><?php echo __('Plugin URL:','rvg-optimize-database');?></strong><br />
286
  <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 />
287
  <strong><?php echo __('Download URL:','rvg-optimize-database');?></strong><br />
@@ -531,7 +531,7 @@ function rvg_optimize_db()
531
  if($_REQUEST['action'] == "delete_log")
532
  echo '<div class="updated" style="position:relative;left:-15px;"><p><strong>Optimize Database after Deleting Revisions - LOG FILE DELETED</strong></p></div>';
533
  ?>
534
- <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> - <?php echo __('A WordPress Plugin by','rvg-optimize-database');?> <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, <?php echo __('The Netherlands','rvg-optimize-database');?></span></p>
535
  <p><?php echo __('Current options','rvg-optimize-database');?>:<br />
536
  <strong><?php echo __('Maximum number of - most recent - revisions to keep per post / page','rvg-optimize-database');?>:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $max_revisions?></span><br />
537
  <strong><?php echo __('Delete all trashed items','rvg-optimize-database');?>:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_trash_yn?></span><br />
@@ -1216,17 +1216,46 @@ function rvg_delete_tags()
1216
  $total_deleted = 0;
1217
 
1218
  $tags = get_terms('post_tag', array('hide_empty' => 0));
 
1219
  for($i=0; $i<count($tags); $i++)
1220
  if($tags[$i]->count < 1)
1221
- { $total_deleted++;
1222
- // echo $tags[$i]->term_id.' '.$tags[$i]->name.'<br />';
1223
- wp_delete_term($tags[$i]->term_id,'post_tag');
 
 
 
1224
  }
1225
 
1226
  return $total_deleted;
1227
  } // rvg_delete_tags ()
1228
 
1229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1230
  /********************************************************************************************
1231
 
1232
  DELETE EXPIRED TRANSIENTS
@@ -1460,7 +1489,7 @@ td {
1460
  <body>
1461
  <div id="header">
1462
  <h2><a href="http://wordpress.org/extend/plugins/rvg-optimize-database/" target="_blank">Optimize Database after Deleting Revisions v'.$odb_version.'</a></h2>
1463
- '.__('A WordPress Plugin by','rvg-optimize-database').' <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','rvg-optimize-database').'</strong>
1464
  </div>
1465
  <table width="100%" border="0" cellspacing="6" cellpadding="1">
1466
  <tr>
1
  <?php
2
+ $odb_version = '3.0';
3
+ $odb_release_date = '12/28/2014';
4
  /**
5
  * @package Optimize Database after Deleting Revisions
6
+ * @version 3.0
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: 3.0
14
  Author URI: http://cagewebdev.com
15
  */
16
 
281
  <p><?php echo __('Plugin version:','rvg-optimize-database');?><br />
282
  <strong>v<?php echo $odb_version ?> (<?php echo $odb_release_date?>)</strong> </p>
283
  <p><strong><?php echo __('Author','rvg-optimize-database');?>:</strong><br />
284
+ <strong><a href="http://cagewebdev.com/" target="_blank">CAGE Web Design</a> | <a href="http://rvg.cage.nl/" target="_blank">Rolf van Gelder</a></strong>, Eindhoven, <?php echo __('The Netherlands','rvg-optimize-database');?><br />
285
  <strong><?php echo __('Plugin URL:','rvg-optimize-database');?></strong><br />
286
  <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 />
287
  <strong><?php echo __('Download URL:','rvg-optimize-database');?></strong><br />
531
  if($_REQUEST['action'] == "delete_log")
532
  echo '<div class="updated" style="position:relative;left:-15px;"><p><strong>Optimize Database after Deleting Revisions - LOG FILE DELETED</strong></p></div>';
533
  ?>
534
+ <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> - <?php echo __('A WordPress Plugin by','rvg-optimize-database');?> <a href="http://cagewebdev.com/" target="_blank" style="font-weight:bold;">CAGE Web Design</a> | <a href="http://rvg.cage.nl/" target="_blank" style="font-weight:bold;">Rolf van Gelder</a>, Eindhoven, <?php echo __('The Netherlands','rvg-optimize-database');?></span></p>
535
  <p><?php echo __('Current options','rvg-optimize-database');?>:<br />
536
  <strong><?php echo __('Maximum number of - most recent - revisions to keep per post / page','rvg-optimize-database');?>:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $max_revisions?></span><br />
537
  <strong><?php echo __('Delete all trashed items','rvg-optimize-database');?>:</strong> <span style="font-weight:bold;color:#00F;"><?php echo $clear_trash_yn?></span><br />
1216
  $total_deleted = 0;
1217
 
1218
  $tags = get_terms('post_tag', array('hide_empty' => 0));
1219
+
1220
  for($i=0; $i<count($tags); $i++)
1221
  if($tags[$i]->count < 1)
1222
+ { if(!rvg_delete_tags_is_scheduled($tags[$i]->term_id))
1223
+ { // v3.0: TAG NOT USED IN SCHEDULED POSTS: CAN BE DELETED
1224
+ $total_deleted++;
1225
+ // echo $tags[$i]->term_id.' '.$tags[$i]->name.'<br />';
1226
+ wp_delete_term($tags[$i]->term_id,'post_tag');
1227
+ }
1228
  }
1229
 
1230
  return $total_deleted;
1231
  } // rvg_delete_tags ()
1232
 
1233
 
1234
+ /********************************************************************************************
1235
+
1236
+ v3.0: IS THE UNUSED TAG USED IN ONE OR MORE SCHEDULED POSTS?
1237
+
1238
+ *********************************************************************************************/
1239
+ function rvg_delete_tags_is_scheduled($term_id)
1240
+ {
1241
+ global $wpdb;
1242
+
1243
+ $sql_get_posts = "
1244
+ SELECT p.post_status
1245
+ FROM $wpdb->term_relationships t, $wpdb->posts p
1246
+ WHERE t.term_taxonomy_id = '".$term_id."'
1247
+ AND t.object_id = p.ID
1248
+ ";
1249
+
1250
+ $results_get_posts = $wpdb -> get_results($sql_get_posts);
1251
+ for($i=0; $i<count($results_get_posts); $i++)
1252
+ if($results_get_posts[$i]->post_status == 'future') return true;
1253
+
1254
+ return false;
1255
+
1256
+ } // rvg_delete_tags_is_scheduled()
1257
+
1258
+
1259
  /********************************************************************************************
1260
 
1261
  DELETE EXPIRED TRANSIENTS
1489
  <body>
1490
  <div id="header">
1491
  <h2><a href="http://wordpress.org/extend/plugins/rvg-optimize-database/" target="_blank">Optimize Database after Deleting Revisions v'.$odb_version.'</a></h2>
1492
+ '.__('A WordPress Plugin by','rvg-optimize-database').' <a href="http://cagewebdev.com" target="_blank"><strong>CAGE Web Design</strong></a> | <a href="http://rvg.cage.nl" target="_blank"><strong>Rolf van Gelder</strong></a>, Eindhoven, '.__('The Netherlands','rvg-optimize-database').'</strong>
1493
  </div>
1494
  <table width="100%" border="0" cellspacing="6" cellpadding="1">
1495
  <tr>