Post Expirator - Version 1.2.1

Version Description

Download this release

Release Info

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

Code changes from version 1.1 to 1.2.1

Files changed (2) hide show
  1. post-expirator.php +51 -11
  2. readme.txt +18 -5
post-expirator.php CHANGED
@@ -4,17 +4,19 @@ 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.1
8
Author URI: http://www.frozenpc.net
9
*/
10
11
12
/**
13
* Function that does the actualy deleting - called by wp_cron
14
*/
15
function expirationdate_delete_expired_posts() {
16
global $wpdb;
17
- $result = $wpdb->get_results('select post_id, meta_value from ' . $wpdb->postmeta . ' where meta_key = "expiration-date" AND meta_value < "' . mktime() . '"');
18
foreach ($result as $a) {
19
$post_result = $wpdb->get_var('select post_type from ' . $wpdb->posts .' where ID = '. $a->post_id);
20
if ($post_result == 'post') {
@@ -40,9 +42,10 @@ add_action ('expirationdate_delete_'.$current_blog->blog_id, 'expirationdate_del
40
* Called at plugin activation
41
*/
42
function expirationdate_activate () {
43
- global $current_blog;
44
update_option('expirationdateExpiredPostStatus','Draft');
45
update_option('expirationdateExpiredPageStatus','Draft');
46
wp_schedule_event(mktime(date('H'),0,0,date('m'),date('d'),date('Y')), 'hourly', 'expirationdate_delete_'.$current_blog->blog_id);
47
}
48
register_activation_hook (__FILE__, 'expirationdate_activate');
@@ -54,6 +57,7 @@ function expirationdate_deactivate () {
54
global $current_blog;
55
delete_option('expirationdateExpiredPostStatus');
56
delete_option('expirationdateExpiredPageStatus');
57
wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
58
}
59
register_deactivation_hook (__FILE__, 'expirationdate_deactivate');
@@ -87,7 +91,7 @@ add_action ('manage_pages_custom_column', 'expirationdate_show_value');
87
* Add's hooks to get the meta box added to post
88
*/
89
function expirationdate_meta_post() {
90
- add_meta_box('expirationdatediv', __('Expiration Date'), 'expirationdate_meta_box', 'post', 'advanced', 'high');
91
}
92
add_action ('dbx_post_advanced','expirationdate_meta_post');
93
@@ -95,7 +99,7 @@ add_action ('dbx_post_advanced','expirationdate_meta_post');
95
* Add's hooks to get the meta box added to page
96
*/
97
function expirationdate_meta_page() {
98
- add_meta_box('expirationdatediv', __('Expiration Date'), 'expirationdate_meta_box', 'page', 'advanced', 'high');
99
}
100
add_action ('edit_page_form','expirationdate_meta_page');
101
@@ -236,6 +240,9 @@ function expirationdate_get_blog_url() {
236
* Called when post is saved - stores expiration-date meta value
237
*/
238
function expirationdate_update_post_meta($id) {
239
$month = $_POST['expirationdate_month'];
240
$day = $_POST['expirationdate_day'];
241
$year = $_POST['expirationdate_year'];
@@ -257,7 +264,7 @@ add_action('save_post','expirationdate_update_post_meta');
257
* Hook's to add plugin page menu
258
*/
259
function expirationdate_plugin_menu() {
260
- add_submenu_page('plugins.php','Expiration Date Options','Expiration Date',9,basename(__FILE__),'expirationdate_show_options');
261
}
262
add_action('admin_menu', 'expirationdate_plugin_menu');
263
@@ -269,6 +276,7 @@ function expirationdate_show_options() {
269
if ($_POST['expirationdateSave']) {
270
update_option('expirationdateExpiredPostStatus',$_POST['expired-post-status']);
271
update_option('expirationdateExpiredPageStatus',$_POST['expired-page-status']);
272
echo "<div id='message' class='updated fade'><p>Saved Options!</p></div>";
273
}
274
@@ -281,17 +289,23 @@ function expirationdate_show_options() {
281
if (empty($expirationdateExpiredPageStatus))
282
$expirationdateExpiredPageStatus = 'Draft';
283
284
?>
285
<div class="wrap">
286
- <h2><?php _e('Expiration Date Options'); ?></h2>
287
<p>
288
- The expiration date plugin sets a custom meta value, and then optionally allows you to select if you want the post
289
changed to a draft status or deleted when it expires.
290
</p>
291
<form method="post" id="expirationdate_save_options">
292
<table class="form-table">
293
<tr valign-"top">
294
- <th scope="row"><label for="expired-post-status">Set Post To -></label></th>
295
<td>
296
<select name="expired-post-status" id="expired-post-status">
297
<option<?php if ($expirationdateExpiredPostStatus == 'Draft'){ echo ' selected="selected"';}?>>Draft</option>
@@ -302,7 +316,7 @@ function expirationdate_show_options() {
302
</td>
303
</tr>
304
<tr valign-"top">
305
- <th scope="row"><label for="expired-page-status">Set Page To -></label></th>
306
<td>
307
<select name="expired-page-status" id="expired-page-status">
308
<option<?php if ($expirationdateExpiredPageStatus == 'Draft'){ echo ' selected="selected"';}?>>Draft</option>
@@ -312,6 +326,15 @@ function expirationdate_show_options() {
312
Select whether the page should be deleted or changed to a draft at expiration time.
313
</td>
314
</tr>
315
</table>
316
<p class="submit">
317
<input type="submit" name="expirationdateSave" value="Save" />
@@ -321,4 +344,21 @@ function expirationdate_show_options() {
321
<?php
322
}
323
324
- ?>
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.1
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') {
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
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
* 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
* 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
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
* 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
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
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
</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
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
<?php
345
}
346
347
+ // [postexpirator format="l F jS, Y g:ia" tz="foo"]
348
+ function postexpirator_shortcode($atts) {
349
+ global $post,$expirationdateDefaultDateFormat;
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');
readme.txt CHANGED
@@ -2,19 +2,21 @@
2
Contributors: axelseaa
3
Tags: expire, posts, pages
4
Requires at least: 2.5
5
- Tested up to: 2.6
6
Stable tag: trunk
7
8
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.
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,7 +24,7 @@ functions.
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
@@ -33,6 +35,17 @@ This section describes how to install the plugin and get it working.
33
34
== Changelog ==
35
36
**Version 1.1**
37
38
* Expired posts retain expiration date
2
Contributors: axelseaa
3
Tags: expire, posts, pages
4
Requires at least: 2.5
5
+ Tested up to: 2.7
6
Stable tag: trunk
7
8
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.
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
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
35
36
== Changelog ==
37
38
+ **Version 1.2.1**
39
+
40
+ * Fixed issue with display date format not being recognized after upgrade
41
+
42
+ **Version 1.2**
43
+
44
+ * Changed wording from "Expiration Date" to "Post Expirator" and moved the configuration options to the "Settings" tab.
45
+ * Added shortcode tag [postexpirator] to display the post expiration date within the post
46
+ ** Added new setting for the default format
47
+ * Fixed bug where expiration date was removed when a post was auto saved
48
+
49
**Version 1.1**
50
51
* Expired posts retain expiration date