Version Description
Download this release
Release Info
Developer | axelseaa |
Plugin | Post Expirator |
Version | 2.1.0 |
Comparing to | |
See all releases |
Code changes from version 2.0.1 to 2.1.0
- post-expirator.php +162 -60
- readme.txt +10 -1
- style.css +5 -0
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: 2.0
|
8 |
Author URI: http://postexpirator.tuxdocs.net/
|
9 |
Translation: Thierry (http://palijn.info)
|
10 |
Text Domain: post-expirator
|
@@ -18,7 +18,7 @@ function postExpirator_init() {
|
|
18 |
add_action('plugins_loaded', 'postExpirator_init');
|
19 |
|
20 |
// Default Values
|
21 |
-
define('POSTEXPIRATOR_VERSION','2.0
|
22 |
define('POSTEXPIRATOR_DATEFORMAT',__('l F jS, Y','post-expirator'));
|
23 |
define('POSTEXPIRATOR_TIMEFORMAT',__('g:ia','post-expirator'));
|
24 |
define('POSTEXPIRATOR_FOOTERCONTENTS',__('Post expires at EXPIRATIONTIME on EXPIRATIONDATE','post-expirator'));
|
@@ -62,7 +62,7 @@ function expirationdate_show_value ($column_name) {
|
|
62 |
$id = $post->ID;
|
63 |
if ($column_name === 'expirationdate') {
|
64 |
$ed = get_post_meta($id,'_expiration-date',true);
|
65 |
-
echo ($ed ? postexpirator_get_date_from_gmt(
|
66 |
}
|
67 |
}
|
68 |
add_action ('manage_posts_custom_column', 'expirationdate_show_value');
|
@@ -89,9 +89,8 @@ function expirationdate_meta_box($post) {
|
|
89 |
$firstsave = get_post_meta($post->ID,'_expiration-date-status',true);
|
90 |
$default = '';
|
91 |
$expireType = '';
|
|
|
92 |
if (empty($expirationdatets)) {
|
93 |
-
$defaults = get_option('expirationdateDefaults'.ucfirst($post->post_type));
|
94 |
-
|
95 |
$default = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
|
96 |
if ($default == 'null') {
|
97 |
$defaultmonth = date_i18n('m');
|
@@ -111,11 +110,11 @@ function expirationdate_meta_box($post) {
|
|
111 |
|
112 |
if ( $tz ) date_default_timezone_set('UTC');
|
113 |
}
|
114 |
-
$defaultmonth = postexpirator_get_date_from_gmt(
|
115 |
-
$defaultday = postexpirator_get_date_from_gmt(
|
116 |
-
$defaultyear = postexpirator_get_date_from_gmt(
|
117 |
-
$defaulthour = postexpirator_get_date_from_gmt(
|
118 |
-
$defaultminute = postexpirator_get_date_from_gmt(
|
119 |
}
|
120 |
|
121 |
$enabled = '';
|
@@ -131,11 +130,11 @@ function expirationdate_meta_box($post) {
|
|
131 |
$disabled='';
|
132 |
}
|
133 |
} else {
|
134 |
-
$defaultmonth = postexpirator_get_date_from_gmt(
|
135 |
-
$defaultday = postexpirator_get_date_from_gmt(
|
136 |
-
$defaultyear = postexpirator_get_date_from_gmt(
|
137 |
-
$defaulthour = postexpirator_get_date_from_gmt(
|
138 |
-
$defaultminute = postexpirator_get_date_from_gmt(
|
139 |
$enabled = ' checked="checked"';
|
140 |
$disabled = '';
|
141 |
$opts = get_post_meta($post->ID,'_expiration-date-options',true);
|
@@ -209,7 +208,7 @@ function expirationdate_meta_box($post) {
|
|
209 |
echo implode("\n",$rv);
|
210 |
|
211 |
echo '<br/>'.__('How to expire','post-expirator').': ';
|
212 |
-
echo _postExpiratorExpireType(array('name'=>'expirationdate_expiretype','selected'=>$expireType,'disabled'=>$disabled,'onchange' => 'expirationdate_toggle_category(this)'));
|
213 |
echo '<br/>';
|
214 |
|
215 |
if ($post->post_type != 'page') {
|
@@ -225,9 +224,21 @@ function expirationdate_meta_box($post) {
|
|
225 |
echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
|
226 |
$walker = new Walker_PostExpirator_Category_Checklist();
|
227 |
if (!empty($disabled)) $walker->setDisabled();
|
228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
echo '</ul>';
|
230 |
echo '</div>';
|
|
|
|
|
231 |
echo '</div>';
|
232 |
}
|
233 |
echo '<div id="expirationdate_ajax_result"></div>';
|
@@ -357,6 +368,7 @@ function expirationdate_update_post_meta($id) {
|
|
357 |
if (isset($category) && !empty($category)) {
|
358 |
if (!empty($category)) {
|
359 |
$opts['category'] = $category;
|
|
|
360 |
}
|
361 |
}
|
362 |
}
|
@@ -459,13 +471,26 @@ function postExpiratorExpire($id) {
|
|
459 |
}
|
460 |
} elseif ($expireType == 'category') {
|
461 |
if (!empty($category)) {
|
462 |
-
if (
|
463 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
} else {
|
465 |
-
|
466 |
-
|
467 |
-
$debug->save(array('message' => $id.' ->
|
468 |
-
|
|
|
|
|
|
|
|
|
|
|
469 |
}
|
470 |
}
|
471 |
} else {
|
@@ -473,38 +498,71 @@ function postExpiratorExpire($id) {
|
|
473 |
}
|
474 |
} elseif ($expireType == 'category-add') {
|
475 |
if (!empty($category)) {
|
476 |
-
$
|
477 |
-
|
478 |
-
|
479 |
-
if (
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
|
|
|
|
485 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
}
|
487 |
} else {
|
488 |
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
|
489 |
}
|
490 |
} elseif ($expireType == 'category-remove') {
|
491 |
if (!empty($category)) {
|
492 |
-
$
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
if (wp_update_post(array('ID' => $id, 'post_category' => $merged)) == 0) {
|
500 |
-
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
|
501 |
-
} else {
|
502 |
-
if (POSTEXPIRATOR_DEBUG) {
|
503 |
-
$debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
|
504 |
-
$debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
|
505 |
-
$debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($merged),true)));
|
506 |
}
|
507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
508 |
} else {
|
509 |
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
|
510 |
}
|
@@ -712,7 +770,7 @@ function postExpiratorMenuGeneral() {
|
|
712 |
|
713 |
function postExpiratorMenuDefaults() {
|
714 |
$debug = postExpiratorDebug();
|
715 |
-
$types = get_post_types(array('_builtin' => false));
|
716 |
array_unshift($types,'post','page');
|
717 |
|
718 |
if (isset($_POST['expirationdateSaveDefaults'])) {
|
@@ -724,6 +782,9 @@ function postExpiratorMenuDefaults() {
|
|
724 |
if (isset($_POST['expirationdate_autoenable-'.$type])) {
|
725 |
$defaults[$type]['autoEnable'] = intval($_POST['expirationdate_autoenable-'.$type]);
|
726 |
}
|
|
|
|
|
|
|
727 |
|
728 |
//Save Settings
|
729 |
update_option('expirationdateDefaults'.ucfirst($type),$defaults[$type]);
|
@@ -734,7 +795,7 @@ function postExpiratorMenuDefaults() {
|
|
734 |
<form method="post">
|
735 |
<h3><?php _e('Default Expiration Values','post-expirator');?></h3>
|
736 |
<p>
|
737 |
-
<?php _e('Use the values below to set the default actions/values to be used for each for the corresponding post types. These values can all be
|
738 |
</p>
|
739 |
<?php
|
740 |
foreach ($types as $type) {
|
@@ -767,6 +828,15 @@ function postExpiratorMenuDefaults() {
|
|
767 |
<?php _e('Select whether the post expirator is enabled for all new posts.','post-expirator');?>
|
768 |
</td>
|
769 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
770 |
</table>
|
771 |
<?php
|
772 |
}
|
@@ -911,7 +981,7 @@ function postexpirator_shortcode($atts) {
|
|
911 |
else if ($type == 'time')
|
912 |
$format = $timeformat;
|
913 |
|
914 |
-
return postexpirator_get_date_from_gmt(
|
915 |
}
|
916 |
add_shortcode('postexpirator', 'postexpirator_shortcode');
|
917 |
|
@@ -938,9 +1008,9 @@ function postexpirator_add_footer($text) {
|
|
938 |
'EXPIRATIONTIME'
|
939 |
);
|
940 |
$replace = array(
|
941 |
-
postexpirator_get_date_from_gmt(
|
942 |
-
postexpirator_get_date_from_gmt(
|
943 |
-
postexpirator_get_date_from_gmt(
|
944 |
);
|
945 |
|
946 |
$add_to_footer = '<p style="'.$expirationdateFooterStyle.'">'.str_replace($search,$replace,$expirationdateFooterContents).'</p>';
|
@@ -954,11 +1024,11 @@ add_action('the_content','postexpirator_add_footer',0);
|
|
954 |
function postExpiratorDebug() {
|
955 |
$debug = get_option('expirationdateDebug');
|
956 |
if ($debug == 1) {
|
957 |
-
define('POSTEXPIRATOR_DEBUG',1);
|
958 |
require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php'); // Load Class
|
959 |
return new postExpiratorDebug();
|
960 |
} else {
|
961 |
-
define('POSTEXPIRATOR_DEBUG',0);
|
962 |
return false;
|
963 |
}
|
964 |
}
|
@@ -1048,6 +1118,11 @@ function postexpirator_upgrade() {
|
|
1048 |
|
1049 |
update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
|
1050 |
}
|
|
|
|
|
|
|
|
|
|
|
1051 |
}
|
1052 |
}
|
1053 |
add_action('admin_init','postexpirator_upgrade');
|
@@ -1140,18 +1215,45 @@ function _postExpiratorExpireType($opts) {
|
|
1140 |
extract($opts);
|
1141 |
if (!isset($name)) return false;
|
1142 |
if (!isset($id)) $id = $name;
|
1143 |
-
if (!isset($disabled)) $disabled =
|
1144 |
if (!isset($onchange)) $onchange = '';
|
1145 |
if (!isset($type)) $type = '';
|
1146 |
|
1147 |
$rv = array();
|
1148 |
-
$rv[] = '<select name="'.$name.'" id="'.$id.'"'
|
1149 |
$rv[] = '<option value="draft" '. ($selected == 'draft' ? 'selected="selected"' : '') . '>'.__('Draft','post-expirator').'</option>';
|
1150 |
$rv[] = '<option value="delete" '. ($selected == 'delete' ? 'selected="selected"' : '') . '>'.__('Delete','post-expirator').'</option>';
|
1151 |
$rv[] = '<option value="private" '. ($selected == 'private' ? 'selected="selected"' : '') . '>'.__('Private','post-expirator').'</option>';
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1155 |
$rv[] = '</select>';
|
1156 |
return implode("<br/>/n",$rv);
|
1157 |
}
|
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: 2.1.0
|
8 |
Author URI: http://postexpirator.tuxdocs.net/
|
9 |
Translation: Thierry (http://palijn.info)
|
10 |
Text Domain: post-expirator
|
18 |
add_action('plugins_loaded', 'postExpirator_init');
|
19 |
|
20 |
// Default Values
|
21 |
+
define('POSTEXPIRATOR_VERSION','2.1.0');
|
22 |
define('POSTEXPIRATOR_DATEFORMAT',__('l F jS, Y','post-expirator'));
|
23 |
define('POSTEXPIRATOR_TIMEFORMAT',__('g:ia','post-expirator'));
|
24 |
define('POSTEXPIRATOR_FOOTERCONTENTS',__('Post expires at EXPIRATIONTIME on EXPIRATIONDATE','post-expirator'));
|
62 |
$id = $post->ID;
|
63 |
if ($column_name === 'expirationdate') {
|
64 |
$ed = get_post_meta($id,'_expiration-date',true);
|
65 |
+
echo ($ed ? postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),get_option('date_format').' '.get_option('time_format')) : __("Never",'post-expirator'));
|
66 |
}
|
67 |
}
|
68 |
add_action ('manage_posts_custom_column', 'expirationdate_show_value');
|
89 |
$firstsave = get_post_meta($post->ID,'_expiration-date-status',true);
|
90 |
$default = '';
|
91 |
$expireType = '';
|
92 |
+
$defaults = get_option('expirationdateDefaults'.ucfirst($post->post_type));
|
93 |
if (empty($expirationdatets)) {
|
|
|
|
|
94 |
$default = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
|
95 |
if ($default == 'null') {
|
96 |
$defaultmonth = date_i18n('m');
|
110 |
|
111 |
if ( $tz ) date_default_timezone_set('UTC');
|
112 |
}
|
113 |
+
$defaultmonth = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'m');
|
114 |
+
$defaultday = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'d');
|
115 |
+
$defaultyear = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'Y');;
|
116 |
+
$defaulthour = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'H');
|
117 |
+
$defaultminute = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'i');
|
118 |
}
|
119 |
|
120 |
$enabled = '';
|
130 |
$disabled='';
|
131 |
}
|
132 |
} else {
|
133 |
+
$defaultmonth = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'m');
|
134 |
+
$defaultday = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'d');
|
135 |
+
$defaultyear = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'Y');
|
136 |
+
$defaulthour = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'H');
|
137 |
+
$defaultminute = postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'i');
|
138 |
$enabled = ' checked="checked"';
|
139 |
$disabled = '';
|
140 |
$opts = get_post_meta($post->ID,'_expiration-date-options',true);
|
208 |
echo implode("\n",$rv);
|
209 |
|
210 |
echo '<br/>'.__('How to expire','post-expirator').': ';
|
211 |
+
echo _postExpiratorExpireType(array('type' => $post->post_type, 'name'=>'expirationdate_expiretype','selected'=>$expireType,'disabled'=>$disabled,'onchange' => 'expirationdate_toggle_category(this)'));
|
212 |
echo '<br/>';
|
213 |
|
214 |
if ($post->post_type != 'page') {
|
224 |
echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
|
225 |
$walker = new Walker_PostExpirator_Category_Checklist();
|
226 |
if (!empty($disabled)) $walker->setDisabled();
|
227 |
+
$taxonomies = get_object_taxonomies($post->post_type,'object');
|
228 |
+
$taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true));
|
229 |
+
if (sizeof($taxonomies) == 0) {
|
230 |
+
echo '<p>'.__('You must assign a heirarchical taxonomy to this post type to use this feature.','post-expirator').'</p>';
|
231 |
+
} elseif (sizeof($taxonomies) > 1 && !isset($defaults['taxonomy'])) {
|
232 |
+
echo '<p>'.__('More than 1 heirachical taxonomy detected. You must assign a default taxonomy on the settings screen.','post-expirator').'</p>';
|
233 |
+
} else {
|
234 |
+
$taxonomy = isset($defaults['taxonomy']) ? $defaults['taxonomy'] : $taxonomies[0];
|
235 |
+
wp_terms_checklist(0, array( 'taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
|
236 |
+
echo '<input type="hidden" name="taxonomy-heirarchical" value="'.$taxonomy.'" />';
|
237 |
+
}
|
238 |
echo '</ul>';
|
239 |
echo '</div>';
|
240 |
+
if (isset($taxonomy))
|
241 |
+
echo '<p class="post-expirator-taxonomy-name">'.__('Taxonomy Name','post-expirator').': '.$taxonomy.'</p>';
|
242 |
echo '</div>';
|
243 |
}
|
244 |
echo '<div id="expirationdate_ajax_result"></div>';
|
368 |
if (isset($category) && !empty($category)) {
|
369 |
if (!empty($category)) {
|
370 |
$opts['category'] = $category;
|
371 |
+
$opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical'];
|
372 |
}
|
373 |
}
|
374 |
}
|
471 |
}
|
472 |
} elseif ($expireType == 'category') {
|
473 |
if (!empty($category)) {
|
474 |
+
if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
|
475 |
+
if (wp_update_post(array('ID' => $id, 'post_category' => $category)) == 0) {
|
476 |
+
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
|
477 |
+
} else {
|
478 |
+
if (POSTEXPIRATOR_DEBUG) {
|
479 |
+
$debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
|
480 |
+
$debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
|
481 |
+
$debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
|
482 |
+
}
|
483 |
+
}
|
484 |
} else {
|
485 |
+
$terms = array_map('intval', $category);
|
486 |
+
if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,false))) {
|
487 |
+
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
|
488 |
+
} else {
|
489 |
+
if (POSTEXPIRATOR_DEBUG) {
|
490 |
+
$debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
|
491 |
+
$debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
|
492 |
+
$debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
|
493 |
+
}
|
494 |
}
|
495 |
}
|
496 |
} else {
|
498 |
}
|
499 |
} elseif ($expireType == 'category-add') {
|
500 |
if (!empty($category)) {
|
501 |
+
if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
|
502 |
+
$cats = wp_get_post_categories($id);
|
503 |
+
$merged = array_merge($cats,$category);
|
504 |
+
if (wp_update_post(array('ID' => $id, 'post_category' => $merged)) == 0) {
|
505 |
+
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
|
506 |
+
} else {
|
507 |
+
if (POSTEXPIRATOR_DEBUG) {
|
508 |
+
$debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
|
509 |
+
$debug->save(array('message' => $id.' -> CATEGORIES ADDED '.print_r(_postExpiratorGetCatNames($category),true)));
|
510 |
+
$debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($merged),true)));
|
511 |
+
}
|
512 |
}
|
513 |
+
} else {
|
514 |
+
$terms = array_map('intval', $category);
|
515 |
+
if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,true))) {
|
516 |
+
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
|
517 |
+
} else {
|
518 |
+
if (POSTEXPIRATOR_DEBUG) {
|
519 |
+
$debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
|
520 |
+
$debug->save(array('message' => $id.' -> CATEGORIES ADDED '.print_r(_postExpiratorGetCatNames($category),true)));
|
521 |
+
$debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
|
522 |
+
}
|
523 |
+
}
|
524 |
}
|
525 |
} else {
|
526 |
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
|
527 |
}
|
528 |
} elseif ($expireType == 'category-remove') {
|
529 |
if (!empty($category)) {
|
530 |
+
if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
|
531 |
+
$cats = wp_get_post_categories($id);
|
532 |
+
$merged = array();
|
533 |
+
foreach ($cats as $cat) {
|
534 |
+
if (!in_array($cat,$category)) {
|
535 |
+
$merged[] = $cat;
|
536 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
537 |
}
|
538 |
+
if (wp_update_post(array('ID' => $id, 'post_category' => $merged)) == 0) {
|
539 |
+
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
|
540 |
+
} else {
|
541 |
+
if (POSTEXPIRATOR_DEBUG) {
|
542 |
+
$debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
|
543 |
+
$debug->save(array('message' => $id.' -> CATEGORIES REMOVED '.print_r(_postExpiratorGetCatNames($category),true)));
|
544 |
+
$debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($merged),true)));
|
545 |
+
}
|
546 |
+
}
|
547 |
+
} else {
|
548 |
+
$terms = wp_get_object_terms($id, $categoryTaxonomy, array('fields' => 'ids'));
|
549 |
+
$merged = array();
|
550 |
+
foreach ($terms as $term) {
|
551 |
+
if (!in_array($term,$category)) {
|
552 |
+
$merged[] = $term;
|
553 |
+
}
|
554 |
+
}
|
555 |
+
$terms = array_map('intval', $merged);
|
556 |
+
if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,false))) {
|
557 |
+
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
|
558 |
+
} else {
|
559 |
+
if (POSTEXPIRATOR_DEBUG) {
|
560 |
+
$debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
|
561 |
+
$debug->save(array('message' => $id.' -> CATEGORIES REMOVED '.print_r(_postExpiratorGetCatNames($category),true)));
|
562 |
+
$debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
|
563 |
+
}
|
564 |
+
}
|
565 |
+
}
|
566 |
} else {
|
567 |
if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
|
568 |
}
|
770 |
|
771 |
function postExpiratorMenuDefaults() {
|
772 |
$debug = postExpiratorDebug();
|
773 |
+
$types = get_post_types(array('public' => true, '_builtin' => false));
|
774 |
array_unshift($types,'post','page');
|
775 |
|
776 |
if (isset($_POST['expirationdateSaveDefaults'])) {
|
782 |
if (isset($_POST['expirationdate_autoenable-'.$type])) {
|
783 |
$defaults[$type]['autoEnable'] = intval($_POST['expirationdate_autoenable-'.$type]);
|
784 |
}
|
785 |
+
if (isset($_POST['expirationdate_taxonomy-'.$type])) {
|
786 |
+
$defaults[$type]['taxonomy'] = $_POST['expirationdate_taxonomy-'.$type];
|
787 |
+
}
|
788 |
|
789 |
//Save Settings
|
790 |
update_option('expirationdateDefaults'.ucfirst($type),$defaults[$type]);
|
795 |
<form method="post">
|
796 |
<h3><?php _e('Default Expiration Values','post-expirator');?></h3>
|
797 |
<p>
|
798 |
+
<?php _e('Use the values below to set the default actions/values to be used for each for the corresponding post types. These values can all be overwritten when creating/editing the post/page.','post-expirator'); ?>
|
799 |
</p>
|
800 |
<?php
|
801 |
foreach ($types as $type) {
|
828 |
<?php _e('Select whether the post expirator is enabled for all new posts.','post-expirator');?>
|
829 |
</td>
|
830 |
</tr>
|
831 |
+
<tr valign-"top">
|
832 |
+
<th scope="row"><label for="expirationdate_taxonomy-<?php echo $type ?>"><?php _e('Taxonomy (hierarchical):','post-expirator'); ?></label></th>
|
833 |
+
<td>
|
834 |
+
<?php echo _postExpiratorTaxonomy(array('type' => $type, 'name'=>'expirationdate_taxonomy-'.$type,'selected' => $defaults['taxonomy'])); ?>
|
835 |
+
</select>
|
836 |
+
<br/>
|
837 |
+
<?php _e('Select the hierarchical taxonomy to be used for "category" based expiration.','post-expirator');?>
|
838 |
+
</td>
|
839 |
+
</tr>
|
840 |
</table>
|
841 |
<?php
|
842 |
}
|
981 |
else if ($type == 'time')
|
982 |
$format = $timeformat;
|
983 |
|
984 |
+
return postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$format);
|
985 |
}
|
986 |
add_shortcode('postexpirator', 'postexpirator_shortcode');
|
987 |
|
1008 |
'EXPIRATIONTIME'
|
1009 |
);
|
1010 |
$replace = array(
|
1011 |
+
postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),"$dateformat $timeformat"),
|
1012 |
+
postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$dateformat),
|
1013 |
+
postexpirator_get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$timeformat)
|
1014 |
);
|
1015 |
|
1016 |
$add_to_footer = '<p style="'.$expirationdateFooterStyle.'">'.str_replace($search,$replace,$expirationdateFooterContents).'</p>';
|
1024 |
function postExpiratorDebug() {
|
1025 |
$debug = get_option('expirationdateDebug');
|
1026 |
if ($debug == 1) {
|
1027 |
+
if (!defined('POSTEXPIRATOR_DEBUG')) define('POSTEXPIRATOR_DEBUG',1);
|
1028 |
require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php'); // Load Class
|
1029 |
return new postExpiratorDebug();
|
1030 |
} else {
|
1031 |
+
if (!defined('POSTEXPIRATOR_DEBUG')) define('POSTEXPIRATOR_DEBUG',0);
|
1032 |
return false;
|
1033 |
}
|
1034 |
}
|
1118 |
|
1119 |
update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
|
1120 |
}
|
1121 |
+
|
1122 |
+
if (version_compare($version,'2.1.0') == -1) {
|
1123 |
+
|
1124 |
+
update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
|
1125 |
+
}
|
1126 |
}
|
1127 |
}
|
1128 |
add_action('admin_init','postexpirator_upgrade');
|
1215 |
extract($opts);
|
1216 |
if (!isset($name)) return false;
|
1217 |
if (!isset($id)) $id = $name;
|
1218 |
+
if (!isset($disabled)) $disabled = false;
|
1219 |
if (!isset($onchange)) $onchange = '';
|
1220 |
if (!isset($type)) $type = '';
|
1221 |
|
1222 |
$rv = array();
|
1223 |
+
$rv[] = '<select name="'.$name.'" id="'.$id.'"'.($disabled == true ? ' disabled="disabled"' : '').' onchange="'.$onchange.'">';
|
1224 |
$rv[] = '<option value="draft" '. ($selected == 'draft' ? 'selected="selected"' : '') . '>'.__('Draft','post-expirator').'</option>';
|
1225 |
$rv[] = '<option value="delete" '. ($selected == 'delete' ? 'selected="selected"' : '') . '>'.__('Delete','post-expirator').'</option>';
|
1226 |
$rv[] = '<option value="private" '. ($selected == 'private' ? 'selected="selected"' : '') . '>'.__('Private','post-expirator').'</option>';
|
1227 |
+
if ($type != 'page') {
|
1228 |
+
$rv[] = '<option value="category" '. ($selected == 'category' ? 'selected="selected"' : '') . '>'.__('Category: Replace','post-expirator').'</option>';
|
1229 |
+
$rv[] = '<option value="category-add" '. ($selected == 'category-add' ? 'selected="selected"' : '') . '>'.__('Category: Add','post-expirator').'</option>';
|
1230 |
+
$rv[] = '<option value="category-remove" '. ($selected == 'category-remove' ? 'selected="selected"' : '') . '>'.__('Category: Remove','post-expirator').'</option>';
|
1231 |
+
}
|
1232 |
+
$rv[] = '</select>';
|
1233 |
+
return implode("<br/>/n",$rv);
|
1234 |
+
}
|
1235 |
+
|
1236 |
+
function _postExpiratorTaxonomy($opts) {
|
1237 |
+
if (empty($opts)) return false;
|
1238 |
+
|
1239 |
+
extract($opts);
|
1240 |
+
if (!isset($name)) return false;
|
1241 |
+
if (!isset($id)) $id = $name;
|
1242 |
+
if (!isset($disabled)) $disabled = false;
|
1243 |
+
if (!isset($onchange)) $onchange = '';
|
1244 |
+
if (!isset($type)) $type = '';
|
1245 |
+
|
1246 |
+
$taxonomies = get_object_taxonomies($type,'object');
|
1247 |
+
$taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true));
|
1248 |
+
|
1249 |
+
if (empty($taxonomies)) $disabled = true;
|
1250 |
+
|
1251 |
+
$rv = array();
|
1252 |
+
$rv[] = '<select name="'.$name.'" id="'.$id.'"'.($disabled == true ? ' disabled="disabled"' : '').' onchange="'.$onchange.'">';
|
1253 |
+
foreach ($taxonomies as $taxonomy) {
|
1254 |
+
$rv[] = '<option value="'.$taxonomy->name.'" '. ($selected == $taxonomy->name ? 'selected="selected"' : '') . '>'.$taxonomy->name.'</option>';
|
1255 |
+
}
|
1256 |
+
|
1257 |
$rv[] = '</select>';
|
1258 |
return implode("<br/>/n",$rv);
|
1259 |
}
|
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.5.1
|
6 |
-
Stable tag: 2.0
|
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,15 @@ This section describes how to install the plugin and get it working.
|
|
47 |
|
48 |
== Changelog ==
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
**Version 2.0.1**
|
51 |
|
52 |
* Removes old scheduled hook - this was not done completely in the 2.0.0 upgrade
|
3 |
Tags: expire, posts, pages, schedule
|
4 |
Requires at least: 3.2
|
5 |
Tested up to: 3.5.1
|
6 |
+
Stable tag: 2.1.0
|
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 2.1.0**
|
51 |
+
|
52 |
+
* New: Added support for heirarchical custom taxonomy
|
53 |
+
* New: Enhanced custom post type support
|
54 |
+
* Fix: Updated debug function to be friendly for scripted calls
|
55 |
+
* Fix: Change to only show public custom post types on defaults screen
|
56 |
+
* Fix: Removed category expiration options for 'pages', which is currently unsupported
|
57 |
+
* Fix: Some date calls were getting "double" converted for the timezone pending how other plugins handled date - this issue should now be resolved
|
58 |
+
|
59 |
**Version 2.0.1**
|
60 |
|
61 |
* Removes old scheduled hook - this was not done completely in the 2.0.0 upgrade
|
style.css
CHANGED
@@ -21,3 +21,8 @@
|
|
21 |
.post-expirator-timestamp {
|
22 |
width: 150px;
|
23 |
}
|
|
|
|
|
|
|
|
|
|
21 |
.post-expirator-timestamp {
|
22 |
width: 150px;
|
23 |
}
|
24 |
+
.post-expirator-taxonomy-name {
|
25 |
+
margin: 0px;
|
26 |
+
font-style: italic;
|
27 |
+
font-size: x-small;
|
28 |
+
}
|