Post Expirator - Version 1.6.2

Version Description

Download this release

Release Info

Developer axelseaa
Plugin Icon 128x128 Post Expirator
Version 1.6.2
Comparing to
See all releases

Code changes from version 1.6.1 to 1.6.2

Files changed (2) hide show
  1. post-expirator.php +63 -35
  2. readme.txt +7 -1
post-expirator.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Post Expirator
4
  Plugin URI: http://wordpress.org/extend/plugins/post-expirator/
5
  Description: Allows you to add an expiration date (minute) to posts which you can configure to either delete the post, change it to a draft, or update the post categories at expiration time.
6
  Author: Aaron Axelsen
7
- Version: 1.6.1
8
  Author URI: http://postexpirator.tuxdocs.net/
9
  Translation: Thierry (http://palijn.info)
10
  Text Domain: post-expirator
@@ -19,7 +19,7 @@ add_action('plugins_loaded', 'postExpirator_init');
19
 
20
 
21
  // Default Values
22
- define('POSTEXPIRATOR_VERSION','1.6.1');
23
  define('POSTEXPIRATOR_DATEFORMAT',__('l F jS, Y','post-expirator'));
24
  define('POSTEXPIRATOR_TIMEFORMAT',__('g:ia','post-expirator'));
25
  define('POSTEXPIRATOR_FOOTERCONTENTS',__('Post expires at EXPIRATIONTIME on EXPIRATIONDATE','post-expirator'));
@@ -28,6 +28,7 @@ define('POSTEXPIRATOR_POSTSTATUS','Draft');
28
  define('POSTEXPIRATOR_PAGESTATUS','Draft');
29
  define('POSTEXPIRATOR_FOOTERDISPLAY','0');
30
  define('POSTEXPIRATOR_CATEGORY','1');
 
31
  define('POSTEXPIRATOR_DEBUG','0');
32
  define('POSTEXPIRATOR_CRONSCHEDULE','postexpiratorminute');
33
  define('POSTEXPIRATOR_EXPIREDEFAULT','null');
@@ -100,15 +101,15 @@ function expirationdate_delete_expired_posts() {
100
  require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
101
 
102
  $debug = new postExpiratorDebug();
103
- $startts = mktime();
104
  $debug->save(array('timestamp' => $startts,'message' => 'START'));
105
  $debug->save(array('timestamp' => $startts,'message' => 'SQL EXPIRE: '.$sql));
106
  }
107
 
108
  $processsql = 'select post_id from '.$wpdb->postmeta.' where meta_key = "_expiration-date-processed" AND meta_value = "1"';
109
- if ($debugEnabled) $debug->save(array('timestamp' => mktime(),'message' => 'SQL PROCESSED: '.$processsql));
110
  $processresult = $wpdb->get_col($processsql);
111
- if ($debugEnabled) $debug->save(array('timestamp' => mktime(),'message' => 'PROCESSED POST IDS: '.print_r($processresult,true)));
112
 
113
  if (!empty($result)) foreach ($result as $a) {
114
  // Check to see if already proccessed
@@ -128,28 +129,29 @@ function expirationdate_delete_expired_posts() {
128
  $cat = get_post_meta($a->post_id,'_expiration-date-category');
129
  if (($catEnabled === false || $catEnabled == 1) && (isset($cat) && !empty($cat[0]))) {
130
  wp_update_post(array('ID' => $a->post_id, 'post_category' => $cat[0]));
131
- if ($debugEnabled) $debug->save(array('timestamp' => mktime(),'message' => 'EXPIRE: ID:'.$a->post_id.' CATEGORY:'.print_r($cat[0],true)));
132
  } else {
133
  if ($expiredStatus == 'delete') {
134
  wp_delete_post($a->post_id);
135
- if ($debugEnabled) $debug->save(array('timestamp' => mktime(),'message' => 'EXPIRE: ID:'.$a->post_id.' DELETE'));
136
  } else {
137
  wp_update_post(array('ID' => $a->post_id, 'post_status' => 'draft'));
138
  delete_post_meta($a->post_id, 'expiration-date');
139
  update_post_meta($a->post_id, 'expiration-date', $a->meta_value);
140
- if ($debugEnabled) $debug->save(array('timestamp' => mktime(),'message' => 'EXPIRE: ID:'.$a->post_id.' DRAFT'));
141
  }
142
  }
143
 
144
  // Mark as Processed
145
  update_post_meta($a->post_id, '_expiration-date-processed', 1);
146
- if ($debugEnabled) $debug->save(array('timestamp' => mktime(),'message' => 'PROCESSED: ID:'.$a->post_id));
147
  }
148
- if ($debugEnabled) $debug->save(array('timestamp' => mktime(),'message' => 'END - DURATION: '.(mktime() - $startts)));
149
  }
150
- if (postExpirator_is_wpmu())
 
151
  add_action ('expirationdate_delete_'.$current_blog->blog_id, 'expirationdate_delete_expired_posts');
152
- else
153
  add_action ('expirationdate_delete', 'expirationdate_delete_expired_posts');
154
 
155
  /**
@@ -222,6 +224,12 @@ function expirationdate_meta_box($post) {
222
  $enabled = '';
223
  $disabled = ' disabled="disabled"';
224
  $categories = get_option('expirationdateCategoryDefaults');
 
 
 
 
 
 
225
  } else {
226
  $defaultmonth = date('F',$expirationdatets);
227
  $defaultday = date('d',$expirationdatets);
@@ -483,6 +491,7 @@ function postExpiratorMenuGeneral() {
483
  update_option('expirationdateCategoryDefaults',$_POST['expirationdate_category']);
484
  update_option('expirationdateCronSchedule',$_POST['expired-default-cron-schedule']);
485
  update_option('expirationdateDefaultDate',$_POST['expired-default-expiration-date']);
 
486
  if ($_POST['expired-custom-expiration-date']) update_option('expirationdateDefaultDateCustom',$_POST['expired-custom-expiration-date']);
487
  postExpiratorResetCronEvent();
488
  echo "<div id='message' class='updated fade'><p>";
@@ -497,6 +506,7 @@ function postExpiratorMenuGeneral() {
497
  $expirationdateDefaultDateFormat = get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
498
  $expirationdateDefaultTimeFormat = get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
499
  $expiredcategory = get_option('expirationdateCategory',POSTEXPIRATOR_CATEGORY);
 
500
  $expireddisplayfooter = get_option('expirationdateDisplayFooter',POSTEXPIRATOR_FOOTERDISPLAY);
501
  $expirationdateFooterContents = get_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
502
  $expirationdateFooterStyle = get_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
@@ -520,6 +530,12 @@ function postExpiratorMenuGeneral() {
520
  else if ($expiredcategory == 1)
521
  $expiredcategoryenabled = 'checked="checked"';
522
 
 
 
 
 
 
 
523
 
524
  ?>
525
  <p>
@@ -558,6 +574,15 @@ function postExpiratorMenuGeneral() {
558
  <?php _e('Select whether the page should be deleted or changed to a draft at expiration time.','post-expirator');?>
559
  </td>
560
  </tr>
 
 
 
 
 
 
 
 
 
561
  <tr valign-"top">
562
  <th scope="row"><label for="expired-default-date-format"><?php _e('Date Format:','post-expirator');?></label></th>
563
  <td>
@@ -945,7 +970,10 @@ function postexpirator_upgrade() {
945
  update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
946
  update_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
947
  break;
948
-
 
 
 
949
  }
950
  }
951
  }
@@ -992,6 +1020,7 @@ function expirationdate_deactivate () {
992
  delete_option('expirationdateCronSchedule');
993
  delete_option('expirationdateDefaultDate');
994
  delete_option('expirationdateDefaultDateCustom');
 
995
  if (postExpirator_is_wpmu())
996
  wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
997
  else
@@ -1003,8 +1032,8 @@ function expirationdate_deactivate () {
1003
  register_deactivation_hook (__FILE__, 'expirationdate_deactivate');
1004
 
1005
  class Walker_PostExpirator_Category_Checklist extends Walker {
1006
- var $tree_type = 'category';
1007
- var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
1008
 
1009
  var $disabled = '';
1010
 
@@ -1012,29 +1041,28 @@ class Walker_PostExpirator_Category_Checklist extends Walker {
1012
  $this->disabled = 'disabled="disabled"';
1013
  }
1014
 
1015
- function start_lvl(&$output, $depth, $args) {
1016
- $indent = str_repeat("\t", $depth);
1017
- $output .= "$indent<ul class='children'>\n";
1018
- }
1019
 
1020
- function end_lvl(&$output, $depth, $args) {
1021
- $indent = str_repeat("\t", $depth);
1022
- $output .= "$indent</ul>\n";
1023
- }
1024
 
1025
- function start_el(&$output, $category, $depth, $args) {
1026
- extract($args);
1027
- if ( empty($taxonomy) )
1028
- $taxonomy = 'category';
1029
 
1030
  $name = 'expirationdate_category';
1031
 
1032
- $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
1033
- $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' '.$this->disabled.'/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
1034
- }
1035
-
1036
- function end_el(&$output, $category, $depth, $args) {
1037
- $output .= "</li>\n";
1038
- }
1039
  }
1040
-
4
  Plugin URI: http://wordpress.org/extend/plugins/post-expirator/
5
  Description: Allows you to add an expiration date (minute) to posts which you can configure to either delete the post, change it to a draft, or update the post categories at expiration time.
6
  Author: Aaron Axelsen
7
+ Version: 1.6.2
8
  Author URI: http://postexpirator.tuxdocs.net/
9
  Translation: Thierry (http://palijn.info)
10
  Text Domain: post-expirator
19
 
20
 
21
  // Default Values
22
+ define('POSTEXPIRATOR_VERSION','1.6.2');
23
  define('POSTEXPIRATOR_DATEFORMAT',__('l F jS, Y','post-expirator'));
24
  define('POSTEXPIRATOR_TIMEFORMAT',__('g:ia','post-expirator'));
25
  define('POSTEXPIRATOR_FOOTERCONTENTS',__('Post expires at EXPIRATIONTIME on EXPIRATIONDATE','post-expirator'));
28
  define('POSTEXPIRATOR_PAGESTATUS','Draft');
29
  define('POSTEXPIRATOR_FOOTERDISPLAY','0');
30
  define('POSTEXPIRATOR_CATEGORY','1');
31
+ define('POSTEXPIRATOR_AUTOENABLE','0');
32
  define('POSTEXPIRATOR_DEBUG','0');
33
  define('POSTEXPIRATOR_CRONSCHEDULE','postexpiratorminute');
34
  define('POSTEXPIRATOR_EXPIREDEFAULT','null');
101
  require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
102
 
103
  $debug = new postExpiratorDebug();
104
+ $startts = time();
105
  $debug->save(array('timestamp' => $startts,'message' => 'START'));
106
  $debug->save(array('timestamp' => $startts,'message' => 'SQL EXPIRE: '.$sql));
107
  }
108
 
109
  $processsql = 'select post_id from '.$wpdb->postmeta.' where meta_key = "_expiration-date-processed" AND meta_value = "1"';
110
+ if ($debugEnabled) $debug->save(array('timestamp' => time(),'message' => 'SQL PROCESSED: '.$processsql));
111
  $processresult = $wpdb->get_col($processsql);
112
+ if ($debugEnabled) $debug->save(array('timestamp' => time(),'message' => 'PROCESSED POST IDS: '.print_r($processresult,true)));
113
 
114
  if (!empty($result)) foreach ($result as $a) {
115
  // Check to see if already proccessed
129
  $cat = get_post_meta($a->post_id,'_expiration-date-category');
130
  if (($catEnabled === false || $catEnabled == 1) && (isset($cat) && !empty($cat[0]))) {
131
  wp_update_post(array('ID' => $a->post_id, 'post_category' => $cat[0]));
132
+ if ($debugEnabled) $debug->save(array('timestamp' => time(),'message' => 'EXPIRE: ID:'.$a->post_id.' CATEGORY:'.print_r($cat[0],true)));
133
  } else {
134
  if ($expiredStatus == 'delete') {
135
  wp_delete_post($a->post_id);
136
+ if ($debugEnabled) $debug->save(array('timestamp' => time(),'message' => 'EXPIRE: ID:'.$a->post_id.' DELETE'));
137
  } else {
138
  wp_update_post(array('ID' => $a->post_id, 'post_status' => 'draft'));
139
  delete_post_meta($a->post_id, 'expiration-date');
140
  update_post_meta($a->post_id, 'expiration-date', $a->meta_value);
141
+ if ($debugEnabled) $debug->save(array('timestamp' => time(),'message' => 'EXPIRE: ID:'.$a->post_id.' DRAFT'));
142
  }
143
  }
144
 
145
  // Mark as Processed
146
  update_post_meta($a->post_id, '_expiration-date-processed', 1);
147
+ if ($debugEnabled) $debug->save(array('timestamp' => time(),'message' => 'PROCESSED: ID:'.$a->post_id));
148
  }
149
+ if ($debugEnabled) $debug->save(array('timestamp' => time(),'message' => 'END - DURATION: '.(time() - $startts)));
150
  }
151
+ if (postExpirator_is_wpmu()) {
152
+ global $current_blog;
153
  add_action ('expirationdate_delete_'.$current_blog->blog_id, 'expirationdate_delete_expired_posts');
154
+ } else
155
  add_action ('expirationdate_delete', 'expirationdate_delete_expired_posts');
156
 
157
  /**
224
  $enabled = '';
225
  $disabled = ' disabled="disabled"';
226
  $categories = get_option('expirationdateCategoryDefaults');
227
+
228
+ $expiredauto = get_option('expirationdateAutoEnabled',POSTEXPIRATOR_AUTOENABLE);
229
+ if ($expiredauto === true || $expiredauto == 1) {
230
+ $enabled = ' checked="checked"';
231
+ $disabled='';
232
+ }
233
  } else {
234
  $defaultmonth = date('F',$expirationdatets);
235
  $defaultday = date('d',$expirationdatets);
491
  update_option('expirationdateCategoryDefaults',$_POST['expirationdate_category']);
492
  update_option('expirationdateCronSchedule',$_POST['expired-default-cron-schedule']);
493
  update_option('expirationdateDefaultDate',$_POST['expired-default-expiration-date']);
494
+ update_option('expirationdateAutoEnabled',$_POST['expired-auto-enable']);
495
  if ($_POST['expired-custom-expiration-date']) update_option('expirationdateDefaultDateCustom',$_POST['expired-custom-expiration-date']);
496
  postExpiratorResetCronEvent();
497
  echo "<div id='message' class='updated fade'><p>";
506
  $expirationdateDefaultDateFormat = get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
507
  $expirationdateDefaultTimeFormat = get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
508
  $expiredcategory = get_option('expirationdateCategory',POSTEXPIRATOR_CATEGORY);
509
+ $expiredauto = get_option('expirationdateAutoEnabled',POSTEXPIRATOR_AUTOENABLE);
510
  $expireddisplayfooter = get_option('expirationdateDisplayFooter',POSTEXPIRATOR_FOOTERDISPLAY);
511
  $expirationdateFooterContents = get_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
512
  $expirationdateFooterStyle = get_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
530
  else if ($expiredcategory == 1)
531
  $expiredcategoryenabled = 'checked="checked"';
532
 
533
+ $expiredautoenabled = '';
534
+ $expiredautodisabled = '';
535
+ if ($expiredauto == 0)
536
+ $expiredautodisabled = 'checked="checked"';
537
+ else if ($expiredauto == 1)
538
+ $expiredautoenabled= 'checked="checked"';
539
 
540
  ?>
541
  <p>
574
  <?php _e('Select whether the page should be deleted or changed to a draft at expiration time.','post-expirator');?>
575
  </td>
576
  </tr>
577
+ <tr valign-"top">
578
+ <th scope="row"><label for="expired-auto-enable"><?php _e('Auto-Enable Post Expirator:','post-expirator');?></label></th>
579
+ <td>
580
+ <input type="radio" name="expired-auto-enable" id="expired-auto-enable-true" value="1" <?php echo $expiredautoenabled ?>/> <label for="expired-auto-enable-true"><?php _e('Enabled','post-expirator');?></label>
581
+ <input type="radio" name="expired-auto-enable" id="expired-auto-enable-false" value="0" <?php echo $expiredautodisabled ?>/> <label for="expired-auto-enable-false"><?php _e('Disabled','post-expirator');?></label>
582
+ <br/>
583
+ <?php _e('Select whether the post expirator is enabled for all new posts.','post-expirator');?>
584
+ </td>
585
+ </tr>
586
  <tr valign-"top">
587
  <th scope="row"><label for="expired-default-date-format"><?php _e('Date Format:','post-expirator');?></label></th>
588
  <td>
970
  update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
971
  update_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
972
  break;
973
+ case '1.6.2':
974
+ update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
975
+ update_option('expirationdateAutoEnabled',POSTEXPIRATOR_AUTOENABLE);
976
+ break;
977
  }
978
  }
979
  }
1020
  delete_option('expirationdateCronSchedule');
1021
  delete_option('expirationdateDefaultDate');
1022
  delete_option('expirationdateDefaultDateCustom');
1023
+ delete_option('expirationdateAutoEnabled');
1024
  if (postExpirator_is_wpmu())
1025
  wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
1026
  else
1032
  register_deactivation_hook (__FILE__, 'expirationdate_deactivate');
1033
 
1034
  class Walker_PostExpirator_Category_Checklist extends Walker {
1035
+ var $tree_type = 'category';
1036
+ var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
1037
 
1038
  var $disabled = '';
1039
 
1041
  $this->disabled = 'disabled="disabled"';
1042
  }
1043
 
1044
+ function start_lvl(&$output, $depth, $args) {
1045
+ $indent = str_repeat("\t", $depth);
1046
+ $output .= "$indent<ul class='children'>\n";
1047
+ }
1048
 
1049
+ function end_lvl(&$output, $depth, $args) {
1050
+ $indent = str_repeat("\t", $depth);
1051
+ $output .= "$indent</ul>\n";
1052
+ }
1053
 
1054
+ function start_el(&$output, $category, $depth, $args) {
1055
+ extract($args);
1056
+ if ( empty($taxonomy) )
1057
+ $taxonomy = 'category';
1058
 
1059
  $name = 'expirationdate_category';
1060
 
1061
+ $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
1062
+ $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' '.$this->disabled.'/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
1063
+ }
1064
+
1065
+ function end_el(&$output, $category, $depth, $args) {
1066
+ $output .= "</li>\n";
1067
+ }
1068
  }
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: axelseaa
3
  Tags: expire, posts, pages, schedule
4
  Requires at least: 3.2
5
  Tested up to: 3.4
6
- Stable tag: 1.6.1
7
 
8
  Allows you to add an expiration date to posts which you can configure to either delete the post, change it to a draft, or update the
9
  post categories.
@@ -47,6 +47,12 @@ This section describes how to install the plugin and get it working.
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
 
50
  **Version 1.6.1**
51
 
52
  * Tweaked error messages, removed clicks for reset cron event
3
  Tags: expire, posts, pages, schedule
4
  Requires at least: 3.2
5
  Tested up to: 3.4
6
+ Stable tag: 1.6.2
7
 
8
  Allows you to add an expiration date to posts which you can configure to either delete the post, change it to a draft, or update the
9
  post categories.
47
 
48
  == Changelog ==
49
 
50
+ **Version 1.6.2**
51
+
52
+ * Added the ability to configure the post expirator to be enabled by default for all new posts
53
+ * Changed some instances of mktime to time
54
+ * Fixed missing global call for MS installs
55
+
56
  **Version 1.6.1**
57
 
58
  * Tweaked error messages, removed clicks for reset cron event