Post Expirator - Version 1.0

Version Description

Download this release

Release Info

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

Code changes from version 1.2 to 1.0

Files changed (2) hide show
  1. post-expirator.php +13 -57
  2. readme.txt +4 -23
post-expirator.php CHANGED
@@ -4,19 +4,16 @@ Plugin Name: Post Expirator
4
  Plugin URI: http://wordpress.org/extend/plugins/post-expirator/
5
  Description: Allows you to add an expiration date (hourly) to posts which you can configure to either delete the post or change it to a draft.
6
  Author: Aaron Axelsen
7
- Version: 1.2
8
  Author URI: http://www.frozenpc.net
9
  */
10
 
11
- // Default Values
12
- $expirationdateDefaultDateFormat = 'l F jS, Y g:ia';
13
-
14
  /**
15
  * Function that does the actualy deleting - called by wp_cron
16
  */
17
  function expirationdate_delete_expired_posts() {
18
  global $wpdb;
19
- $result = $wpdb->get_results('select post_id, meta_value from ' . $wpdb->postmeta . ' where meta_key = "expiration-date" AND meta_value <= "' . mktime() . '"');
20
  foreach ($result as $a) {
21
  $post_result = $wpdb->get_var('select post_type from ' . $wpdb->posts .' where ID = '. $a->post_id);
22
  if ($post_result == 'post') {
@@ -29,11 +26,8 @@ function expirationdate_delete_expired_posts() {
29
 
30
  if ($expiredStatus == 'delete')
31
  wp_delete_post($a->post_id);
32
- else {
33
  wp_update_post(array('ID' => $a->post_id, 'post_status' => 'draft'));
34
- delete_post_meta($a->post_id, 'expiration-date');
35
- update_post_meta($a->post_id, 'expiration-date', $a->meta_value, true);
36
- }
37
  }
38
  }
39
  add_action ('expirationdate_delete_'.$current_blog->blog_id, 'expirationdate_delete_expired_posts');
@@ -42,10 +36,9 @@ add_action ('expirationdate_delete_'.$current_blog->blog_id, 'expirationdate_del
42
  * Called at plugin activation
43
  */
44
  function expirationdate_activate () {
45
- global $current_blog,$expirationdateDefaultDateFormat;
46
  update_option('expirationdateExpiredPostStatus','Draft');
47
  update_option('expirationdateExpiredPageStatus','Draft');
48
- update_option('expirationdateDefaultDateFormat',$expirationdateDefaultDateFormat);
49
  wp_schedule_event(mktime(date('H'),0,0,date('m'),date('d'),date('Y')), 'hourly', 'expirationdate_delete_'.$current_blog->blog_id);
50
  }
51
  register_activation_hook (__FILE__, 'expirationdate_activate');
@@ -57,7 +50,6 @@ function expirationdate_deactivate () {
57
  global $current_blog;
58
  delete_option('expirationdateExpiredPostStatus');
59
  delete_option('expirationdateExpiredPageStatus');
60
- delete_option('expirationdateDefaultDateFormat');
61
  wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
62
  }
63
  register_deactivation_hook (__FILE__, 'expirationdate_deactivate');
@@ -91,7 +83,7 @@ add_action ('manage_pages_custom_column', 'expirationdate_show_value');
91
  * Add's hooks to get the meta box added to post
92
  */
93
  function expirationdate_meta_post() {
94
- add_meta_box('expirationdatediv', __('Post Expirator'), 'expirationdate_meta_box', 'post', 'advanced', 'high');
95
  }
96
  add_action ('dbx_post_advanced','expirationdate_meta_post');
97
 
@@ -99,7 +91,7 @@ add_action ('dbx_post_advanced','expirationdate_meta_post');
99
  * Add's hooks to get the meta box added to page
100
  */
101
  function expirationdate_meta_page() {
102
- add_meta_box('expirationdatediv', __('Post Expirator'), 'expirationdate_meta_box', 'page', 'advanced', 'high');
103
  }
104
  add_action ('edit_page_form','expirationdate_meta_page');
105
 
@@ -127,7 +119,7 @@ function expirationdate_meta_box($post) {
127
 
128
  $rv = array();
129
  $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"'.$enabled.' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />';
130
- $rv[] = '<label for="enable-expirationdate">Enable Post Expiration</label></p>';
131
  $rv[] = '<table><tr>';
132
  $rv[] = '<th style="text-align: left;">Month</th>';
133
  $rv[] = '<th style="text-align: left;">Day</th>';
@@ -240,9 +232,6 @@ function expirationdate_get_blog_url() {
240
  * Called when post is saved - stores expiration-date meta value
241
  */
242
  function expirationdate_update_post_meta($id) {
243
- if ( 'autosave' == $_POST['action'] )
244
- return;
245
-
246
  $month = $_POST['expirationdate_month'];
247
  $day = $_POST['expirationdate_day'];
248
  $year = $_POST['expirationdate_year'];
@@ -264,7 +253,7 @@ add_action('save_post','expirationdate_update_post_meta');
264
  * Hook's to add plugin page menu
265
  */
266
  function expirationdate_plugin_menu() {
267
- add_submenu_page('options-general.php','Post Expirator Options','Post Expirator',9,basename(__FILE__),'expirationdate_show_options');
268
  }
269
  add_action('admin_menu', 'expirationdate_plugin_menu');
270
 
@@ -276,7 +265,6 @@ function expirationdate_show_options() {
276
  if ($_POST['expirationdateSave']) {
277
  update_option('expirationdateExpiredPostStatus',$_POST['expired-post-status']);
278
  update_option('expirationdateExpiredPageStatus',$_POST['expired-page-status']);
279
- update_option('expirationdateDefaultDateFormat',$_POST['expired-default-date-format']);
280
  echo "<div id='message' class='updated fade'><p>Saved Options!</p></div>";
281
  }
282
 
@@ -289,23 +277,17 @@ function expirationdate_show_options() {
289
  if (empty($expirationdateExpiredPageStatus))
290
  $expirationdateExpiredPageStatus = 'Draft';
291
 
292
- $expirationdateDefaultDateFormat = get_option('expirationdateDefaultDateFormat');
293
- if (empty($expirationdateDefaultDateFormat)) {
294
- global $expirationdateDefaultDateFormat;
295
- $expirationdateDefaultDateFormat = $expirationdateDefaultDateFormat;
296
- }
297
-
298
  ?>
299
  <div class="wrap">
300
- <h2><?php _e('Post Expirator Options'); ?></h2>
301
  <p>
302
- The post expirator plugin sets a custom meta value, and then optionally allows you to select if you want the post
303
  changed to a draft status or deleted when it expires.
304
  </p>
305
  <form method="post" id="expirationdate_save_options">
306
  <table class="form-table">
307
  <tr valign-"top">
308
- <th scope="row"><label for="expired-post-status">Set Post To:</label></th>
309
  <td>
310
  <select name="expired-post-status" id="expired-post-status">
311
  <option<?php if ($expirationdateExpiredPostStatus == 'Draft'){ echo ' selected="selected"';}?>>Draft</option>
@@ -316,7 +298,7 @@ function expirationdate_show_options() {
316
  </td>
317
  </tr>
318
  <tr valign-"top">
319
- <th scope="row"><label for="expired-page-status">Set Page To:</label></th>
320
  <td>
321
  <select name="expired-page-status" id="expired-page-status">
322
  <option<?php if ($expirationdateExpiredPageStatus == 'Draft'){ echo ' selected="selected"';}?>>Draft</option>
@@ -326,15 +308,6 @@ function expirationdate_show_options() {
326
  Select whether the page should be deleted or changed to a draft at expiration time.
327
  </td>
328
  </tr>
329
- <tr valign-"top">
330
- <th scope="row"><label for="expired-default-date-format">Default Date Format:</label></th>
331
- <td>
332
- <input type="text" name="expired-default-date-format" id="expired-default-date-format" value="<?php echo $expirationdateDefaultDateFormat ?>" size="25" /> (<?php echo date("$expirationdateDefaultDateFormat") ?>)
333
- <br/>
334
- The default format to use when displaying the expiration date within a post using the [postexpirator]
335
- shortcode. For information on valid formatting options, see: <a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>.
336
- </td>
337
- </tr>
338
  </table>
339
  <p class="submit">
340
  <input type="submit" name="expirationdateSave" value="Save" />
@@ -344,21 +317,4 @@ function expirationdate_show_options() {
344
  <?php
345
  }
346
 
347
- // [postexpirator format="l F jS, Y g:ia" tz="foo"]
348
- function postexpirator_shortcode($atts) {
349
- global $post;
350
- $expirationdatets = get_post_meta($post->ID,'expiration-date',true);
351
- if (empty($expirationdatets))
352
- return false;
353
- extract(shortcode_atts(array(
354
- 'format' => get_option('expirationdateDefaultDateFormat'),
355
- 'tz' => date('T'),
356
- ), $atts));
357
-
358
- $postexpirator_date_display = get_option('expirationdateDefaultDateFormat');
359
- if (empty($format))
360
- $format = $expirationdateDefaultDateFormat;
361
-
362
- return date("$format",$expirationdatets);
363
- }
364
- add_shortcode('postexpirator', 'postexpirator_shortcode');
4
  Plugin URI: http://wordpress.org/extend/plugins/post-expirator/
5
  Description: Allows you to add an expiration date (hourly) to posts which you can configure to either delete the post or change it to a draft.
6
  Author: Aaron Axelsen
7
+ Version: 1.0
8
  Author URI: http://www.frozenpc.net
9
  */
10
 
 
 
 
11
  /**
12
  * Function that does the actualy deleting - called by wp_cron
13
  */
14
  function expirationdate_delete_expired_posts() {
15
  global $wpdb;
16
+ $result = $wpdb->get_results('select post_id from ' . $wpdb->postmeta . ' where meta_key = "expiration-date" AND meta_value < "' . mktime() . '"');
17
  foreach ($result as $a) {
18
  $post_result = $wpdb->get_var('select post_type from ' . $wpdb->posts .' where ID = '. $a->post_id);
19
  if ($post_result == 'post') {
26
 
27
  if ($expiredStatus == 'delete')
28
  wp_delete_post($a->post_id);
29
+ else
30
  wp_update_post(array('ID' => $a->post_id, 'post_status' => 'draft'));
 
 
 
31
  }
32
  }
33
  add_action ('expirationdate_delete_'.$current_blog->blog_id, 'expirationdate_delete_expired_posts');
36
  * Called at plugin activation
37
  */
38
  function expirationdate_activate () {
39
+ global $current_blog;
40
  update_option('expirationdateExpiredPostStatus','Draft');
41
  update_option('expirationdateExpiredPageStatus','Draft');
 
42
  wp_schedule_event(mktime(date('H'),0,0,date('m'),date('d'),date('Y')), 'hourly', 'expirationdate_delete_'.$current_blog->blog_id);
43
  }
44
  register_activation_hook (__FILE__, 'expirationdate_activate');
50
  global $current_blog;
51
  delete_option('expirationdateExpiredPostStatus');
52
  delete_option('expirationdateExpiredPageStatus');
 
53
  wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
54
  }
55
  register_deactivation_hook (__FILE__, 'expirationdate_deactivate');
83
  * Add's hooks to get the meta box added to post
84
  */
85
  function expirationdate_meta_post() {
86
+ add_meta_box('expirationdatediv', __('Expiration Date'), 'expirationdate_meta_box', 'post', 'advanced', 'high');
87
  }
88
  add_action ('dbx_post_advanced','expirationdate_meta_post');
89
 
91
  * Add's hooks to get the meta box added to page
92
  */
93
  function expirationdate_meta_page() {
94
+ add_meta_box('expirationdatediv', __('Expiration Date'), 'expirationdate_meta_box', 'page', 'advanced', 'high');
95
  }
96
  add_action ('edit_page_form','expirationdate_meta_page');
97
 
119
 
120
  $rv = array();
121
  $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"'.$enabled.' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />';
122
+ $rv[] = '<label for="enable-expirationdate">Enable Post Expiration</labael></p>';
123
  $rv[] = '<table><tr>';
124
  $rv[] = '<th style="text-align: left;">Month</th>';
125
  $rv[] = '<th style="text-align: left;">Day</th>';
232
  * Called when post is saved - stores expiration-date meta value
233
  */
234
  function expirationdate_update_post_meta($id) {
 
 
 
235
  $month = $_POST['expirationdate_month'];
236
  $day = $_POST['expirationdate_day'];
237
  $year = $_POST['expirationdate_year'];
253
  * Hook's to add plugin page menu
254
  */
255
  function expirationdate_plugin_menu() {
256
+ add_submenu_page('plugins.php','Expiration Date Options','Expiration Date',9,basename(__FILE__),'expirationdate_show_options');
257
  }
258
  add_action('admin_menu', 'expirationdate_plugin_menu');
259
 
265
  if ($_POST['expirationdateSave']) {
266
  update_option('expirationdateExpiredPostStatus',$_POST['expired-post-status']);
267
  update_option('expirationdateExpiredPageStatus',$_POST['expired-page-status']);
 
268
  echo "<div id='message' class='updated fade'><p>Saved Options!</p></div>";
269
  }
270
 
277
  if (empty($expirationdateExpiredPageStatus))
278
  $expirationdateExpiredPageStatus = 'Draft';
279
 
 
 
 
 
 
 
280
  ?>
281
  <div class="wrap">
282
+ <h2><?php _e('Expiration Date Options'); ?></h2>
283
  <p>
284
+ The expiration date plugin sets a custom meta value, and then optionally allows you to select if you want the post
285
  changed to a draft status or deleted when it expires.
286
  </p>
287
  <form method="post" id="expirationdate_save_options">
288
  <table class="form-table">
289
  <tr valign-"top">
290
+ <th scope="row"><label for="expired-post-status">Set Post To -></label></th>
291
  <td>
292
  <select name="expired-post-status" id="expired-post-status">
293
  <option<?php if ($expirationdateExpiredPostStatus == 'Draft'){ echo ' selected="selected"';}?>>Draft</option>
298
  </td>
299
  </tr>
300
  <tr valign-"top">
301
+ <th scope="row"><label for="expired-page-status">Set Page To -></label></th>
302
  <td>
303
  <select name="expired-page-status" id="expired-page-status">
304
  <option<?php if ($expirationdateExpiredPageStatus == 'Draft'){ echo ' selected="selected"';}?>>Draft</option>
308
  Select whether the page should be deleted or changed to a draft at expiration time.
309
  </td>
310
  </tr>
 
 
 
 
 
 
 
 
 
311
  </table>
312
  <p class="submit">
313
  <input type="submit" name="expirationdateSave" value="Save" />
317
  <?php
318
  }
319
 
320
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -9,14 +9,12 @@ Allows you to add an expiration date (hourly) to posts which you can configure t
9
 
10
  == Description ==
11
 
12
- The Post Expirator plugin allows the user to set expiration dates for both posts and pages. There is a configuration option page in the plugins
13
- area that will allow you to seperataly control whether or not posts/pages are wither deleted or changed to draft status.
 
14
 
15
  The plugin hooks into the wp cron processes and runs every hour.
16
 
17
- The expiration date can be displayed within the actual post by using the [postexpirator] tag. The format attribute will override the plugin
18
- default display format. See the [PHP Date Function](http://us2.php.net/manual/en/function.date.php) for valid format options.
19
-
20
  == Wordpress MU ==
21
 
22
  This plugin is compataibile with Wordpress MU 1.5+, however currently it will not work in the mu-plugins folder due to the plugin activation
@@ -24,7 +22,7 @@ functions.
24
 
25
  == Credits ==
26
 
27
- Plugin is based on the orginial [Expiration Date](http://www.hostscope.com/wordpress-plugins/the-expirationdate-wordpress-plugin/) plugin by jrrl.
28
 
29
  == Installation ==
30
 
@@ -33,20 +31,3 @@ This section describes how to install the plugin and get it working.
33
  1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
34
  2. Activate the plugin through the 'Plugins' menu in WordPress
35
 
36
- == Changelog ==
37
-
38
- **Version 1.2**
39
-
40
- * Changed wording from "Expiration Date" to "Post Expirator" and moved the configuration options to the "Settings" tab.
41
- * Added shortcode tag [postexpirator] to display the post expiration date within the post
42
- * Added new setting for the default date display format
43
- * Fixed bug where expiration date was removed when a post was auto saved
44
-
45
- **Version 1.1**
46
-
47
- * Expired posts retain expiration date
48
-
49
- **Version 1.0**
50
-
51
- * Initial Release
52
-
9
 
10
  == Description ==
11
 
12
+ The Post Expirator plugin allows the user to set expiration dates for both posts and pages. There is a configuration option
13
+ page in the plugins area that will allow you to separately control whether or not posts/pages are either deleted or changed to
14
+ draft status.
15
 
16
  The plugin hooks into the wp cron processes and runs every hour.
17
 
 
 
 
18
  == Wordpress MU ==
19
 
20
  This plugin is compataibile with Wordpress MU 1.5+, however currently it will not work in the mu-plugins folder due to the plugin activation
22
 
23
  == Credits ==
24
 
25
+ Plugin concept is based on the orginial [Expiration Date](http://www.hostscope.com/wordpress-plugins/the-expirationdate-wordpress-plugin/) plugin by jrrl.
26
 
27
  == Installation ==
28
 
31
  1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
32
  2. Activate the plugin through the 'Plugins' menu in WordPress
33