Post Expirator - Version 2.4.3

Version Description

Download this release

Release Info

Developer publishpress
Plugin Icon 128x128 Post Expirator
Version 2.4.3
Comparing to
See all releases

Code changes from version 2.4.2 to 2.4.3

admin-edit.js CHANGED
@@ -1,90 +1,102 @@
1
- (function($, config) {
2
-
3
- // we create a copy of the WP inline edit post function
4
- var $wp_inline_edit = inlineEditPost.edit;
5
-
6
- // and then we overwrite the function with our own code
7
- inlineEditPost.edit = function( id ) {
8
-
9
- // "call" the original WP edit function
10
- // we don't want to leave WordPress hanging
11
- $wp_inline_edit.apply( this, arguments );
12
-
13
- // now we take care of our business
14
-
15
- // get the post ID
16
- var $post_id = 0;
17
- if ( typeof( id ) == 'object' ) {
18
- $post_id = parseInt( this.getId( id ) );
19
- }
20
-
21
- if ( $post_id > 0 ) {
22
- // define the edit row
23
- var $edit_row = $( '#edit-' + $post_id );
24
-
25
- // get / set year
26
- var $year = $( '#expirationdate_year-' + $post_id ).text();
27
- $edit_row.find( 'input[name="expirationdate_year"]' ).val( $year );
28
-
29
- // get / set month
30
- var $month = $( '#expirationdate_month-' + $post_id ).text();
31
- $edit_row.find( 'select[name="expirationdate_month"]' ).val( $month );
32
-
33
- // get / set day
34
- var $day = $( '#expirationdate_day-' + $post_id ).text();
35
- $edit_row.find( 'input[name="expirationdate_day"]' ).val( $day );
36
-
37
- // get / set hour
38
- var $hour = $( '#expirationdate_hour-' + $post_id ).text();
39
- $edit_row.find( 'input[name="expirationdate_hour"]' ).val( $hour );
40
-
41
- // get / set minute
42
- var $minute = $( '#expirationdate_minute-' + $post_id ).text();
43
- $edit_row.find( 'input[name="expirationdate_minute"]' ).val( $minute );
44
-
45
- var $enabled = $( '#expirationdate_enabled-' + $post_id ).text();
46
- if ($enabled == "true") {
47
- $edit_row.find( 'input[name="enable-expirationdate"]' ).prop( 'checked', true );
48
- }
49
- }
50
- };
51
-
52
- $( '#bulk_edit' ).on( 'click', function() {
53
-
54
- // define the bulk edit row
55
- var $bulk_row = $( '#bulk-edit' );
56
-
57
- // get the selected post ids that are being edited
58
- var $post_ids = [];
59
- $bulk_row.find( '#bulk-titles' ).children().each( function() {
60
- $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) );
61
- });
62
-
63
- // get the custom fields
64
- var $expirationdate_month = $bulk_row.find( 'select[name="expirationdate_month"]' ).val();
65
- var $expirationdate_day = $bulk_row.find( 'input[name="expirationdate_day"]' ).val();
66
- var $expirationdate_year = $bulk_row.find( 'input[name="expirationdate_year"]' ).val();
67
- var $expirationdate_hour = $bulk_row.find( 'input[name="expirationdate_hour"]' ).val();
68
- var $expirationdate_minute = $bulk_row.find( 'input[name="expirationdate_minute"]' ).val();
69
-
70
- // save the data
71
- $.ajax({
72
- url: ajaxurl, // this is a variable that WordPress has already defined for us
73
- type: 'POST',
74
- async: false,
75
- cache: false,
76
- data: {
77
- action: config.ajax.bulk_edit,
78
- post_ids: $post_ids, // and these are the 2 parameters we're passing to our function
79
- expirationdate_month: $expirationdate_month,
80
- expirationdate_day: $expirationdate_day,
81
- expirationdate_year: $expirationdate_year,
82
- expirationdate_hour: $expirationdate_hour,
83
- expirationdate_minute: $expirationdate_minute,
84
- nonce: config.ajax.nonce
85
- }
86
- });
87
-
88
- });
89
-
90
- })(jQuery, config);
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function($, config) {
2
+
3
+ // show/hide the date fields when the user chooses the intent.
4
+ $('body').on('change', 'select[name="expirationdate_status"]', function(e){
5
+ var $show = $(this).find('option:selected').attr('data-show-fields');
6
+ if($show === 'true'){
7
+ $(this).parents('.timestamp-wrap').find('span.post-expirator-date-fields').show();
8
+ }else{
9
+ $(this).parents('.timestamp-wrap').find('span.post-expirator-date-fields').hide();
10
+ }
11
+ });
12
+
13
+ // we create a copy of the WP inline edit post function
14
+ var $wp_inline_edit = inlineEditPost.edit;
15
+
16
+ // and then we overwrite the function with our own code
17
+ inlineEditPost.edit = function( id ) {
18
+
19
+ // "call" the original WP edit function
20
+ // we don't want to leave WordPress hanging
21
+ $wp_inline_edit.apply( this, arguments );
22
+
23
+ // now we take care of our business
24
+
25
+ // get the post ID
26
+ var $post_id = 0;
27
+ if ( typeof( id ) == 'object' ) {
28
+ $post_id = parseInt( this.getId( id ) );
29
+ }
30
+
31
+ if ( $post_id > 0 ) {
32
+ // define the edit row
33
+ var $edit_row = $( '#edit-' + $post_id );
34
+
35
+ // get / set year
36
+ var $year = $( '#expirationdate_year-' + $post_id ).text();
37
+ $edit_row.find( 'input[name="expirationdate_year"]' ).val( $year );
38
+
39
+ // get / set month
40
+ var $month = $( '#expirationdate_month-' + $post_id ).text();
41
+ $edit_row.find( 'select[name="expirationdate_month"]' ).val( $month );
42
+
43
+ // get / set day
44
+ var $day = $( '#expirationdate_day-' + $post_id ).text();
45
+ $edit_row.find( 'input[name="expirationdate_day"]' ).val( $day );
46
+
47
+ // get / set hour
48
+ var $hour = $( '#expirationdate_hour-' + $post_id ).text();
49
+ $edit_row.find( 'input[name="expirationdate_hour"]' ).val( $hour );
50
+
51
+ // get / set minute
52
+ var $minute = $( '#expirationdate_minute-' + $post_id ).text();
53
+ $edit_row.find( 'input[name="expirationdate_minute"]' ).val( $minute );
54
+
55
+ var $enabled = $( '#expirationdate_enabled-' + $post_id ).text();
56
+ if ($enabled == "true") {
57
+ $edit_row.find( 'input[name="enable-expirationdate"]' ).prop( 'checked', true );
58
+ }
59
+ }
60
+ };
61
+
62
+ $( '#bulk_edit' ).on( 'click', function() {
63
+
64
+ // define the bulk edit row
65
+ var $bulk_row = $( '#bulk-edit' );
66
+
67
+ // get the selected post ids that are being edited
68
+ var $post_ids = [];
69
+ $bulk_row.find( '#bulk-titles' ).children().each( function() {
70
+ $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) );
71
+ });
72
+
73
+ // get the custom fields
74
+ var $expirationdate_month = $bulk_row.find( 'select[name="expirationdate_month"]' ).val();
75
+ var $expirationdate_day = $bulk_row.find( 'input[name="expirationdate_day"]' ).val();
76
+ var $expirationdate_year = $bulk_row.find( 'input[name="expirationdate_year"]' ).val();
77
+ var $expirationdate_hour = $bulk_row.find( 'input[name="expirationdate_hour"]' ).val();
78
+ var $expirationdate_minute = $bulk_row.find( 'input[name="expirationdate_minute"]' ).val();
79
+ var $expirationdate_status = $bulk_row.find( 'select[name="expirationdate_status"]' ).val();
80
+
81
+ // save the data
82
+ $.ajax({
83
+ url: ajaxurl, // this is a variable that WordPress has already defined for us
84
+ type: 'POST',
85
+ async: false,
86
+ cache: false,
87
+ data: {
88
+ action: config.ajax.bulk_edit,
89
+ post_ids: $post_ids, // and these are the 2 parameters we're passing to our function
90
+ expirationdate_month: $expirationdate_month,
91
+ expirationdate_day: $expirationdate_day,
92
+ expirationdate_year: $expirationdate_year,
93
+ expirationdate_hour: $expirationdate_hour,
94
+ expirationdate_minute: $expirationdate_minute,
95
+ expirationdate_status: $expirationdate_status,
96
+ nonce: config.ajax.nonce
97
+ }
98
+ });
99
+
100
+ });
101
+
102
+ })(jQuery, config);
assets/css/edit.css ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ div.timestamp-wrap label {
2
+ vertical-align: middle !important;
3
+ }
4
+
5
+ div.timestamp-wrap > span.post-expirator-date-fields {
6
+ display: none;
7
+ }
8
+
9
+ .post-expirator-quickedit input {
10
+ font-size: 12px;
11
+ }
style.css → assets/css/style.css RENAMED
@@ -1,31 +1,34 @@
1
- .post-expirator-adminnotice {
2
- background-color: red;
3
- }
4
- .post-expirator-addcolumn {
5
- font-size: 0.8em;
6
- font-weight: normal;
7
- }
8
- #post-expirator-cat-list {
9
- max-width: 250px;
10
- }
11
- #post-expirator-cat-list ul {
12
- margin: 0;
13
- }
14
- #post-expirator-cat-list ul ul {
15
- margin-left: 18px;
16
- }
17
- .post-expirator-debug th {
18
- font-weight: bold;
19
- border-bottom: 1px solid black;
20
- }
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
- }
29
- .post-expirator-quickedit input {
30
- font-size: 12px;
31
- }
 
 
 
1
+ /* settings */
2
+ .post-expirator-adminnotice {
3
+ background-color: red;
4
+ }
5
+
6
+ .post-expirator-addcolumn {
7
+ font-size: 0.8em;
8
+ font-weight: normal;
9
+ }
10
+
11
+ .post-expirator-debug th {
12
+ font-weight: bold;
13
+ border-bottom: 1px solid black;
14
+ }
15
+
16
+ .post-expirator-timestamp {
17
+ width: 150px;
18
+ }
19
+
20
+ /* metabox */
21
+ #post-expirator-cat-list {
22
+ max-width: 250px;
23
+ }
24
+ #post-expirator-cat-list ul {
25
+ margin: 0;
26
+ }
27
+ #post-expirator-cat-list ul ul {
28
+ margin-left: 18px;
29
+ }
30
+ .post-expirator-taxonomy-name {
31
+ margin: 0px;
32
+ font-style: italic;
33
+ font-size: x-small;
34
+ }
functions.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file provides access to all publicly exposed functions.
4
+ */
5
+
6
+ require_once POSTEXPIRATOR_BASEDIR . '/legacy-functions.php';
7
+
languages/post-expirator.pot CHANGED
@@ -1,560 +1,582 @@
1
- # Copyright (C) 2021 Aaron Axelsen
2
- # This file is distributed under the same license as the Post Expirator package.
3
- msgid ""
4
- msgstr ""
5
- "Project-Id-Version: Post Expirator 2.4.1\n"
6
- "Report-Msgid-Bugs-To: "
7
- "https://wordpress.org/support/plugin/PublishPress-Future\n"
8
- "POT-Creation-Date: 2021-05-23 13:19:49+00:00\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=utf-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "Last-Translator: PostExpirator Translate Team\n"
13
- "Language-Team: PostExpirator Translate Team\n"
14
-
15
- #: post-expirator-debug.php:66
16
- msgid "Debugging table is currently empty."
17
- msgstr ""
18
-
19
- #: post-expirator-debug.php:70
20
- msgid "Timestamp"
21
- msgstr ""
22
-
23
- #: post-expirator-debug.php:71
24
- msgid "Message"
25
- msgstr ""
26
-
27
- #: post-expirator.php:15
28
- msgid "l F jS, Y"
29
- msgstr ""
30
-
31
- #: post-expirator.php:16
32
- msgid "g:ia"
33
- msgstr ""
34
-
35
- #: post-expirator.php:17
36
- msgid "Post expires at EXPIRATIONTIME on EXPIRATIONDATE"
37
- msgstr ""
38
-
39
- #: post-expirator.php:40
40
- msgid "Settings"
41
- msgstr ""
42
-
43
- #: post-expirator.php:52 post-expirator.php:113
44
- msgid "Expires"
45
- msgstr ""
46
-
47
- #: post-expirator.php:127
48
- msgid "Never"
49
- msgstr ""
50
-
51
- #: post-expirator.php:219
52
- msgid ""
53
- "Post Expirator: Will only update expiration date if already configured on "
54
- "post."
55
- msgstr ""
56
-
57
- #: post-expirator.php:351
58
- msgid "Enable Post Expiration"
59
- msgstr ""
60
-
61
- #: post-expirator.php:354
62
- msgid "The published date/time will be used as the expiration value"
63
- msgstr ""
64
-
65
- #: post-expirator.php:357
66
- msgid "Year"
67
- msgstr ""
68
-
69
- #: post-expirator.php:358
70
- msgid "Month"
71
- msgstr ""
72
-
73
- #: post-expirator.php:359
74
- msgid "Day"
75
- msgstr ""
76
-
77
- #: post-expirator.php:395
78
- msgid "Hour"
79
- msgstr ""
80
-
81
- #: post-expirator.php:396
82
- msgid "Minute"
83
- msgstr ""
84
-
85
- #: post-expirator.php:417
86
- msgid "How to expire"
87
- msgstr ""
88
-
89
- #: post-expirator.php:428
90
- msgid "Expiration Categories"
91
- msgstr ""
92
-
93
- #: post-expirator.php:439
94
- msgid ""
95
- "You must assign a heirarchical taxonomy to this post type to use this "
96
- "feature."
97
- msgstr ""
98
-
99
- #: post-expirator.php:441
100
- msgid ""
101
- "More than 1 heirachical taxonomy detected. You must assign a default "
102
- "taxonomy on the settings screen."
103
- msgstr ""
104
-
105
- #: post-expirator.php:451
106
- msgid "Taxonomy Name"
107
- msgstr ""
108
-
109
- #: post-expirator.php:710 post-expirator.php:721 post-expirator.php:732
110
- #: post-expirator.php:743
111
- msgid ""
112
- "%1$s (%2$s) has expired at %3$s. Post status has been successfully changed "
113
- "to \"%4$s\"."
114
- msgstr ""
115
-
116
- #: post-expirator.php:754
117
- msgid ""
118
- "%1$s (%2$s) has expired at %3$s. Post \"%4$s\" status has been successfully "
119
- "set."
120
- msgstr ""
121
-
122
- #: post-expirator.php:765
123
- msgid ""
124
- "%1$s (%2$s) has expired at %3$s. Post \"%4$s\" status has been successfully "
125
- "removed."
126
- msgstr ""
127
-
128
- #: post-expirator.php:778 post-expirator.php:792
129
- msgid ""
130
- "%1$s (%2$s) has expired at %3$s. Post \"%4$s\" have now been set to "
131
- "\"%5$s\"."
132
- msgstr ""
133
-
134
- #: post-expirator.php:815 post-expirator.php:829
135
- msgid ""
136
- "%1$s (%2$s) has expired at %3$s. The following post \"%4$s\" have now been "
137
- "added: \"%5$s\". The full list of categories on the post are: \"%6$s\"."
138
- msgstr ""
139
-
140
- #: post-expirator.php:857 post-expirator.php:878
141
- msgid ""
142
- "%1$s (%2$s) has expired at %3$s. The following post \"%4$s\" have now been "
143
- "removed: \"%5$s\". The full list of categories on the post are: \"%6$s\"."
144
- msgstr ""
145
-
146
- #: post-expirator.php:897
147
- msgid "Post Expiration Complete \"%s\""
148
- msgstr ""
149
-
150
- #: post-expirator.php:933
151
- msgid "[%1$s] %2$s"
152
- msgstr ""
153
-
154
- #: post-expirator.php:967
155
- msgid "General Settings"
156
- msgstr ""
157
-
158
- #: post-expirator.php:968 post-expirator.php:1091
159
- msgid "Defaults"
160
- msgstr ""
161
-
162
- #: post-expirator.php:969
163
- msgid "Diagnostics"
164
- msgstr ""
165
-
166
- #: post-expirator.php:970
167
- msgid "View Debug Logs"
168
- msgstr ""
169
-
170
- #: post-expirator.php:981 post-expirator.php:1000
171
- msgid "Post Expirator Options"
172
- msgstr ""
173
-
174
- #: post-expirator.php:1032 post-expirator.php:1260
175
- msgid "Saved Options!"
176
- msgstr ""
177
-
178
- #: post-expirator.php:1079
179
- msgid ""
180
- "The post expirator plugin sets a custom meta value, and then optionally "
181
- "allows you to select if you want the post changed to a draft status or "
182
- "deleted when it expires."
183
- msgstr ""
184
-
185
- #: post-expirator.php:1082
186
- msgid "Valid [postexpirator] attributes:"
187
- msgstr ""
188
-
189
- #: post-expirator.php:1084
190
- msgid "type - defaults to full - valid options are full,date,time"
191
- msgstr ""
192
-
193
- #: post-expirator.php:1085
194
- msgid ""
195
- "dateformat - format set here will override the value set on the settings "
196
- "page"
197
- msgstr ""
198
-
199
- #: post-expirator.php:1086
200
- msgid ""
201
- "timeformat - format set here will override the value set on the settings "
202
- "page"
203
- msgstr ""
204
-
205
- #: post-expirator.php:1094
206
- msgid "Date Format:"
207
- msgstr ""
208
-
209
- #: post-expirator.php:1098
210
- msgid ""
211
- "The default format to use when displaying the expiration date within a post "
212
- "using the [postexpirator] shortcode or within the footer. For information "
213
- "on valid formatting options, see: <a "
214
- "href=\"http://us2.php.net/manual/en/function.date.php\" "
215
- "target=\"_blank\">PHP Date Function</a>."
216
- msgstr ""
217
-
218
- #: post-expirator.php:1102
219
- msgid "Time Format:"
220
- msgstr ""
221
-
222
- #: post-expirator.php:1106
223
- msgid ""
224
- "The default format to use when displaying the expiration time within a post "
225
- "using the [postexpirator] shortcode or within the footer. For information "
226
- "on valid formatting options, see: <a "
227
- "href=\"http://us2.php.net/manual/en/function.date.php\" "
228
- "target=\"_blank\">PHP Date Function</a>."
229
- msgstr ""
230
-
231
- #: post-expirator.php:1110
232
- msgid "Default Date/Time Duration:"
233
- msgstr ""
234
-
235
- #: post-expirator.php:1113
236
- msgid "None"
237
- msgstr ""
238
-
239
- #: post-expirator.php:1114
240
- msgid "Custom"
241
- msgstr ""
242
-
243
- #: post-expirator.php:1115
244
- msgid "Post/Page Publish Time"
245
- msgstr ""
246
-
247
- #: post-expirator.php:1118
248
- msgid ""
249
- "Set the default expiration date to be used when creating new posts and "
250
- "pages. Defaults to none."
251
- msgstr ""
252
-
253
- #: post-expirator.php:1123
254
- msgid ""
255
- "Set the custom value to use for the default expiration date. For "
256
- "information on formatting, see <a "
257
- "href=\"http://php.net/manual/en/function.strtotime.php\">PHP strtotime "
258
- "function</a>. For example, you could enter \"+1 month\" or \"+1 week 2 days "
259
- "4 hours 2 seconds\" or \"next Thursday.\""
260
- msgstr ""
261
-
262
- #: post-expirator.php:1128
263
- msgid "Category Expiration"
264
- msgstr ""
265
-
266
- #: post-expirator.php:1131
267
- msgid "Default Expiration Category"
268
- msgstr ""
269
-
270
- #: post-expirator.php:1142
271
- msgid "Set's the default expiration category for the post."
272
- msgstr ""
273
-
274
- #: post-expirator.php:1147
275
- msgid "Expiration Email Notification"
276
- msgstr ""
277
-
278
- #: post-expirator.php:1148
279
- msgid ""
280
- "Whenever a post expires, an email can be sent to alert users of the "
281
- "expiration."
282
- msgstr ""
283
-
284
- #: post-expirator.php:1151
285
- msgid "Enable Email Notification?"
286
- msgstr ""
287
-
288
- #: post-expirator.php:1153 post-expirator.php:1163 post-expirator.php:1186
289
- #: post-expirator.php:1323
290
- msgid "Enabled"
291
- msgstr ""
292
-
293
- #: post-expirator.php:1155 post-expirator.php:1165 post-expirator.php:1188
294
- #: post-expirator.php:1325
295
- msgid "Disabled"
296
- msgstr ""
297
-
298
- #: post-expirator.php:1157
299
- msgid ""
300
- "This will enable or disable the send of email notification on post "
301
- "expiration."
302
- msgstr ""
303
-
304
- #: post-expirator.php:1161
305
- msgid "Include Blog Administrators?"
306
- msgstr ""
307
-
308
- #: post-expirator.php:1167
309
- msgid ""
310
- "This will include all users with the role of \"Administrator\" in the post "
311
- "expiration email."
312
- msgstr ""
313
-
314
- #: post-expirator.php:1171 post-expirator.php:1337
315
- msgid "Who to notify:"
316
- msgstr ""
317
-
318
- #: post-expirator.php:1175
319
- msgid ""
320
- "Enter a comma seperate list of emails that you would like to be notified "
321
- "when the post expires. This will be applied to ALL post types. You can "
322
- "set post type specific emails on the Defaults tab."
323
- msgstr ""
324
-
325
- #: post-expirator.php:1180
326
- msgid "Post Footer Display"
327
- msgstr ""
328
-
329
- #: post-expirator.php:1181
330
- msgid ""
331
- "Enabling this below will display the expiration date automatically at the "
332
- "end of any post which is set to expire."
333
- msgstr ""
334
-
335
- #: post-expirator.php:1184
336
- msgid "Show in post footer?"
337
- msgstr ""
338
-
339
- #: post-expirator.php:1190
340
- msgid ""
341
- "This will enable or disable displaying the post expiration date in the post "
342
- "footer."
343
- msgstr ""
344
-
345
- #: post-expirator.php:1194
346
- msgid "Footer Contents:"
347
- msgstr ""
348
-
349
- #: post-expirator.php:1198
350
- msgid ""
351
- "Enter the text you would like to appear at the bottom of every post that "
352
- "will expire. The following placeholders will be replaced with the post "
353
- "expiration date in the following format:"
354
- msgstr ""
355
-
356
- #: post-expirator.php:1207
357
- msgid "Footer Style:"
358
- msgstr ""
359
-
360
- #: post-expirator.php:1210
361
- msgid "This post will expire on"
362
- msgstr ""
363
-
364
- #: post-expirator.php:1212
365
- msgid "The inline css which will be used to style the footer text."
366
- msgstr ""
367
-
368
- #: post-expirator.php:1217 post-expirator.php:1351
369
- msgid "Save Changes"
370
- msgstr ""
371
-
372
- #: post-expirator.php:1268
373
- msgid "Default Expiration Values"
374
- msgstr ""
375
-
376
- #: post-expirator.php:1270
377
- msgid ""
378
- "Use the values below to set the default actions/values to be used for each "
379
- "for the corresponding post types. These values can all be overwritten when "
380
- "creating/editing the post/page."
381
- msgstr ""
382
-
383
- #: post-expirator.php:1302
384
- msgid "Active:"
385
- msgstr ""
386
-
387
- #: post-expirator.php:1304
388
- msgid "Active"
389
- msgstr ""
390
-
391
- #: post-expirator.php:1306
392
- msgid "Inactive"
393
- msgstr ""
394
-
395
- #: post-expirator.php:1308
396
- msgid "Select whether the post expirator meta box is active for this post type."
397
- msgstr ""
398
-
399
- #: post-expirator.php:1312
400
- msgid "How to expire:"
401
- msgstr ""
402
-
403
- #: post-expirator.php:1317
404
- msgid "Select the default expire action for the post type."
405
- msgstr ""
406
-
407
- #: post-expirator.php:1321
408
- msgid "Auto-Enable?"
409
- msgstr ""
410
-
411
- #: post-expirator.php:1327
412
- msgid "Select whether the post expirator is enabled for all new posts."
413
- msgstr ""
414
-
415
- #: post-expirator.php:1331
416
- msgid "Taxonomy (hierarchical):"
417
- msgstr ""
418
-
419
- #: post-expirator.php:1341
420
- msgid ""
421
- "Enter a comma seperate list of emails that you would like to be notified "
422
- "when the post expires."
423
- msgstr ""
424
-
425
- #: post-expirator.php:1369
426
- msgid "Debugging Disabled"
427
- msgstr ""
428
-
429
- #: post-expirator.php:1374
430
- msgid "Debugging Enabled"
431
- msgstr ""
432
-
433
- #: post-expirator.php:1381
434
- msgid "Debugging Table Emptied"
435
- msgstr ""
436
-
437
- #: post-expirator.php:1390
438
- msgid "Advanced Diagnostics"
439
- msgstr ""
440
-
441
- #: post-expirator.php:1393
442
- msgid "Post Expirator Debug Logging:"
443
- msgstr ""
444
-
445
- #: post-expirator.php:1397
446
- msgid "Status: Enabled"
447
- msgstr ""
448
-
449
- #: post-expirator.php:1398
450
- msgid "Disable Debugging"
451
- msgstr ""
452
-
453
- #: post-expirator.php:1400
454
- msgid "Status: Disabled"
455
- msgstr ""
456
-
457
- #: post-expirator.php:1401
458
- msgid "Enable Debugging"
459
- msgstr ""
460
-
461
- #: post-expirator.php:1409
462
- msgid "Purge Debug Log:"
463
- msgstr ""
464
-
465
- #: post-expirator.php:1411
466
- msgid "Purge Debug Log"
467
- msgstr ""
468
-
469
- #: post-expirator.php:1415
470
- msgid "WP-Cron Status:"
471
- msgstr ""
472
-
473
- #: post-expirator.php:1419
474
- msgid "DISABLED"
475
- msgstr ""
476
-
477
- #: post-expirator.php:1421
478
- msgid "ENABLED - OK"
479
- msgstr ""
480
-
481
- #: post-expirator.php:1427
482
- msgid "Current Cron Schedule:"
483
- msgstr ""
484
-
485
- #: post-expirator.php:1429
486
- msgid ""
487
- "The below table will show all currently scheduled cron events with the next "
488
- "run time."
489
- msgstr ""
490
-
491
- #: post-expirator.php:1432
492
- msgid "Date"
493
- msgstr ""
494
-
495
- #: post-expirator.php:1433
496
- msgid "Event"
497
- msgstr ""
498
-
499
- #: post-expirator.php:1434
500
- msgid "Arguments / Schedule"
501
- msgstr ""
502
-
503
- #: post-expirator.php:1459
504
- msgid "Single Event"
505
- msgstr ""
506
-
507
- #: post-expirator.php:1483
508
- msgid ""
509
- "Below is a dump of the debugging table, this should be useful for "
510
- "troubleshooting."
511
- msgstr ""
512
-
513
- #: post-expirator.php:1887
514
- msgid "Draft"
515
- msgstr ""
516
-
517
- #: post-expirator.php:1888
518
- msgid "Delete"
519
- msgstr ""
520
-
521
- #: post-expirator.php:1889
522
- msgid "Trash"
523
- msgstr ""
524
-
525
- #: post-expirator.php:1890
526
- msgid "Private"
527
- msgstr ""
528
-
529
- #: post-expirator.php:1891
530
- msgid "Stick"
531
- msgstr ""
532
-
533
- #: post-expirator.php:1892
534
- msgid "Unstick"
535
- msgstr ""
536
-
537
- #: post-expirator.php:1894
538
- msgid "Category: Replace"
539
- msgstr ""
540
-
541
- #: post-expirator.php:1895
542
- msgid "Category: Add"
543
- msgstr ""
544
-
545
- #: post-expirator.php:1896
546
- msgid "Category: Remove"
547
- msgstr ""
548
-
549
- #: post-expirator.php:1945
550
- msgid ""
551
- "Select the hierarchical taxonomy to be used for \"category\" based "
552
- "expiration."
553
- msgstr ""
554
-
555
- #. Description of the plugin/theme
556
- msgid ""
557
- "Allows you to add an expiration date (minute) to posts which you can "
558
- "configure to either delete the post, change it to a draft, or update the "
559
- "post categories at expiration time."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
560
  msgstr ""
1
+ # Copyright (C) 2021 Aaron Axelsen
2
+ # This file is distributed under the same license as the Post Expirator package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Post Expirator 2.4.2\n"
6
+ "Report-Msgid-Bugs-To: "
7
+ "https://wordpress.org/support/plugin/PublishPress-Future\n"
8
+ "POT-Creation-Date: 2021-06-17 17:09:25+00:00\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=utf-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "Last-Translator: PostExpirator Translate Team\n"
13
+ "Language-Team: PostExpirator Translate Team\n"
14
+
15
+ #: post-expirator-debug.php:66
16
+ msgid "Debugging table is currently empty."
17
+ msgstr ""
18
+
19
+ #: post-expirator-debug.php:70
20
+ msgid "Timestamp"
21
+ msgstr ""
22
+
23
+ #: post-expirator-debug.php:71
24
+ msgid "Message"
25
+ msgstr ""
26
+
27
+ #: post-expirator.php:15
28
+ msgid "l F jS, Y"
29
+ msgstr ""
30
+
31
+ #: post-expirator.php:16
32
+ msgid "g:ia"
33
+ msgstr ""
34
+
35
+ #: post-expirator.php:17
36
+ msgid "Post expires at EXPIRATIONTIME on EXPIRATIONDATE"
37
+ msgstr ""
38
+
39
+ #: post-expirator.php:41
40
+ msgid "Settings"
41
+ msgstr ""
42
+
43
+ #: post-expirator.php:70 post-expirator.php:147 post-expirator.php:218
44
+ #: post-expirator.php:269
45
+ msgid "Expires"
46
+ msgstr ""
47
+
48
+ #: post-expirator.php:164
49
+ msgid "Never"
50
+ msgstr ""
51
+
52
+ #: post-expirator.php:216 post-expirator.php:272 post-expirator.php:429
53
+ msgid "Enable Post Expiration"
54
+ msgstr ""
55
+
56
+ #: post-expirator.php:220 post-expirator.php:283 post-expirator.php:436
57
+ msgid "Month"
58
+ msgstr ""
59
+
60
+ #: post-expirator.php:233 post-expirator.php:297 post-expirator.php:437
61
+ msgid "Day"
62
+ msgstr ""
63
+
64
+ #: post-expirator.php:235 post-expirator.php:301 post-expirator.php:435
65
+ msgid "Year"
66
+ msgstr ""
67
+
68
+ #: post-expirator.php:237 post-expirator.php:305 post-expirator.php:474
69
+ msgid "Hour"
70
+ msgstr ""
71
+
72
+ #: post-expirator.php:239 post-expirator.php:309 post-expirator.php:475
73
+ msgid "Minute"
74
+ msgstr ""
75
+
76
+ #: post-expirator.php:274
77
+ msgid "No Change"
78
+ msgstr ""
79
+
80
+ #: post-expirator.php:275
81
+ msgid "Change expiry date if enabled on posts"
82
+ msgstr ""
83
+
84
+ #: post-expirator.php:275
85
+ msgid "Change on posts"
86
+ msgstr ""
87
+
88
+ #: post-expirator.php:276
89
+ msgid "Add expiry date if not enabled on posts"
90
+ msgstr ""
91
+
92
+ #: post-expirator.php:276
93
+ msgid "Add to posts"
94
+ msgstr ""
95
+
96
+ #: post-expirator.php:277
97
+ msgid "Change & Add"
98
+ msgstr ""
99
+
100
+ #: post-expirator.php:278
101
+ msgid "Remove from posts"
102
+ msgstr ""
103
+
104
+ #: post-expirator.php:432
105
+ msgid "The published date/time will be used as the expiration value"
106
+ msgstr ""
107
+
108
+ #: post-expirator.php:496
109
+ msgid "How to expire"
110
+ msgstr ""
111
+
112
+ #: post-expirator.php:507
113
+ msgid "Expiration Categories"
114
+ msgstr ""
115
+
116
+ #: post-expirator.php:518
117
+ msgid ""
118
+ "You must assign a heirarchical taxonomy to this post type to use this "
119
+ "feature."
120
+ msgstr ""
121
+
122
+ #: post-expirator.php:520
123
+ msgid ""
124
+ "More than 1 heirachical taxonomy detected. You must assign a default "
125
+ "taxonomy on the settings screen."
126
+ msgstr ""
127
+
128
+ #: post-expirator.php:530
129
+ msgid "Taxonomy Name"
130
+ msgstr ""
131
+
132
+ #: post-expirator.php:827 post-expirator.php:838 post-expirator.php:849
133
+ #: post-expirator.php:860
134
+ msgid ""
135
+ "%1$s (%2$s) has expired at %3$s. Post status has been successfully changed "
136
+ "to \"%4$s\"."
137
+ msgstr ""
138
+
139
+ #: post-expirator.php:871
140
+ msgid ""
141
+ "%1$s (%2$s) has expired at %3$s. Post \"%4$s\" status has been successfully "
142
+ "set."
143
+ msgstr ""
144
+
145
+ #: post-expirator.php:882
146
+ msgid ""
147
+ "%1$s (%2$s) has expired at %3$s. Post \"%4$s\" status has been successfully "
148
+ "removed."
149
+ msgstr ""
150
+
151
+ #: post-expirator.php:895 post-expirator.php:909
152
+ msgid ""
153
+ "%1$s (%2$s) has expired at %3$s. Post \"%4$s\" have now been set to "
154
+ "\"%5$s\"."
155
+ msgstr ""
156
+
157
+ #: post-expirator.php:932 post-expirator.php:946
158
+ msgid ""
159
+ "%1$s (%2$s) has expired at %3$s. The following post \"%4$s\" have now been "
160
+ "added: \"%5$s\". The full list of categories on the post are: \"%6$s\"."
161
+ msgstr ""
162
+
163
+ #: post-expirator.php:974 post-expirator.php:995
164
+ msgid ""
165
+ "%1$s (%2$s) has expired at %3$s. The following post \"%4$s\" have now been "
166
+ "removed: \"%5$s\". The full list of categories on the post are: \"%6$s\"."
167
+ msgstr ""
168
+
169
+ #: post-expirator.php:1014
170
+ msgid "Post Expiration Complete \"%s\""
171
+ msgstr ""
172
+
173
+ #: post-expirator.php:1050
174
+ msgid "[%1$s] %2$s"
175
+ msgstr ""
176
+
177
+ #: post-expirator.php:1092
178
+ msgid "General Settings"
179
+ msgstr ""
180
+
181
+ #: post-expirator.php:1093 post-expirator.php:1228
182
+ msgid "Defaults"
183
+ msgstr ""
184
+
185
+ #: post-expirator.php:1094
186
+ msgid "Diagnostics"
187
+ msgstr ""
188
+
189
+ #: post-expirator.php:1095
190
+ msgid "View Debug Logs"
191
+ msgstr ""
192
+
193
+ #: post-expirator.php:1110 post-expirator.php:1133
194
+ msgid "Post Expirator Options"
195
+ msgstr ""
196
+
197
+ #: post-expirator.php:1169 post-expirator.php:1401
198
+ msgid "Saved Options!"
199
+ msgstr ""
200
+
201
+ #: post-expirator.php:1216
202
+ msgid ""
203
+ "The post expirator plugin sets a custom meta value, and then optionally "
204
+ "allows you to select if you want the post changed to a draft status or "
205
+ "deleted when it expires."
206
+ msgstr ""
207
+
208
+ #: post-expirator.php:1219
209
+ msgid "Valid [postexpirator] attributes:"
210
+ msgstr ""
211
+
212
+ #: post-expirator.php:1221
213
+ msgid "type - defaults to full - valid options are full,date,time"
214
+ msgstr ""
215
+
216
+ #: post-expirator.php:1222
217
+ msgid ""
218
+ "dateformat - format set here will override the value set on the settings "
219
+ "page"
220
+ msgstr ""
221
+
222
+ #: post-expirator.php:1223
223
+ msgid ""
224
+ "timeformat - format set here will override the value set on the settings "
225
+ "page"
226
+ msgstr ""
227
+
228
+ #: post-expirator.php:1231
229
+ msgid "Date Format:"
230
+ msgstr ""
231
+
232
+ #: post-expirator.php:1235
233
+ msgid ""
234
+ "The default format to use when displaying the expiration date within a post "
235
+ "using the [postexpirator] shortcode or within the footer. For information "
236
+ "on valid formatting options, see: <a "
237
+ "href=\"http://us2.php.net/manual/en/function.date.php\" "
238
+ "target=\"_blank\">PHP Date Function</a>."
239
+ msgstr ""
240
+
241
+ #: post-expirator.php:1239
242
+ msgid "Time Format:"
243
+ msgstr ""
244
+
245
+ #: post-expirator.php:1243
246
+ msgid ""
247
+ "The default format to use when displaying the expiration time within a post "
248
+ "using the [postexpirator] shortcode or within the footer. For information "
249
+ "on valid formatting options, see: <a "
250
+ "href=\"http://us2.php.net/manual/en/function.date.php\" "
251
+ "target=\"_blank\">PHP Date Function</a>."
252
+ msgstr ""
253
+
254
+ #: post-expirator.php:1247
255
+ msgid "Default Date/Time Duration:"
256
+ msgstr ""
257
+
258
+ #: post-expirator.php:1250
259
+ msgid "None"
260
+ msgstr ""
261
+
262
+ #: post-expirator.php:1251
263
+ msgid "Custom"
264
+ msgstr ""
265
+
266
+ #: post-expirator.php:1252
267
+ msgid "Post/Page Publish Time"
268
+ msgstr ""
269
+
270
+ #: post-expirator.php:1255
271
+ msgid ""
272
+ "Set the default expiration date to be used when creating new posts and "
273
+ "pages. Defaults to none."
274
+ msgstr ""
275
+
276
+ #: post-expirator.php:1260
277
+ msgid ""
278
+ "Set the custom value to use for the default expiration date. For "
279
+ "information on formatting, see %1$s. For example, you could enter %2$s+1 "
280
+ "month%3$s or %4$s+1 week 2 days 4 hours 2 seconds%5$s or %6$snext "
281
+ "Thursday%7$s."
282
+ msgstr ""
283
+
284
+ #: post-expirator.php:1265
285
+ msgid "Category Expiration"
286
+ msgstr ""
287
+
288
+ #: post-expirator.php:1268
289
+ msgid "Default Expiration Category"
290
+ msgstr ""
291
+
292
+ #: post-expirator.php:1279
293
+ msgid "Set's the default expiration category for the post."
294
+ msgstr ""
295
+
296
+ #: post-expirator.php:1284
297
+ msgid "Expiration Email Notification"
298
+ msgstr ""
299
+
300
+ #: post-expirator.php:1285
301
+ msgid ""
302
+ "Whenever a post expires, an email can be sent to alert users of the "
303
+ "expiration."
304
+ msgstr ""
305
+
306
+ #: post-expirator.php:1288
307
+ msgid "Enable Email Notification?"
308
+ msgstr ""
309
+
310
+ #: post-expirator.php:1290 post-expirator.php:1300 post-expirator.php:1323
311
+ #: post-expirator.php:1464
312
+ msgid "Enabled"
313
+ msgstr ""
314
+
315
+ #: post-expirator.php:1292 post-expirator.php:1302 post-expirator.php:1325
316
+ #: post-expirator.php:1466
317
+ msgid "Disabled"
318
+ msgstr ""
319
+
320
+ #: post-expirator.php:1294
321
+ msgid ""
322
+ "This will enable or disable the send of email notification on post "
323
+ "expiration."
324
+ msgstr ""
325
+
326
+ #: post-expirator.php:1298
327
+ msgid "Include Blog Administrators?"
328
+ msgstr ""
329
+
330
+ #: post-expirator.php:1304
331
+ msgid ""
332
+ "This will include all users with the role of \"Administrator\" in the post "
333
+ "expiration email."
334
+ msgstr ""
335
+
336
+ #: post-expirator.php:1308 post-expirator.php:1478
337
+ msgid "Who to notify:"
338
+ msgstr ""
339
+
340
+ #: post-expirator.php:1312
341
+ msgid ""
342
+ "Enter a comma seperate list of emails that you would like to be notified "
343
+ "when the post expires. This will be applied to ALL post types. You can "
344
+ "set post type specific emails on the Defaults tab."
345
+ msgstr ""
346
+
347
+ #: post-expirator.php:1317
348
+ msgid "Post Footer Display"
349
+ msgstr ""
350
+
351
+ #: post-expirator.php:1318
352
+ msgid ""
353
+ "Enabling this below will display the expiration date automatically at the "
354
+ "end of any post which is set to expire."
355
+ msgstr ""
356
+
357
+ #: post-expirator.php:1321
358
+ msgid "Show in post footer?"
359
+ msgstr ""
360
+
361
+ #: post-expirator.php:1327
362
+ msgid ""
363
+ "This will enable or disable displaying the post expiration date in the post "
364
+ "footer."
365
+ msgstr ""
366
+
367
+ #: post-expirator.php:1331
368
+ msgid "Footer Contents:"
369
+ msgstr ""
370
+
371
+ #: post-expirator.php:1335
372
+ msgid ""
373
+ "Enter the text you would like to appear at the bottom of every post that "
374
+ "will expire. The following placeholders will be replaced with the post "
375
+ "expiration date in the following format:"
376
+ msgstr ""
377
+
378
+ #: post-expirator.php:1344
379
+ msgid "Footer Style:"
380
+ msgstr ""
381
+
382
+ #: post-expirator.php:1347
383
+ msgid "This post will expire on"
384
+ msgstr ""
385
+
386
+ #: post-expirator.php:1349
387
+ msgid "The inline css which will be used to style the footer text."
388
+ msgstr ""
389
+
390
+ #: post-expirator.php:1354 post-expirator.php:1492
391
+ msgid "Save Changes"
392
+ msgstr ""
393
+
394
+ #: post-expirator.php:1409
395
+ msgid "Default Expiration Values"
396
+ msgstr ""
397
+
398
+ #: post-expirator.php:1411
399
+ msgid ""
400
+ "Use the values below to set the default actions/values to be used for each "
401
+ "for the corresponding post types. These values can all be overwritten when "
402
+ "creating/editing the post/page."
403
+ msgstr ""
404
+
405
+ #: post-expirator.php:1443
406
+ msgid "Active:"
407
+ msgstr ""
408
+
409
+ #: post-expirator.php:1445
410
+ msgid "Active"
411
+ msgstr ""
412
+
413
+ #: post-expirator.php:1447
414
+ msgid "Inactive"
415
+ msgstr ""
416
+
417
+ #: post-expirator.php:1449
418
+ msgid "Select whether the post expirator meta box is active for this post type."
419
+ msgstr ""
420
+
421
+ #: post-expirator.php:1453
422
+ msgid "How to expire:"
423
+ msgstr ""
424
+
425
+ #: post-expirator.php:1458
426
+ msgid "Select the default expire action for the post type."
427
+ msgstr ""
428
+
429
+ #: post-expirator.php:1462
430
+ msgid "Auto-Enable?"
431
+ msgstr ""
432
+
433
+ #: post-expirator.php:1468
434
+ msgid "Select whether the post expirator is enabled for all new posts."
435
+ msgstr ""
436
+
437
+ #: post-expirator.php:1472
438
+ msgid "Taxonomy (hierarchical):"
439
+ msgstr ""
440
+
441
+ #: post-expirator.php:1482
442
+ msgid ""
443
+ "Enter a comma seperate list of emails that you would like to be notified "
444
+ "when the post expires."
445
+ msgstr ""
446
+
447
+ #: post-expirator.php:1514
448
+ msgid "Debugging Disabled"
449
+ msgstr ""
450
+
451
+ #: post-expirator.php:1519
452
+ msgid "Debugging Enabled"
453
+ msgstr ""
454
+
455
+ #: post-expirator.php:1526
456
+ msgid "Debugging Table Emptied"
457
+ msgstr ""
458
+
459
+ #: post-expirator.php:1535
460
+ msgid "Advanced Diagnostics"
461
+ msgstr ""
462
+
463
+ #: post-expirator.php:1538
464
+ msgid "Post Expirator Debug Logging:"
465
+ msgstr ""
466
+
467
+ #: post-expirator.php:1542
468
+ msgid "Status: Enabled"
469
+ msgstr ""
470
+
471
+ #: post-expirator.php:1543
472
+ msgid "Disable Debugging"
473
+ msgstr ""
474
+
475
+ #: post-expirator.php:1545
476
+ msgid "Status: Disabled"
477
+ msgstr ""
478
+
479
+ #: post-expirator.php:1546
480
+ msgid "Enable Debugging"
481
+ msgstr ""
482
+
483
+ #: post-expirator.php:1554
484
+ msgid "Purge Debug Log:"
485
+ msgstr ""
486
+
487
+ #: post-expirator.php:1556
488
+ msgid "Purge Debug Log"
489
+ msgstr ""
490
+
491
+ #: post-expirator.php:1560
492
+ msgid "WP-Cron Status:"
493
+ msgstr ""
494
+
495
+ #: post-expirator.php:1564
496
+ msgid "DISABLED"
497
+ msgstr ""
498
+
499
+ #: post-expirator.php:1566
500
+ msgid "ENABLED - OK"
501
+ msgstr ""
502
+
503
+ #: post-expirator.php:1572
504
+ msgid "Current Cron Schedule:"
505
+ msgstr ""
506
+
507
+ #: post-expirator.php:1574
508
+ msgid ""
509
+ "The below table will show all currently scheduled cron events with the next "
510
+ "run time."
511
+ msgstr ""
512
+
513
+ #: post-expirator.php:1577
514
+ msgid "Date"
515
+ msgstr ""
516
+
517
+ #: post-expirator.php:1578
518
+ msgid "Event"
519
+ msgstr ""
520
+
521
+ #: post-expirator.php:1579
522
+ msgid "Arguments / Schedule"
523
+ msgstr ""
524
+
525
+ #: post-expirator.php:1604
526
+ msgid "Single Event"
527
+ msgstr ""
528
+
529
+ #: post-expirator.php:1632
530
+ msgid ""
531
+ "Below is a dump of the debugging table, this should be useful for "
532
+ "troubleshooting."
533
+ msgstr ""
534
+
535
+ #: post-expirator.php:2075
536
+ msgid "Draft"
537
+ msgstr ""
538
+
539
+ #: post-expirator.php:2076
540
+ msgid "Delete"
541
+ msgstr ""
542
+
543
+ #: post-expirator.php:2077
544
+ msgid "Trash"
545
+ msgstr ""
546
+
547
+ #: post-expirator.php:2078
548
+ msgid "Private"
549
+ msgstr ""
550
+
551
+ #: post-expirator.php:2079
552
+ msgid "Stick"
553
+ msgstr ""
554
+
555
+ #: post-expirator.php:2080
556
+ msgid "Unstick"
557
+ msgstr ""
558
+
559
+ #: post-expirator.php:2082
560
+ msgid "Category: Replace"
561
+ msgstr ""
562
+
563
+ #: post-expirator.php:2083
564
+ msgid "Category: Add"
565
+ msgstr ""
566
+
567
+ #: post-expirator.php:2084
568
+ msgid "Category: Remove"
569
+ msgstr ""
570
+
571
+ #: post-expirator.php:2137
572
+ msgid ""
573
+ "Select the hierarchical taxonomy to be used for \"category\" based "
574
+ "expiration."
575
+ msgstr ""
576
+
577
+ #. Description of the plugin/theme
578
+ msgid ""
579
+ "Allows you to add an expiration date (minute) to posts which you can "
580
+ "configure to either delete the post, change it to a draft, or update the "
581
+ "post categories at expiration time."
582
  msgstr ""
legacy-functions.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This file provides access to all legacy functions that are now deprecated.
4
+ */
5
+
6
+ if ( ! function_exists( '_scheduleExpiratorEvent' ) ) {
7
+
8
+ /**
9
+ * Schedules the single event.
10
+ *
11
+ * @since 2.4.3
12
+ * @deprecated 2.4.3
13
+ */
14
+ function _scheduleExpiratorEvent( $id, $ts, $opts ) {
15
+ postexpirator_schedule_event( $id, $ts, $opts );
16
+ }
17
+ }
18
+
19
+
20
+ if ( ! function_exists( '_unscheduleExpiratorEvent' ) ) {
21
+
22
+ /**
23
+ * Unschedules the single event.
24
+ *
25
+ * @since 2.4.3
26
+ * @deprecated 2.4.3
27
+ */
28
+ function _unscheduleExpiratorEvent( $id ) {
29
+ postexpirator_unschedule_event( $id );
30
+ }
31
+ }
32
+
33
+
34
+ if ( ! function_exists( 'postExpiratorExpire' ) ) {
35
+
36
+ /**
37
+ * Expires the post.
38
+ *
39
+ * @since 2.4.3
40
+ * @deprecated 2.4.3
41
+ */
42
+ function postExpiratorExpire( $id ) {
43
+ postexpirator_expire_post( $id );
44
+ }
45
+ }
46
+
47
+
post-expirator-debug.php CHANGED
@@ -1,88 +1,88 @@
1
- <?php
2
-
3
- // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
4
-
5
- /**
6
- * The class that adds debug entries to the database.
7
- */
8
- class PostExpiratorDebug {
9
-
10
- /**
11
- * Constructor.
12
- */
13
- function __construct() {
14
- global $wpdb;
15
- $this->debug_table = $wpdb->prefix . 'postexpirator_debug';
16
- $this->createDBTable();
17
- }
18
-
19
- /**
20
- * Create Database Table to store debugging information if it does not already exist.
21
- */
22
- private function createDBTable() {
23
- global $wpdb;
24
-
25
- if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $this->debug_table . "'" ) !== $this->debug_table ) {
26
- $sql = 'CREATE TABLE `' . $this->debug_table . '` (
27
- `id` INT(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,
28
- `timestamp` TIMESTAMP NOT NULL,
29
- `blog` INT(9) NOT NULL,
30
- `message` text NOT NULL
31
- );';
32
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
33
- dbDelta( $sql );
34
- }
35
- }
36
-
37
- /**
38
- * Drop Database Table.
39
- */
40
- public function removeDBTable() {
41
- global $wpdb;
42
- $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->debug_table );
43
- }
44
-
45
- /**
46
- * Insert into Database Table.
47
- */
48
- public function save( $data ) {
49
- global $wpdb;
50
- if ( is_multisite() ) {
51
- global $current_blog;
52
- $blog = $current_blog->blog_id;
53
- } else {
54
- $blog = 0;
55
- }
56
- $wpdb->query( $wpdb->prepare( 'INSERT INTO ' . $this->debug_table . ' (`timestamp`,`message`,`blog`) VALUES (FROM_UNIXTIME(%d),%s,%s)', time(), $data['message'], $blog ) );
57
- }
58
-
59
- /**
60
- * Get the HTML of the table's data.
61
- */
62
- public function getTable() {
63
- global $wpdb;
64
- $results = $wpdb->get_results( "SELECT * FROM {$this->debug_table} ORDER BY `id` DESC" );
65
- if ( empty( $results ) ) {
66
- print '<p>' . __( 'Debugging table is currently empty.', 'post-expirator' ) . '</p>';
67
- return;
68
- }
69
- print '<table class="post-expirator-debug">';
70
- print '<tr><th class="post-expirator-timestamp">' . __( 'Timestamp', 'post-expirator' ) . '</th>';
71
- print '<th>' . __( 'Message', 'post-expirator' ) . '</th></tr>';
72
- foreach ( $results as $result ) {
73
- print '<tr><td>' . $result->timestamp . '</td>';
74
- print '<td>' . $result->message . '</td></tr>';
75
- }
76
- print '</table>';
77
- }
78
-
79
- /**
80
- * Truncate Database Table.
81
- */
82
- public function purge() {
83
- global $wpdb;
84
- $wpdb->query( "TRUNCATE TABLE {$this->debug_table}" );
85
- }
86
- }
87
-
88
  // phpcs:enable
1
+ <?php
2
+
3
+ // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
4
+
5
+ /**
6
+ * The class that adds debug entries to the database.
7
+ */
8
+ class PostExpiratorDebug {
9
+
10
+ /**
11
+ * Constructor.
12
+ */
13
+ function __construct() {
14
+ global $wpdb;
15
+ $this->debug_table = $wpdb->prefix . 'postexpirator_debug';
16
+ $this->createDBTable();
17
+ }
18
+
19
+ /**
20
+ * Create Database Table to store debugging information if it does not already exist.
21
+ */
22
+ private function createDBTable() {
23
+ global $wpdb;
24
+
25
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $this->debug_table . "'" ) !== $this->debug_table ) {
26
+ $sql = 'CREATE TABLE `' . $this->debug_table . '` (
27
+ `id` INT(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,
28
+ `timestamp` TIMESTAMP NOT NULL,
29
+ `blog` INT(9) NOT NULL,
30
+ `message` text NOT NULL
31
+ );';
32
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
33
+ dbDelta( $sql );
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Drop Database Table.
39
+ */
40
+ public function removeDBTable() {
41
+ global $wpdb;
42
+ $wpdb->query( 'DROP TABLE IF EXISTS ' . $this->debug_table );
43
+ }
44
+
45
+ /**
46
+ * Insert into Database Table.
47
+ */
48
+ public function save( $data ) {
49
+ global $wpdb;
50
+ if ( is_multisite() ) {
51
+ global $current_blog;
52
+ $blog = $current_blog->blog_id;
53
+ } else {
54
+ $blog = 0;
55
+ }
56
+ $wpdb->query( $wpdb->prepare( 'INSERT INTO ' . $this->debug_table . ' (`timestamp`,`message`,`blog`) VALUES (FROM_UNIXTIME(%d),%s,%s)', time(), $data['message'], $blog ) );
57
+ }
58
+
59
+ /**
60
+ * Get the HTML of the table's data.
61
+ */
62
+ public function getTable() {
63
+ global $wpdb;
64
+ $results = $wpdb->get_results( "SELECT * FROM {$this->debug_table} ORDER BY `id` DESC" );
65
+ if ( empty( $results ) ) {
66
+ print '<p>' . __( 'Debugging table is currently empty.', 'post-expirator' ) . '</p>';
67
+ return;
68
+ }
69
+ print '<table class="post-expirator-debug">';
70
+ print '<tr><th class="post-expirator-timestamp">' . __( 'Timestamp', 'post-expirator' ) . '</th>';
71
+ print '<th>' . __( 'Message', 'post-expirator' ) . '</th></tr>';
72
+ foreach ( $results as $result ) {
73
+ print '<tr><td>' . $result->timestamp . '</td>';
74
+ print '<td>' . $result->message . '</td></tr>';
75
+ }
76
+ print '</table>';
77
+ }
78
+
79
+ /**
80
+ * Truncate Database Table.
81
+ */
82
+ public function purge() {
83
+ global $wpdb;
84
+ $wpdb->query( "TRUNCATE TABLE {$this->debug_table}" );
85
+ }
86
+ }
87
+
88
  // phpcs:enable
post-expirator.php CHANGED
@@ -1,2022 +1,2252 @@
1
- <?php
2
- /*
3
- 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.4.2
8
- Author URI: http://postexpirator.tuxdocs.net/
9
- Text Domain: post-expirator
10
- Domain Path: /languages
11
- */
12
-
13
- // Default Values
14
- define( 'POSTEXPIRATOR_VERSION', '2.4.2' );
15
- define( 'POSTEXPIRATOR_DATEFORMAT', __( 'l F jS, Y', 'post-expirator' ) );
16
- define( 'POSTEXPIRATOR_TIMEFORMAT', __( 'g:ia', 'post-expirator' ) );
17
- define( 'POSTEXPIRATOR_FOOTERCONTENTS', __( 'Post expires at EXPIRATIONTIME on EXPIRATIONDATE', 'post-expirator' ) );
18
- define( 'POSTEXPIRATOR_FOOTERSTYLE', 'font-style: italic;' );
19
- define( 'POSTEXPIRATOR_FOOTERDISPLAY', '0' );
20
- define( 'POSTEXPIRATOR_EMAILNOTIFICATION', '0' );
21
- define( 'POSTEXPIRATOR_EMAILNOTIFICATIONADMINS', '0' );
22
- define( 'POSTEXPIRATOR_DEBUGDEFAULT', '0' );
23
- define( 'POSTEXPIRATOR_EXPIREDEFAULT', 'null' );
24
- define( 'POSTEXPIRATOR_SLUG', 'post-expirator' );
25
-
26
- /**
27
- * Adds links to the plugin listing screen.
28
- */
29
- function postexpirator_plugin_action_links( $links, $file ) {
30
- $this_plugin = basename( plugin_dir_url( __FILE__ ) ) . '/post-expirator.php';
31
- if ( $file === $this_plugin ) {
32
- $links[] = '<a href="options-general.php?page=post-expirator">' . __( 'Settings', 'post-expirator' ) . '</a>';
33
- }
34
- return $links;
35
- }
36
- add_filter( 'plugin_action_links', 'postexpirator_plugin_action_links', 10, 2 );
37
-
38
- /**
39
- * Load translation, if it exists.
40
- */
41
- function postexpirator_init() {
42
- $plugin_dir = basename( dirname( __FILE__ ) );
43
- load_plugin_textdomain( 'post-expirator', null, $plugin_dir . '/languages/' );
44
- }
45
- add_action( 'plugins_loaded', 'postexpirator_init' );
46
-
47
- /**
48
- * Adds an 'Expires' column to the post display table.
49
- */
50
- function postexpirator_add_column( $columns, $type ) {
51
- $defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
52
- if ( ! isset( $defaults['activeMetaBox'] ) || $defaults['activeMetaBox'] === 'active' ) {
53
- $columns['expirationdate'] = __( 'Expires', 'post-expirator' );
54
- }
55
- return $columns;
56
- }
57
- add_filter( 'manage_posts_columns', 'postexpirator_add_column', 10, 2 );
58
-
59
- /**
60
- * Adds sortable columns.
61
- */
62
- function postexpirator_manage_sortable_columns() {
63
- $post_types = get_post_types( array('public' => true) );
64
- foreach ( $post_types as $post_type ) {
65
- add_filter( 'manage_edit-' . $post_type . '_sortable_columns', 'postexpirator_sortable_column' );
66
- }
67
- }
68
- add_action( 'init', 'postexpirator_manage_sortable_columns', 100 );
69
-
70
- /**
71
- * Adds an 'Expires' column to the post display table.
72
- */
73
- function postexpirator_sortable_column( $columns ) {
74
- $columns['expirationdate'] = 'expirationdate';
75
- return $columns;
76
- }
77
-
78
- /**
79
- * Modify the sorting of posts.
80
- */
81
- function postexpirator_orderby( $query ) {
82
- if ( ! is_admin() ) {
83
- return;
84
- }
85
-
86
- $orderby = $query->get( 'orderby' );
87
-
88
- if ( 'expirationdate' === $orderby ) {
89
- $query->set(
90
- 'meta_query', array(
91
- 'relation' => 'OR',
92
- array(
93
- 'key' => '_expiration-date',
94
- 'compare' => 'EXISTS',
95
- ),
96
- array(
97
- 'key' => '_expiration-date',
98
- 'compare' => 'NOT EXISTS',
99
- 'value' => '',
100
- ),
101
- )
102
- );
103
- $query->set( 'orderby', 'meta_value_num' );
104
- }
105
- }
106
- add_action( 'pre_get_posts', 'postexpirator_orderby' );
107
-
108
- /**
109
- * Adds an 'Expires' column to the page display table.
110
- */
111
- function postexpirator_add_column_page( $columns ) {
112
- $defaults = get_option( 'expirationdateDefaultsPage' );
113
- if ( ! isset( $defaults['activeMetaBox'] ) || $defaults['activeMetaBox'] === 'active' ) {
114
- $columns['expirationdate'] = __( 'Expires', 'post-expirator' );
115
- }
116
- return $columns;
117
- }
118
- add_filter( 'manage_pages_columns', 'postexpirator_add_column_page' );
119
-
120
- /**
121
- * Fills the 'Expires' column of the post display table.
122
- */
123
- function postexpirator_show_value( $column_name ) {
124
- global $post;
125
- $id = $post->ID;
126
- if ( $column_name === 'expirationdate' ) {
127
- $ed = get_post_meta( $id, '_expiration-date', true );
128
- echo ( $ed ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ed ), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) : __( 'Never', 'post-expirator' ) );
129
-
130
- // Values for Quick Edit
131
- if ( $ed ) {
132
- $year = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ed ), 'Y' );
133
- $month = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ed ), 'm' );
134
- $day = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ed ), 'd' );
135
- $hour = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ed ), 'H' );
136
- $minute = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ed ), 'i' );
137
- echo '<span id="expirationdate_year-' . $id . '" style="display: none;">' . $year . '</span>';
138
- echo '<span id="expirationdate_month-' . $id . '" style="display: none;">' . $month . '</span>';
139
- echo '<span id="expirationdate_day-' . $id . '" style="display: none;">' . $day . '</span>';
140
- echo '<span id="expirationdate_hour-' . $id . '" style="display: none;">' . $hour . '</span>';
141
- echo '<span id="expirationdate_minute-' . $id . '" style="display: none;">' . $minute . '</span>';
142
- echo '<span id="expirationdate_enabled-' . $id . '" style="display: none;">true</span>';
143
- } else {
144
- echo '<span id="expirationdate_year-' . $id . '" style="display: none;">' . date( 'Y' ) . '</span>';
145
- echo '<span id="expirationdate_month-' . $id . '" style="display: none;">' . date( 'm' ) . '</span>';
146
- echo '<span id="expirationdate_day-' . $id . '" style="display: none;">' . date( 'd' ) . '</span>';
147
- echo '<span id="expirationdate_hour-' . $id . '" style="display: none;">' . date( 'H' ) . '</span>';
148
- echo '<span id="expirationdate_minute-' . $id . '" style="display: none;">' . date( 'i' ) . '</span>';
149
- echo '<span id="expirationdate_enabled-' . $id . '" style="display: none;">false</span>';
150
- }
151
- }
152
- }
153
- add_action( 'manage_posts_custom_column', 'postexpirator_show_value' );
154
- add_action( 'manage_pages_custom_column', 'postexpirator_show_value' );
155
-
156
-
157
- /**
158
- * Quick Edit functionality.
159
- */
160
- function postexpirator_quickedit( $column_name, $post_type ) {
161
- if ( $column_name !== 'expirationdate' ) {
162
- return;
163
- }
164
- ?>
165
- <div style="clear:both"></div>
166
- <fieldset class="inline-edit-col-left post-expirator-quickedit">
167
- <div class="inline-edit-col">
168
- <div class="inline-edit-group">
169
- <span class="title">Post Expirator</span>
170
- <p><input name="enable-expirationdate" type="checkbox" /><span class="title">Enable Post Expiration</span></p>
171
- <fieldset class="inline-edit-date">
172
- <legend><span class="title">Expires</span></legend>
173
- <div class="timestamp-wrap">
174
- <label><span class="screen-reader-text">Month</span>
175
- <select name="expirationdate_month">
176
- <option value="01" data-text="Jan">01-Jan</option>
177
- <option value="02" data-text="Feb">02-Feb</option>
178
- <option value="03" data-text="Mar">03-Mar</option>
179
- <option value="04" data-text="Apr">04-Apr</option>
180
- <option value="05" data-text="May">05-May</option>
181
- <option value="06" data-text="Jun">06-Jun</option>
182
- <option value="07" data-text="Jul">07-Jul</option>
183
- <option value="08" data-text="Aug">08-Aug</option>
184
- <option value="09" data-text="Sep">09-Sep</option>
185
- <option value="10" data-text="Oct">10-Oct</option>
186
- <option value="11" data-text="Nov">11-Nov</option>
187
- <option value="12" data-text="Dec">12-Dec</option>
188
- </select>
189
- </label>
190
- <label><span class="screen-reader-text">Day</span>
191
- <input name="expirationdate_day" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>,
192
- <label><span class="screen-reader-text">Year</span>
193
- <input name="expirationdate_year" value="" size="4" maxlength="4" autocomplete="off" type="text"></label> @
194
- <label><span class="screen-reader-text">Hour</span>
195
- <input name="expirationdate_hour" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>:
196
- <label><span class="screen-reader-text">Minute</span>
197
- <input name="expirationdate_minute" value="" size="2" maxlength="2" autocomplete="off" type="text"></label></div>
198
- <input name="expirationdate_quickedit" value="true" type="hidden"/>
199
- </fieldset>
200
- </div>
201
- </div>
202
- </fieldset>
203
- <?php
204
-
205
- }
206
- add_action( 'quick_edit_custom_box', 'postexpirator_quickedit', 10, 2 );
207
-
208
- /**
209
- * Bulk Edit functionality.
210
- */
211
- function postexpirator_bulkedit( $column_name, $post_type ) {
212
- if ( $column_name !== 'expirationdate' ) {
213
- return;
214
- }
215
- ?>
216
- <div style="clear:both"></div>
217
- <div class="inline-edit-col post-expirator-quickedit">
218
- <div class="inline-edit-col">
219
- <div class="inline-edit-group">
220
- <span class="title"><?php echo __( 'Post Expirator: Will only update expiration date if already configured on post.', 'post-expirator' ); ?></span>
221
- <fieldset class="inline-edit-date">
222
- <legend><span class="title">Expires</span></legend>
223
- <div class="timestamp-wrap">
224
- <label><span class="screen-reader-text">Month</span>
225
- <select name="expirationdate_month">
226
- <option value="false">- No Change -</option>
227
- <option value="01" data-text="Jan">01-Jan</option>
228
- <option value="02" data-text="Feb">02-Feb</option>
229
- <option value="03" data-text="Mar">03-Mar</option>
230
- <option value="04" data-text="Apr">04-Apr</option>
231
- <option value="05" data-text="May">05-May</option>
232
- <option value="06" data-text="Jun">06-Jun</option>
233
- <option value="07" data-text="Jul">07-Jul</option>
234
- <option value="08" data-text="Aug">08-Aug</option>
235
- <option value="09" data-text="Sep">09-Sep</option>
236
- <option value="10" data-text="Oct">10-Oct</option>
237
- <option value="11" data-text="Nov">11-Nov</option>
238
- <option value="12" data-text="Dec">12-Dec</option>
239
- </select>
240
- </label>
241
- <label><span class="screen-reader-text">Day</span>
242
- <input name="expirationdate_day" placeholder="Day" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>,
243
- <label><span class="screen-reader-text">Year</span>
244
- <input name="expirationdate_year" placeholder="Year" value="" size="4" maxlength="4" autocomplete="off" type="text"></label> @
245
- <label><span class="screen-reader-text">Hour</span>
246
- <input name="expirationdate_hour" placeholder="Hour" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>:
247
- <label><span class="screen-reader-text">Minute</span>
248
- <input name="expirationdate_minute" placeholder="Min" value="" size="2" maxlength="2" autocomplete="off" type="text"></label></div>
249
- <input name="expirationdate_quickedit" value="true" type="hidden"/>
250
- </fieldset>
251
- </div>
252
- </div>
253
- </div>
254
- <?php
255
-
256
- }
257
- add_action( 'bulk_edit_custom_box', 'postexpirator_bulkedit', 10, 2 );
258
-
259
- /**
260
- * Adds hooks to get the meta box added to pages and custom post types
261
- */
262
- function postexpirator_meta_custom() {
263
- $custom_post_types = get_post_types();
264
- array_push( $custom_post_types, 'page' );
265
- foreach ( $custom_post_types as $t ) {
266
- $defaults = get_option( 'expirationdateDefaults' . ucfirst( $t ) );
267
- if ( ! isset( $defaults['activeMetaBox'] ) || $defaults['activeMetaBox'] === 'active' ) {
268
- add_meta_box( 'expirationdatediv', __( 'Post Expirator', 'post-expirator' ), 'postexpirator_meta_box', $t, 'side', 'core' );
269
- }
270
- }
271
- }
272
- add_action( 'add_meta_boxes', 'postexpirator_meta_custom' );
273
-
274
- /**
275
- * Actually adds the meta box
276
- */
277
- function postexpirator_meta_box( $post ) {
278
- // Get default month
279
- $expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
280
- $firstsave = get_post_meta( $post->ID, '_expiration-date-status', true );
281
-
282
- // nonce
283
- wp_nonce_field( '__postexpirator', '_postexpiratornonce' );
284
-
285
- $default = '';
286
- $expireType = '';
287
- $defaults = get_option( 'expirationdateDefaults' . ucfirst( $post->post_type ) );
288
- if ( empty( $expirationdatets ) ) {
289
- $default = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
290
- if ( $default === 'null' ) {
291
- $defaultmonth = date_i18n( 'm' );
292
- $defaultday = date_i18n( 'd' );
293
- $defaulthour = date_i18n( 'H' );
294
- $defaultyear = date_i18n( 'Y' );
295
- $defaultminute = date_i18n( 'i' );
296
-
297
- } elseif ( $default === 'custom' ) {
298
- $custom = get_option( 'expirationdateDefaultDateCustom' );
299
- if ( $custom === false ) {
300
- $ts = time();
301
- } else {
302
- $tz = get_option( 'timezone_string' );
303
- if ( $tz ) {
304
- // @TODO Using date_default_timezone_set() and similar isn't allowed, instead use WP internal timezone support.
305
- // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
306
- date_default_timezone_set( $tz );
307
- }
308
- $ts = time() + ( strtotime( $custom ) - time() );
309
- if ( $tz ) {
310
- // @TODO Using date_default_timezone_set() and similar isn't allowed, instead use WP internal timezone support.
311
- // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
312
- date_default_timezone_set( 'UTC' );
313
- }
314
- }
315
- $defaultmonth = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'm' );
316
- $defaultday = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'd' );
317
- $defaultyear = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'Y' );
318
- $defaulthour = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'H' );
319
- $defaultminute = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'i' );
320
- }
321
-
322
- $enabled = '';
323
- $disabled = ' disabled="disabled"';
324
- $categories = get_option( 'expirationdateCategoryDefaults' );
325
-
326
- if ( isset( $defaults['expireType'] ) ) {
327
- $expireType = $defaults['expireType'];
328
- }
329
-
330
- // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
331
- if ( isset( $defaults['autoEnable'] ) && ( $firstsave !== 'saved' ) && ( $defaults['autoEnable'] === true || $defaults['autoEnable'] == 1 ) ) {
332
- $enabled = ' checked="checked"';
333
- $disabled = '';
334
- }
335
- } else {
336
- $defaultmonth = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'm' );
337
- $defaultday = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'd' );
338
- $defaultyear = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'Y' );
339
- $defaulthour = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'H' );
340
- $defaultminute = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'i' );
341
- $enabled = ' checked="checked"';
342
- $disabled = '';
343
- $opts = get_post_meta( $post->ID, '_expiration-date-options', true );
344
- if ( isset( $opts['expireType'] ) ) {
345
- $expireType = $opts['expireType'];
346
- }
347
- $categories = isset( $opts['category'] ) ? $opts['category'] : false;
348
- }
349
-
350
- $rv = array();
351
- $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"' . $enabled . ' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />';
352
- $rv[] = '<label for="enable-expirationdate">' . __( 'Enable Post Expiration', 'post-expirator' ) . '</label></p>';
353
-
354
- if ( $default === 'publish' ) {
355
- $rv[] = '<em>' . __( 'The published date/time will be used as the expiration value', 'post-expirator' ) . '</em><br/>';
356
- } else {
357
- $rv[] = '<table><tr>';
358
- $rv[] = '<th style="text-align: left;">' . __( 'Year', 'post-expirator' ) . '</th>';
359
- $rv[] = '<th style="text-align: left;">' . __( 'Month', 'post-expirator' ) . '</th>';
360
- $rv[] = '<th style="text-align: left;">' . __( 'Day', 'post-expirator' ) . '</th>';
361
- $rv[] = '</tr><tr>';
362
- $rv[] = '<td>';
363
- $rv[] = '<select name="expirationdate_year" id="expirationdate_year"' . $disabled . '>';
364
- $currentyear = date( 'Y' );
365
-
366
- if ( $defaultyear < $currentyear ) {
367
- $currentyear = $defaultyear;
368
- }
369
-
370
- for ( $i = $currentyear; $i <= $currentyear + 10; $i++ ) {
371
- if ( $i === $defaultyear ) {
372
- $selected = ' selected="selected"';
373
- } else {
374
- $selected = '';
375
- }
376
- $rv[] = '<option' . $selected . '>' . ( $i ) . '</option>';
377
- }
378
- $rv[] = '</select>';
379
- $rv[] = '</td><td>';
380
- $rv[] = '<select name="expirationdate_month" id="expirationdate_month"' . $disabled . '>';
381
-
382
- for ( $i = 1; $i <= 12; $i++ ) {
383
- if ( $defaultmonth === date_i18n( 'm', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) ) {
384
- $selected = ' selected="selected"';
385
- } else {
386
- $selected = '';
387
- }
388
- $rv[] = '<option value="' . date_i18n( 'm', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) . '"' . $selected . '>' . date_i18n( 'F', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) . '</option>';
389
- }
390
-
391
- $rv[] = '</select>';
392
- $rv[] = '</td><td>';
393
- $rv[] = '<input type="text" id="expirationdate_day" name="expirationdate_day" value="' . $defaultday . '" size="2"' . $disabled . ' />,';
394
- $rv[] = '</td></tr><tr>';
395
- $rv[] = '<th style="text-align: left;"></th>';
396
- $rv[] = '<th style="text-align: left;">' . __( 'Hour', 'post-expirator' ) . '(' . date_i18n( 'T', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) . ')</th>';
397
- $rv[] = '<th style="text-align: left;">' . __( 'Minute', 'post-expirator' ) . '</th>';
398
- $rv[] = '</tr><tr>';
399
- $rv[] = '<td>@</td><td>';
400
- $rv[] = '<select name="expirationdate_hour" id="expirationdate_hour"' . $disabled . '>';
401
-
402
- for ( $i = 1; $i <= 24; $i++ ) {
403
- if ( $defaulthour === date_i18n( 'H', mktime( $i, 0, 0, date_i18n( 'n' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) ) ) {
404
- $selected = ' selected="selected"';
405
- } else {
406
- $selected = '';
407
- }
408
- $rv[] = '<option value="' . date_i18n( 'H', mktime( $i, 0, 0, date_i18n( 'n' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) ) . '"' . $selected . '>' . date_i18n( 'H', mktime( $i, 0, 0, date_i18n( 'n' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) ) . '</option>';
409
- }
410
-
411
- $rv[] = '</select></td><td>';
412
- $rv[] = '<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="' . $defaultminute . '" size="2"' . $disabled . ' />';
413
- $rv[] = '</td></tr></table>';
414
- }
415
- $rv[] = '<input type="hidden" name="expirationdate_formcheck" value="true" />';
416
- echo implode( "\n", $rv );
417
-
418
- echo '<br/>' . __( 'How to expire', 'post-expirator' ) . ': ';
419
- echo _postexpirator_expire_type( array('type' => $post->post_type, 'name' => 'expirationdate_expiretype', 'selected' => $expireType, 'disabled' => $disabled, 'onchange' => 'expirationdate_toggle_category(this)') );
420
- echo '<br/>';
421
-
422
- if ( $post->post_type !== 'page' ) {
423
- if ( isset( $expireType ) && ( $expireType === 'category' || $expireType === 'category-add' || $expireType === 'category-remove' ) ) {
424
- $catdisplay = 'block';
425
- } else {
426
- $catdisplay = 'none';
427
- }
428
- echo '<div id="expired-category-selection" style="display: ' . $catdisplay . '">';
429
- echo '<br/>' . __( 'Expiration Categories', 'post-expirator' ) . ':<br/>';
430
-
431
- echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
432
- echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
433
- $walker = new Walker_PostExpirator_Category_Checklist();
434
- if ( ! empty( $disabled ) ) {
435
- $walker->setDisabled();
436
- }
437
- $taxonomies = get_object_taxonomies( $post->post_type, 'object' );
438
- $taxonomies = wp_filter_object_list( $taxonomies, array('hierarchical' => true) );
439
- if ( sizeof( $taxonomies ) === 0 ) {
440
- echo '<p>' . __( 'You must assign a heirarchical taxonomy to this post type to use this feature.', 'post-expirator' ) . '</p>';
441
- } elseif ( sizeof( $taxonomies ) > 1 && ! isset( $defaults['taxonomy'] ) ) {
442
- echo '<p>' . __( 'More than 1 heirachical taxonomy detected. You must assign a default taxonomy on the settings screen.', 'post-expirator' ) . '</p>';
443
- } else {
444
- $keys = array_keys( $taxonomies );
445
- $taxonomy = isset( $defaults['taxonomy'] ) ? $defaults['taxonomy'] : $keys[0];
446
- wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
447
- echo '<input type="hidden" name="taxonomy-heirarchical" value="' . $taxonomy . '" />';
448
- }
449
- echo '</ul>';
450
- echo '</div>';
451
- if ( isset( $taxonomy ) ) {
452
- echo '<p class="post-expirator-taxonomy-name">' . __( 'Taxonomy Name', 'post-expirator' ) . ': ' . $taxonomy . '</p>';
453
- }
454
- echo '</div>';
455
- }
456
- echo '<div id="expirationdate_ajax_result"></div>';
457
- }
458
-
459
- /**
460
- * Add's ajax javascript.
461
- */
462
- function postexpirator_js_admin_header() {
463
- // Define custom JavaScript function
464
- ?>
465
- <script type="text/javascript">
466
- //<![CDATA[
467
- function expirationdate_ajax_add_meta(expireenable) {
468
- var expire = document.getElementById(expireenable);
469
-
470
- if (expire.checked == true) {
471
- var enable = 'true';
472
- if (document.getElementById('expirationdate_month')) {
473
- document.getElementById('expirationdate_month').disabled = false;
474
- document.getElementById('expirationdate_day').disabled = false;
475
- document.getElementById('expirationdate_year').disabled = false;
476
- document.getElementById('expirationdate_hour').disabled = false;
477
- document.getElementById('expirationdate_minute').disabled = false;
478
- }
479
- document.getElementById('expirationdate_expiretype').disabled = false;
480
- var cats = document.getElementsByName('expirationdate_category[]');
481
- var max = cats.length;
482
- for (var i=0; i<max; i++) {
483
- cats[i].disabled = '';
484
- }
485
- } else {
486
- if (document.getElementById('expirationdate_month')) {
487
- document.getElementById('expirationdate_month').disabled = true;
488
- document.getElementById('expirationdate_day').disabled = true;
489
- document.getElementById('expirationdate_year').disabled = true;
490
- document.getElementById('expirationdate_hour').disabled = true;
491
- document.getElementById('expirationdate_minute').disabled = true;
492
- }
493
- document.getElementById('expirationdate_expiretype').disabled = true;
494
- var cats = document.getElementsByName('expirationdate_category[]');
495
- var max = cats.length;
496
- for (var i=0; i<max; i++) {
497
- cats[i].disabled = 'disable';
498
- }
499
- var enable = 'false';
500
- }
501
- return true;
502
- }
503
- function expirationdate_toggle_category(id) {
504
- if (id.options[id.selectedIndex].value == 'category') {
505
- jQuery('#expired-category-selection').show();
506
- } else if (id.options[id.selectedIndex].value == 'category-add') {
507
- jQuery('#expired-category-selection').show(); //TEMP
508
- } else if (id.options[id.selectedIndex].value == 'category-remove') {
509
- jQuery('#expired-category-selection').show(); //TEMP
510
- } else {
511
- jQuery('#expired-category-selection').hide();
512
- }
513
- }
514
- function expirationdate_toggle_defaultdate(id) {
515
- if (id.options[id.selectedIndex].value == 'custom') {
516
- jQuery('#expired-custom-container').show();
517
- } else {
518
- jQuery('#expired-custom-container').hide();
519
- }
520
-
521
- }
522
- //]]>
523
- </script>
524
- <?php
525
- }
526
- add_action( 'admin_head', 'postexpirator_js_admin_header' );
527
-
528
- /**
529
- * Get correct URL (HTTP or HTTPS)
530
- */
531
- function expirationdate_get_blog_url() {
532
- if ( is_multisite() ) {
533
- echo network_home_url( '/' );
534
- } else {
535
- echo home_url( '/' );
536
- }
537
- }
538
-
539
- /**
540
- * Called when post is saved - stores expiration-date meta value
541
- */
542
- function postexpirator_update_post_meta( $id ) {
543
- // don't run the echo if this is an auto save
544
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
545
- return;
546
- }
547
-
548
- // don't run the echo if the function is called for saving revision.
549
- $posttype = get_post_type( $id );
550
- if ( $posttype === 'revision' ) {
551
- return;
552
- }
553
-
554
- if ( ! isset( $_POST['expirationdate_quickedit'] ) ) {
555
- if ( ! isset( $_POST['expirationdate_formcheck'] ) ) {
556
- return;
557
- }
558
- }
559
-
560
- if ( isset( $_POST['enable-expirationdate'] ) ) {
561
- $default = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
562
- if ( $default === 'publish' ) {
563
- $month = intval( $_POST['mm'] );
564
- $day = intval( $_POST['jj'] );
565
- $year = intval( $_POST['aa'] );
566
- $hour = intval( $_POST['hh'] );
567
- $minute = intval( $_POST['mn'] );
568
- } else {
569
- $month = intval( $_POST['expirationdate_month'] );
570
- $day = intval( $_POST['expirationdate_day'] );
571
- $year = intval( $_POST['expirationdate_year'] );
572
- $hour = intval( $_POST['expirationdate_hour'] );
573
- $minute = intval( $_POST['expirationdate_minute'] );
574
- }
575
- $category = isset( $_POST['expirationdate_category'] ) ? $_POST['expirationdate_category'] : 0;
576
-
577
- $ts = get_gmt_from_date( "$year-$month-$day $hour:$minute:0", 'U' );
578
-
579
- if ( isset( $_POST['expirationdate_quickedit'] ) ) {
580
- $ed = get_post_meta( $id, '_expiration-date', true );
581
- if ( $ed ) {
582
- $opts = get_post_meta( $id, '_expiration-date-options', true );
583
- }
584
- } else {
585
- $opts = array();
586
-
587
- // Schedule/Update Expiration
588
- $opts['expireType'] = $_POST['expirationdate_expiretype'];
589
- $opts['id'] = $id;
590
-
591
- if ( $opts['expireType'] === 'category' || $opts['expireType'] === 'category-add' || $opts['expireType'] === 'category-remove' ) {
592
- if ( isset( $category ) && ! empty( $category ) ) {
593
- if ( ! empty( $category ) ) {
594
- $opts['category'] = $category;
595
- $opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical'];
596
- }
597
- }
598
- }
599
- }
600
- postexpirator_schedule_event( $id, $ts, $opts );
601
- } else {
602
- postexpirator_unschedule_event( $id );
603
- }
604
- }
605
- add_action( 'save_post', 'postexpirator_update_post_meta' );
606
-
607
- /**
608
- * Schedules the single event.
609
- */
610
- function postexpirator_schedule_event( $id, $ts, $opts ) {
611
- $debug = postexpirator_debug(); // check for/load debug
612
-
613
- $id = intval( $id );
614
-
615
- do_action( 'postexpiratior_schedule', $id, $ts, $opts ); // allow custom actions
616
-
617
- if ( wp_next_scheduled( 'postExpiratorExpire', array($id) ) !== false ) {
618
- $error = wp_clear_scheduled_hook( 'postExpiratorExpire', array($id), true ); // Remove any existing hooks
619
- if ( POSTEXPIRATOR_DEBUG ) {
620
- $debug->save( array('message' => $id . ' -> EXISTING FOUND - UNSCHEDULED - ' . ( is_wp_error( $error ) ? $error->get_error_message() : 'no error' )) );
621
- }
622
- }
623
-
624
- $error = wp_schedule_single_event( $ts, 'postExpiratorExpire', array($id), true );
625
- if ( POSTEXPIRATOR_DEBUG ) {
626
- $debug->save( array('message' => $id . ' -> SCHEDULED at ' . date_i18n( 'r', $ts ) . ' ' . '(' . $ts . ') with options ' . print_r( $opts, true ) . ' ' . ( is_wp_error( $error ) ? $error->get_error_message() : 'no error' ) ) );
627
- }
628
-
629
- // Update Post Meta
630
- update_post_meta( $id, '_expiration-date', $ts );
631
- if ( ! is_null( $opts ) ) {
632
- update_post_meta( $id, '_expiration-date-options', $opts );
633
- }
634
- update_post_meta( $id, '_expiration-date-status', 'saved' );
635
- }
636
-
637
- /**
638
- * Unschedules the single event.
639
- */
640
- function postexpirator_unschedule_event( $id ) {
641
- $debug = postexpirator_debug(); // check for/load debug
642
-
643
- do_action( 'postexpiratior_unschedule', $id ); // allow custom actions
644
-
645
- delete_post_meta( $id, '_expiration-date' );
646
- delete_post_meta( $id, '_expiration-date-options' );
647
-
648
- // Delete Scheduled Expiration
649
- if ( wp_next_scheduled( 'postExpiratorExpire', array($id) ) !== false ) {
650
- wp_clear_scheduled_hook( 'postExpiratorExpire', array($id) ); // Remove any existing hooks
651
- if ( POSTEXPIRATOR_DEBUG ) {
652
- $debug->save( array('message' => $id . ' -> UNSCHEDULED') );
653
- }
654
- }
655
- update_post_meta( $id, '_expiration-date-status', 'saved' );
656
- }
657
-
658
- /**
659
- * The new expiration function, to work with single scheduled events.
660
- *
661
- * This was designed to hopefully be more flexible for future tweaks/modifications to the architecture.
662
- */
663
- function postexpirator_expire_post( $id ) {
664
- $debug = postexpirator_debug(); // check for/load debug
665
-
666
- if ( empty( $id ) ) {
667
- if ( POSTEXPIRATOR_DEBUG ) {
668
- $debug->save( array('message' => 'No Post ID found - exiting') );
669
- }
670
- return false;
671
- }
672
-
673
- if ( is_null( get_post( $id ) ) ) {
674
- if ( POSTEXPIRATOR_DEBUG ) {
675
- $debug->save( array('message' => $id . ' -> Post does not exist - exiting') );
676
- }
677
- return false;
678
- }
679
-
680
- $posttype = get_post_type( $id );
681
- $posttitle = get_the_title( $id );
682
- $postlink = get_post_permalink( $id );
683
-
684
- $postoptions = get_post_meta( $id, '_expiration-date-options', true );
685
- $expireType = $category = $categoryTaxonomy = null;
686
-
687
- if ( isset( $postoptions['expireType'] ) ) {
688
- $expireType = $postoptions['expireType'];
689
- }
690
-
691
- if ( isset( $postoptions['category'] ) ) {
692
- $category = $postoptions['category'];
693
- }
694
-
695
- if ( isset( $postoptions['categoryTaxonomy'] ) ) {
696
- $categoryTaxonomy = $postoptions['categoryTaxonomy'];
697
- }
698
-
699
- $ed = get_post_meta( $id, '_expiration-date', true );
700
-
701
- // Check for default expire only if not passed in
702
- if ( empty( $expireType ) ) {
703
- $posttype = get_post_type( $id );
704
- if ( $posttype === 'page' ) {
705
- $expireType = strtolower( get_option( 'expirationdateExpiredPageStatus', POSTEXPIRATOR_PAGESTATUS ) );
706
- } elseif ( $posttype === 'post' ) {
707
- $expireType = strtolower( get_option( 'expirationdateExpiredPostStatus', 'draft' ) );
708
- } else {
709
- $expireType = apply_filters( 'postexpirator_custom_posttype_expire', $expireType, $posttype ); // hook to set defaults for custom post types
710
- }
711
- }
712
-
713
- // Remove KSES - wp_cron runs as an unauthenticated user, which will by default trigger kses filtering,
714
- // even if the post was published by a admin user. It is fairly safe here to remove the filter call since
715
- // we are only changing the post status/meta information and not touching the content.
716
- kses_remove_filters();
717
-
718
- // Do Work
719
- if ( $expireType === 'draft' ) {
720
- if ( wp_update_post( array('ID' => $id, 'post_status' => 'draft') ) === 0 ) {
721
- if ( POSTEXPIRATOR_DEBUG ) {
722
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
723
- }
724
- } else {
725
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post status has been successfully changed to "%4$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', strtoupper( $expireType ) );
726
- if ( POSTEXPIRATOR_DEBUG ) {
727
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
728
- }
729
- }
730
- } elseif ( $expireType === 'private' ) {
731
- if ( wp_update_post( array('ID' => $id, 'post_status' => 'private') ) === 0 ) {
732
- if ( POSTEXPIRATOR_DEBUG ) {
733
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
734
- }
735
- } else {
736
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post status has been successfully changed to "%4$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', strtoupper( $expireType ) );
737
- if ( POSTEXPIRATOR_DEBUG ) {
738
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
739
- }
740
- }
741
- } elseif ( $expireType === 'delete' ) {
742
- if ( wp_delete_post( $id ) === false ) {
743
- if ( POSTEXPIRATOR_DEBUG ) {
744
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
745
- }
746
- } else {
747
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post status has been successfully changed to "%4$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', strtoupper( $expireType ) );
748
- if ( POSTEXPIRATOR_DEBUG ) {
749
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
750
- }
751
- }
752
- } elseif ( $expireType === 'trash' ) {
753
- if ( wp_trash_post( $id ) === false ) {
754
- if ( POSTEXPIRATOR_DEBUG ) {
755
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
756
- }
757
- } else {
758
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post status has been successfully changed to "%4$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', strtoupper( $expireType ) );
759
- if ( POSTEXPIRATOR_DEBUG ) {
760
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
761
- }
762
- }
763
- } elseif ( $expireType === 'stick' ) {
764
- if ( stick_post( $id ) === false ) {
765
- if ( POSTEXPIRATOR_DEBUG ) {
766
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
767
- }
768
- } else {
769
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post "%4$s" status has been successfully set.', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'STICKY' );
770
- if ( POSTEXPIRATOR_DEBUG ) {
771
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
772
- }
773
- }
774
- } elseif ( $expireType === 'unstick' ) {
775
- if ( unstick_post( $id ) === false ) {
776
- if ( POSTEXPIRATOR_DEBUG ) {
777
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
778
- }
779
- } else {
780
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post "%4$s" status has been successfully removed.', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'STICKY' );
781
- if ( POSTEXPIRATOR_DEBUG ) {
782
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
783
- }
784
- }
785
- } elseif ( $expireType === 'category' ) {
786
- if ( ! empty( $category ) ) {
787
- if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
788
- if ( wp_update_post( array('ID' => $id, 'post_category' => $category) ) === 0 ) {
789
- if ( POSTEXPIRATOR_DEBUG ) {
790
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
791
- }
792
- } else {
793
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post "%4$s" have now been set to "%5$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ) );
794
- if ( POSTEXPIRATOR_DEBUG ) {
795
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
796
- $debug->save( array('message' => $id . ' -> CATEGORIES REPLACED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
797
- $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
798
- }
799
- }
800
- } else {
801
- $terms = array_map( 'intval', $category );
802
- if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, false ) ) ) {
803
- if ( POSTEXPIRATOR_DEBUG ) {
804
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
805
- }
806
- } else {
807
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post "%4$s" have now been set to "%5$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ) );
808
- if ( POSTEXPIRATOR_DEBUG ) {
809
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
810
- $debug->save( array('message' => $id . ' -> CATEGORIES REPLACED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
811
- $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
812
- }
813
- }
814
- }
815
- } else {
816
- if ( POSTEXPIRATOR_DEBUG ) {
817
- $debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
818
- }
819
- }
820
- } elseif ( $expireType === 'category-add' ) {
821
- if ( ! empty( $category ) ) {
822
- if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
823
- $cats = wp_get_post_categories( $id );
824
- $merged = array_merge( $cats, $category );
825
- if ( wp_update_post( array('ID' => $id, 'post_category' => $merged) ) === 0 ) {
826
- if ( POSTEXPIRATOR_DEBUG ) {
827
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
828
- }
829
- } else {
830
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. The following post "%4$s" have now been added: "%5$s". The full list of categories on the post are: "%6$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ), implode( ',', _postexpirator_get_cat_names( $merged ) ) );
831
- if ( POSTEXPIRATOR_DEBUG ) {
832
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
833
- $debug->save( array('message' => $id . ' -> CATEGORIES ADDED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
834
- $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $merged ), true )) );
835
- }
836
- }
837
- } else {
838
- $terms = array_map( 'intval', $category );
839
- if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, true ) ) ) {
840
- if ( POSTEXPIRATOR_DEBUG ) {
841
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
842
- }
843
- } else {
844
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. The following post "%4$s" have now been added: "%5$s". The full list of categories on the post are: "%6$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ), implode( ',', _postexpirator_get_cat_names( $merged ) ) );
845
- if ( POSTEXPIRATOR_DEBUG ) {
846
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
847
- $debug->save( array('message' => $id . ' -> CATEGORIES ADDED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
848
- $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
849
- }
850
- }
851
- }
852
- } else {
853
- if ( POSTEXPIRATOR_DEBUG ) {
854
- $debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
855
- }
856
- }
857
- } elseif ( $expireType === 'category-remove' ) {
858
- if ( ! empty( $category ) ) {
859
- if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
860
- $cats = wp_get_post_categories( $id );
861
- $merged = array();
862
- foreach ( $cats as $cat ) {
863
- if ( ! in_array( $cat, $category, true ) ) {
864
- $merged[] = $cat;
865
- }
866
- }
867
- if ( wp_update_post( array('ID' => $id, 'post_category' => $merged) ) === 0 ) {
868
- if ( POSTEXPIRATOR_DEBUG ) {
869
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
870
- }
871
- } else {
872
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. The following post "%4$s" have now been removed: "%5$s". The full list of categories on the post are: "%6$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ), implode( ',', _postexpirator_get_cat_names( $merged ) ) );
873
- if ( POSTEXPIRATOR_DEBUG ) {
874
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
875
- $debug->save( array('message' => $id . ' -> CATEGORIES REMOVED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
876
- $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $merged ), true )) );
877
- }
878
- }
879
- } else {
880
- $terms = wp_get_object_terms( $id, $categoryTaxonomy, array('fields' => 'ids') );
881
- $merged = array();
882
- foreach ( $terms as $term ) {
883
- if ( ! in_array( $term, $category, true ) ) {
884
- $merged[] = $term;
885
- }
886
- }
887
- $terms = array_map( 'intval', $merged );
888
- if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, false ) ) ) {
889
- if ( POSTEXPIRATOR_DEBUG ) {
890
- $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
891
- }
892
- } else {
893
- $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. The following post "%4$s" have now been removed: "%5$s". The full list of categories on the post are: "%6$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ), implode( ',', _postexpirator_get_cat_names( $merged ) ) );
894
- if ( POSTEXPIRATOR_DEBUG ) {
895
- $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
896
- $debug->save( array('message' => $id . ' -> CATEGORIES REMOVED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
897
- $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
898
- }
899
- }
900
- }
901
- } else {
902
- if ( POSTEXPIRATOR_DEBUG ) {
903
- $debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
904
- }
905
- }
906
- }
907
-
908
- // Process Email
909
- $emailenabled = get_option( 'expirationdateEmailNotification', POSTEXPIRATOR_EMAILNOTIFICATION );
910
- // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
911
- if ( $emailenabled == 1 && isset( $emailBody ) ) {
912
- $subj = sprintf( __( 'Post Expiration Complete "%s"', 'post-expirator' ), $posttitle );
913
- $emailBody = str_replace( '##POSTTITLE##', $posttitle, $emailBody );
914
- $emailBody = str_replace( '##POSTLINK##', $postlink, $emailBody );
915
- $emailBody = str_replace( '##EXPIRATIONDATE##', get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ed ), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ), $emailBody );
916
-
917
- $emails = array();
918
- // Get Blog Admins
919
- $emailadmins = get_option( 'expirationdateEmailNotificationAdmins', POSTEXPIRATOR_EMAILNOTIFICATIONADMINS );
920
- // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
921
- if ( $emailadmins == 1 ) {
922
- $blogusers = get_users( 'role=Administrator' );
923
- foreach ( $blogusers as $user ) {
924
- $emails[] = $user->user_email;
925
- }
926
- }
927
-
928
- // Get Global Notification Emails
929
- $emaillist = get_option( 'expirationdateEmailNotificationList' );
930
- if ( ! empty( $emaillist ) ) {
931
- $vals = explode( ',', $emaillist );
932
- foreach ( $vals as $val ) {
933
- $emails[] = trim( $val );
934
- }
935
- }
936
-
937
- // Get Post Type Notification Emails
938
- $defaults = get_option( 'expirationdateDefaults' . ucfirst( $posttype ) );
939
- if ( isset( $defaults['emailnotification'] ) && ! empty( $defaults['emailnotification'] ) ) {
940
- $vals = explode( ',', $defaults['emailnotification'] );
941
- foreach ( $vals as $val ) {
942
- $emails[] = trim( $val );
943
- }
944
- }
945
-
946
- // Send Emails
947
- foreach ( $emails as $email ) {
948
- if ( wp_mail( $email, sprintf( __( '[%1$s] %2$s' ), get_option( 'blogname' ), $subj ), $emailBody ) ) {
949
- if ( POSTEXPIRATOR_DEBUG ) {
950
- $debug->save( array('message' => $id . ' -> EXPIRATION EMAIL SENT (' . $email . ')') );
951
- }
952
- } else {
953
- if ( POSTEXPIRATOR_DEBUG ) {
954
- $debug->save( array('message' => $id . ' -> EXPIRATION EMAIL FAILED (' . $email . ')') );
955
- }
956
- }
957
- }
958
- }
959
-
960
- }
961
- add_action( 'postExpiratorExpire', 'postexpirator_expire_post' );
962
-
963
- /**
964
- * Internal method to get category names corresponding to the category IDs.
965
- */
966
- function _postexpirator_get_cat_names( $cats ) {
967
- $out = array();
968
- foreach ( $cats as $cat ) {
969
- $out[ $cat ] = get_the_category_by_id( $cat );
970
- }
971
- return $out;
972
- }
973
-
974
- /**
975
- * Build the menu for the options page
976
- */
977
- function postexpirator_menu_tabs( $tab ) {
978
- echo '<p>';
979
- if ( empty( $tab ) ) {
980
- $tab = 'general';
981
- }
982
- echo '<a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=general' ) . '"' . ( $tab === 'general' ? ' style="font-weight: bold; text-decoration:none;"' : '' ) . '>' . __( 'General Settings', 'post-expirator' ) . '</a> | ';
983
- echo '<a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=defaults' ) . '"' . ( $tab === 'defaults' ? ' style="font-weight: bold; text-decoration:none;"' : '' ) . '>' . __( 'Defaults', 'post-expirator' ) . '</a> | ';
984
- echo '<a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=diagnostics' ) . '"' . ( $tab === 'diagnostics' ? ' style="font-weight: bold; text-decoration:none;"' : '' ) . '>' . __( 'Diagnostics', 'post-expirator' ) . '</a> | ';
985
- echo '<a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=viewdebug' ) . '"' . ( $tab === 'viewdebug' ? ' style="font-weight: bold; text-decoration:none;"' : '' ) . '>' . __( 'View Debug Logs', 'post-expirator' ) . '</a>';
986
- echo '</p><hr/>';
987
- }
988
-
989
- /**
990
- * Show the menu.
991
- */
992
- function postexpirator_menu() {
993
- $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : '';
994
-
995
- echo '<div class="wrap">';
996
- echo '<h2>' . __( 'Post Expirator Options', 'post-expirator' ) . '</h2>';
997
-
998
- postexpirator_menu_tabs( $tab );
999
- if ( empty( $tab ) || $tab === 'general' ) {
1000
- postexpirator_menu_general();
1001
- } elseif ( $tab === 'defaults' ) {
1002
- postexpirator_menu_defaults();
1003
- } elseif ( $tab === 'diagnostics' ) {
1004
- postexpirator_menu_diagnostics();
1005
- } elseif ( $tab === 'viewdebug' ) {
1006
- postexpirator_menu_debug();
1007
- }
1008
- echo '</div>';
1009
- }
1010
-
1011
- /**
1012
- * Hook's to add plugin page menu
1013
- */
1014
- function postexpirator_add_menu() {
1015
- add_submenu_page( 'options-general.php', __( 'Post Expirator Options', 'post-expirator' ), __( 'Post Expirator', 'post-expirator' ), 'manage_options', basename( __FILE__ ), 'postexpirator_menu' );
1016
- }
1017
- add_action( 'admin_menu', 'postexpirator_add_menu' );
1018
-
1019
- /**
1020
- * Show the Expiration Date options page
1021
- */
1022
- function postexpirator_menu_general() {
1023
- if ( isset( $_POST['expirationdateSave'] ) && $_POST['expirationdateSave'] ) {
1024
- if ( ! isset( $_POST['_postExpiratorMenuGeneral_nonce'] ) || ! wp_verify_nonce( $_POST['_postExpiratorMenuGeneral_nonce'], 'postexpirator_menu_general' ) ) {
1025
- print 'Form Validation Failure: Sorry, your nonce did not verify.';
1026
- exit;
1027
- } else {
1028
- // Filter Content
1029
- $_POST = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING );
1030
-
1031
- update_option( 'expirationdateDefaultDateFormat', $_POST['expired-default-date-format'] );
1032
- update_option( 'expirationdateDefaultTimeFormat', $_POST['expired-default-time-format'] );
1033
- update_option( 'expirationdateDisplayFooter', $_POST['expired-display-footer'] );
1034
- update_option( 'expirationdateEmailNotification', $_POST['expired-email-notification'] );
1035
- update_option( 'expirationdateEmailNotificationAdmins', $_POST['expired-email-notification-admins'] );
1036
- update_option( 'expirationdateEmailNotificationList', trim( $_POST['expired-email-notification-list'] ) );
1037
- update_option( 'expirationdateFooterContents', $_POST['expired-footer-contents'] );
1038
- update_option( 'expirationdateFooterStyle', $_POST['expired-footer-style'] );
1039
- if ( isset( $_POST['expirationdate_category'] ) ) {
1040
- update_option( 'expirationdateCategoryDefaults', $_POST['expirationdate_category'] );
1041
- }
1042
- update_option( 'expirationdateDefaultDate', $_POST['expired-default-expiration-date'] );
1043
- if ( $_POST['expired-custom-expiration-date'] ) {
1044
- update_option( 'expirationdateDefaultDateCustom', $_POST['expired-custom-expiration-date'] );
1045
- }
1046
- echo "<div id='message' class='updated fade'><p>";
1047
- _e( 'Saved Options!', 'post-expirator' );
1048
- echo '</p></div>';
1049
- }
1050
- }
1051
-
1052
- // phpcs:disable WordPress.NamingConventions.ValidVariableName.InterpolatedVariableNotSnakeCase
1053
- // phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
1054
-
1055
- // Get Option
1056
- $expirationdateDefaultDateFormat = get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT );
1057
- $expirationdateDefaultTimeFormat = get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT );
1058
- $expireddisplayfooter = get_option( 'expirationdateDisplayFooter', POSTEXPIRATOR_FOOTERDISPLAY );
1059
- $expiredemailnotification = get_option( 'expirationdateEmailNotification', POSTEXPIRATOR_EMAILNOTIFICATION );
1060
- $expiredemailnotificationadmins = get_option( 'expirationdateEmailNotificationAdmins', POSTEXPIRATOR_EMAILNOTIFICATIONADMINS );
1061
- $expiredemailnotificationlist = get_option( 'expirationdateEmailNotificationList', '' );
1062
- $expirationdateFooterContents = get_option( 'expirationdateFooterContents', POSTEXPIRATOR_FOOTERCONTENTS );
1063
- $expirationdateFooterStyle = get_option( 'expirationdateFooterStyle', POSTEXPIRATOR_FOOTERSTYLE );
1064
- $expirationdateDefaultDate = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
1065
- $expirationdateDefaultDateCustom = get_option( 'expirationdateDefaultDateCustom' );
1066
-
1067
- $categories = get_option( 'expirationdateCategoryDefaults' );
1068
-
1069
- $expireddisplayfooterenabled = '';
1070
- $expireddisplayfooterdisabled = '';
1071
- if ( $expireddisplayfooter == 0 ) {
1072
- $expireddisplayfooterdisabled = 'checked="checked"';
1073
- } elseif ( $expireddisplayfooter == 1 ) {
1074
- $expireddisplayfooterenabled = 'checked="checked"';
1075
- }
1076
-
1077
- $expiredemailnotificationenabled = '';
1078
- $expiredemailnotificationdisabled = '';
1079
- if ( $expiredemailnotification == 0 ) {
1080
- $expiredemailnotificationdisabled = 'checked="checked"';
1081
- } elseif ( $expiredemailnotification == 1 ) {
1082
- $expiredemailnotificationenabled = 'checked="checked"';
1083
- }
1084
-
1085
- $expiredemailnotificationadminsenabled = '';
1086
- $expiredemailnotificationadminsdisabled = '';
1087
- if ( $expiredemailnotificationadmins == 0 ) {
1088
- $expiredemailnotificationadminsdisabled = 'checked="checked"';
1089
- } elseif ( $expiredemailnotificationadmins == 1 ) {
1090
- $expiredemailnotificationadminsenabled = 'checked="checked"';
1091
- }
1092
- ?>
1093
- <p>
1094
- <?php _e( 'The post expirator plugin sets a custom meta value, and then optionally allows you to select if you want the post changed to a draft status or deleted when it expires.', 'post-expirator' ); ?>
1095
- </p>
1096
- <p>
1097
- <?php _e( 'Valid [postexpirator] attributes:', 'post-expirator' ); ?>
1098
- <ul>
1099
- <li><?php _e( 'type - defaults to full - valid options are full,date,time', 'post-expirator' ); ?></li>
1100
- <li><?php _e( 'dateformat - format set here will override the value set on the settings page', 'post-expirator' ); ?></li>
1101
- <li><?php _e( 'timeformat - format set here will override the value set on the settings page', 'post-expirator' ); ?></li>
1102
- </ul>
1103
- </p>
1104
- <form method="post" id="expirationdate_save_options">
1105
- <?php wp_nonce_field( 'postexpirator_menu_general', '_postExpiratorMenuGeneral_nonce' ); ?>
1106
- <h3><?php _e( 'Defaults', 'post-expirator' ); ?></h3>
1107
- <table class="form-table">
1108
- <tr valign="top">
1109
- <th scope="row"><label for="expired-default-date-format"><?php _e( 'Date Format:', 'post-expirator' ); ?></label></th>
1110
- <td>
1111
- <input type="text" name="expired-default-date-format" id="expired-default-date-format" value="<?php echo $expirationdateDefaultDateFormat; ?>" size="25" /> (<?php echo date_i18n( "$expirationdateDefaultDateFormat" ); ?>)
1112
- <br/>
1113
- <?php _e( 'The default format to use when displaying the expiration date within a post using the [postexpirator] shortcode or within the footer. For information on valid formatting options, see: <a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>.', 'post-expirator' ); ?>
1114
- </td>
1115
- </tr>
1116
- <tr valign="top">
1117
- <th scope="row"><label for="expired-default-time-format"><?php _e( 'Time Format:', 'post-expirator' ); ?></label></th>
1118
- <td>
1119
- <input type="text" name="expired-default-time-format" id="expired-default-time-format" value="<?php echo $expirationdateDefaultTimeFormat; ?>" size="25" /> (<?php echo date_i18n( "$expirationdateDefaultTimeFormat" ); ?>)
1120
- <br/>
1121
- <?php _e( 'The default format to use when displaying the expiration time within a post using the [postexpirator] shortcode or within the footer. For information on valid formatting options, see: <a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>.', 'post-expirator' ); ?>
1122
- </td>
1123
- </tr>
1124
- <tr valign="top">
1125
- <th scope="row"><label for="expired-default-expiration-date"><?php _e( 'Default Date/Time Duration:', 'post-expirator' ); ?></label></th>
1126
- <td>
1127
- <select name="expired-default-expiration-date" id="expired-default-expiration-date" onchange="expirationdate_toggle_defaultdate(this)">
1128
- <option value="null" <?php echo ( $expirationdateDefaultDate == 'null' ) ? ' selected="selected"' : ''; ?>><?php _e( 'None', 'post-expirator' ); ?></option>
1129
- <option value="custom" <?php echo ( $expirationdateDefaultDate == 'custom' ) ? ' selected="selected"' : ''; ?>><?php _e( 'Custom', 'post-expirator' ); ?></option>
1130
- <option value="publish" <?php echo ( $expirationdateDefaultDate == 'publish' ) ? ' selected="selected"' : ''; ?>><?php _e( 'Post/Page Publish Time', 'post-expirator' ); ?></option>
1131
- </select>
1132
- <br/>
1133
- <?php _e( 'Set the default expiration date to be used when creating new posts and pages. Defaults to none.', 'post-expirator' ); ?>
1134
- <?php $show = ( $expirationdateDefaultDate == 'custom' ) ? 'block' : 'none'; ?>
1135
- <div id="expired-custom-container" style="display: <?php echo $show; ?>;">
1136
- <br/><label for="expired-custom-expiration-date">Custom:</label> <input type="text" value="<?php echo $expirationdateDefaultDateCustom; ?>" name="expired-custom-expiration-date" id="expired-custom-expiration-date" />
1137
- <br/>
1138
- <?php _e( 'Set the custom value to use for the default expiration date. For information on formatting, see <a href="http://php.net/manual/en/function.strtotime.php">PHP strtotime function</a>. For example, you could enter "+1 month" or "+1 week 2 days 4 hours 2 seconds" or "next Thursday."', 'post-expirator' ); ?>
1139
- </div>
1140
- </td>
1141
- </tr>
1142
- </table>
1143
- <h3><?php _e( 'Category Expiration', 'post-expirator' ); ?></h3>
1144
- <table class="form-table">
1145
- <tr valign="top">
1146
- <th scope="row"><?php _e( 'Default Expiration Category', 'post-expirator' ); ?>:</th>
1147
- <td>
1148
- <?php
1149
- echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
1150
- echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
1151
- $walker = new Walker_PostExpirator_Category_Checklist();
1152
- wp_terms_checklist( 0, array( 'taxonomy' => 'category', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
1153
- echo '</ul>';
1154
- echo '</div>';
1155
- ?>
1156
- <br/>
1157
- <?php _e( "Set's the default expiration category for the post.", 'post-expirator' ); ?>
1158
- </td>
1159
- </tr>
1160
- </table>
1161
-
1162
- <h3><?php _e( 'Expiration Email Notification', 'post-expirator' ); ?></h3>
1163
- <p><?php _e( 'Whenever a post expires, an email can be sent to alert users of the expiration.', 'post-expirator' ); ?></p>
1164
- <table class="form-table">
1165
- <tr valign="top">
1166
- <th scope="row"><?php _e( 'Enable Email Notification?', 'post-expirator' ); ?></th>
1167
- <td>
1168
- <input type="radio" name="expired-email-notification" id="expired-email-notification-true" value="1" <?php echo $expiredemailnotificationenabled; ?>/> <label for="expired-email-notification-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
1169
- <br/>
1170
- <input type="radio" name="expired-email-notification" id="expired-email-notification-false" value="0" <?php echo $expiredemailnotificationdisabled; ?>/> <label for="expired-email-notification-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
1171
- <br/>
1172
- <?php _e( 'This will enable or disable the send of email notification on post expiration.', 'post-expirator' ); ?>
1173
- </td>
1174
- </tr>
1175
- <tr valign="top">
1176
- <th scope="row"><?php _e( 'Include Blog Administrators?', 'post-expirator' ); ?></th>
1177
- <td>
1178
- <input type="radio" name="expired-email-notification-admins" id="expired-email-notification-admins-true" value="1" <?php echo $expiredemailnotificationadminsenabled; ?>/> <label for="expired-email-notification-admins-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
1179
- <br/>
1180
- <input type="radio" name="expired-email-notification-admins" id="expired-email-notification-admins-false" value="0" <?php echo $expiredemailnotificationadminsdisabled; ?>/> <label for="expired-email-notification-admins-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
1181
- <br/>
1182
- <?php _e( 'This will include all users with the role of "Administrator" in the post expiration email.', 'post-expirator' ); ?>
1183
- </td>
1184
- </tr>
1185
- <tr valign="top">
1186
- <th scope="row"><label for="expired-email-notification-list"><?php _e( 'Who to notify:', 'post-expirator' ); ?></label></th>
1187
- <td>
1188
- <input class="large-text" type="text" name="expired-email-notification-list" id="expired-email-notification-list" value="<?php echo $expiredemailnotificationlist; ?>" />
1189
- <br/>
1190
- <?php _e( 'Enter a comma seperate list of emails that you would like to be notified when the post expires. This will be applied to ALL post types. You can set post type specific emails on the Defaults tab.', 'post-expirator' ); ?>
1191
- </td>
1192
- </tr>
1193
- </table>
1194
-
1195
- <h3><?php _e( 'Post Footer Display', 'post-expirator' ); ?></h3>
1196
- <p><?php _e( 'Enabling this below will display the expiration date automatically at the end of any post which is set to expire.', 'post-expirator' ); ?></p>
1197
- <table class="form-table">
1198
- <tr valign="top">
1199
- <th scope="row"><?php _e( 'Show in post footer?', 'post-expirator' ); ?></th>
1200
- <td>
1201
- <input type="radio" name="expired-display-footer" id="expired-display-footer-true" value="1" <?php echo $expireddisplayfooterenabled; ?>/> <label for="expired-display-footer-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
1202
- <br/>
1203
- <input type="radio" name="expired-display-footer" id="expired-display-footer-false" value="0" <?php echo $expireddisplayfooterdisabled; ?>/> <label for="expired-display-footer-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
1204
- <br/>
1205
- <?php _e( 'This will enable or disable displaying the post expiration date in the post footer.', 'post-expirator' ); ?>
1206
- </td>
1207
- </tr>
1208
- <tr valign="top">
1209
- <th scope="row"><label for="expired-footer-contents"><?php _e( 'Footer Contents:', 'post-expirator' ); ?></label></th>
1210
- <td>
1211
- <textarea id="expired-footer-contents" name="expired-footer-contents" rows="3" cols="50"><?php echo $expirationdateFooterContents; ?></textarea>
1212
- <br/>
1213
- <?php _e( 'Enter the text you would like to appear at the bottom of every post that will expire. The following placeholders will be replaced with the post expiration date in the following format:', 'post-expirator' ); ?>
1214
- <ul>
1215
- <li>EXPIRATIONFULL -> <?php echo date_i18n( "$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat" ); ?></li>
1216
- <li>EXPIRATIONDATE -> <?php echo date_i18n( "$expirationdateDefaultDateFormat" ); ?></li>
1217
- <li>EXPIRATIONTIME -> <?php echo date_i18n( "$expirationdateDefaultTimeFormat" ); ?></li>
1218
- </ul>
1219
- </td>
1220
- </tr>
1221
- <tr valign="top">
1222
- <th scope="row"><label for="expired-footer-style"><?php _e( 'Footer Style:', 'post-expirator' ); ?></label></th>
1223
- <td>
1224
- <input type="text" name="expired-footer-style" id="expired-footer-style" value="<?php echo $expirationdateFooterStyle; ?>" size="25" />
1225
- (<span style="<?php echo $expirationdateFooterStyle; ?>"><?php _e( 'This post will expire on', 'post-expirator' ); ?> <?php echo date_i18n( "$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat" ); ?></span>)
1226
- <br/>
1227
- <?php _e( 'The inline css which will be used to style the footer text.', 'post-expirator' ); ?>
1228
- </td>
1229
- </tr>
1230
- </table>
1231
- <p class="submit">
1232
- <input type="submit" name="expirationdateSave" class="button-primary" value="<?php _e( 'Save Changes', 'post-expirator' ); ?>" />
1233
- </p>
1234
- </form>
1235
- <?php
1236
- // phpcs:enable
1237
- }
1238
-
1239
- /**
1240
- * The default menu.
1241
- */
1242
- function postexpirator_menu_defaults() {
1243
- $debug = postexpirator_debug();
1244
- $types = get_post_types( array('public' => true, '_builtin' => false) );
1245
- array_unshift( $types, 'post', 'page' );
1246
-
1247
- if ( isset( $_POST['expirationdateSaveDefaults'] ) ) {
1248
- if ( ! isset( $_POST['_postExpiratorMenuDefaults_nonce'] ) || ! wp_verify_nonce( $_POST['_postExpiratorMenuDefaults_nonce'], 'postexpirator_menu_defaults' ) ) {
1249
- print 'Form Validation Failure: Sorry, your nonce did not verify.';
1250
- exit;
1251
- } else {
1252
- // Filter Content
1253
- $_POST = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING );
1254
-
1255
- $defaults = array();
1256
- foreach ( $types as $type ) {
1257
- if ( isset( $_POST[ 'expirationdate_expiretype-' . $type ] ) ) {
1258
- $defaults[ $type ]['expireType'] = $_POST[ 'expirationdate_expiretype-' . $type ];
1259
- }
1260
- if ( isset( $_POST[ 'expirationdate_autoenable-' . $type ] ) ) {
1261
- $defaults[ $type ]['autoEnable'] = intval( $_POST[ 'expirationdate_autoenable-' . $type ] );
1262
- }
1263
- if ( isset( $_POST[ 'expirationdate_taxonomy-' . $type ] ) ) {
1264
- $defaults[ $type ]['taxonomy'] = $_POST[ 'expirationdate_taxonomy-' . $type ];
1265
- }
1266
- if ( isset( $_POST[ 'expirationdate_activemeta-' . $type ] ) ) {
1267
- $defaults[ $type ]['activeMetaBox'] = $_POST[ 'expirationdate_activemeta-' . $type ];
1268
- }
1269
- $defaults[ $type ]['emailnotification'] = trim( $_POST[ 'expirationdate_emailnotification-' . $type ] );
1270
-
1271
- // Save Settings
1272
- update_option( 'expirationdateDefaults' . ucfirst( $type ), $defaults[ $type ] );
1273
- }
1274
- echo "<div id='message' class='updated fade'><p>";
1275
- _e( 'Saved Options!', 'post-expirator' );
1276
- echo '</p></div>';
1277
- }
1278
- }
1279
-
1280
- ?>
1281
- <form method="post">
1282
- <?php wp_nonce_field( 'postexpirator_menu_defaults', '_postExpiratorMenuDefaults_nonce' ); ?>
1283
- <h3><?php _e( 'Default Expiration Values', 'post-expirator' ); ?></h3>
1284
- <p>
1285
- <?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' ); ?>
1286
- </p>
1287
- <?php
1288
- foreach ( $types as $type ) {
1289
- echo "<fieldset style='border: 1px solid black; border-radius: 6px; padding: 0px 12px; margin-bottom: 20px;'>";
1290
- echo "<legend>Post Type: $type</legend>";
1291
- $defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
1292
-
1293
- // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1294
- if ( isset( $defaults['autoEnable'] ) && $defaults['autoEnable'] == 1 ) {
1295
- $expiredautoenabled = 'checked = "checked"';
1296
- $expiredautodisabled = '';
1297
- } else {
1298
- $expiredautoenabled = '';
1299
- $expiredautodisabled = 'checked = "checked"';
1300
- }
1301
- if ( isset( $defaults['activeMetaBox'] ) && $defaults['activeMetaBox'] === 'inactive' ) {
1302
- $expiredactivemetaenabled = '';
1303
- $expiredactivemetadisabled = 'checked = "checked"';
1304
- } else {
1305
- $expiredactivemetaenabled = 'checked = "checked"';
1306
- $expiredactivemetadisabled = '';
1307
- }
1308
- if ( ! isset( $defaults['taxonomy'] ) ) {
1309
- $defaults['taxonomy'] = false;
1310
- }
1311
- if ( ! isset( $defaults['emailnotification'] ) ) {
1312
- $defaults['emailnotification'] = '';
1313
- }
1314
- ?>
1315
- <table class="form-table">
1316
- <tr valign="top">
1317
- <th scope="row"><label for="expirationdate_activemeta-<?php echo $type; ?>"><?php _e( 'Active:', 'post-expirator' ); ?></label></th>
1318
- <td>
1319
- <input type="radio" name="expirationdate_activemeta-<?php echo $type; ?>" id="expirationdate_activemeta-true-<?php echo $type; ?>" value="active" <?php echo $expiredactivemetaenabled; ?>/> <label for="expired-active-meta-true"><?php _e( 'Active', 'post-expirator' ); ?></label>
1320
- <br/>
1321
- <input type="radio" name="expirationdate_activemeta-<?php echo $type; ?>" id="expirationdate_activemeta-false-<?php echo $type; ?>" value="inactive" <?php echo $expiredactivemetadisabled; ?>/> <label for="expired-active-meta-false"><?php _e( 'Inactive', 'post-expirator' ); ?></label>
1322
- <br/>
1323
- <?php _e( 'Select whether the post expirator meta box is active for this post type.', 'post-expirator' ); ?>
1324
- </td>
1325
- </tr>
1326
- <tr valign="top">
1327
- <th scope="row"><label for="expirationdate_expiretype-<?php echo $type; ?>"><?php _e( 'How to expire:', 'post-expirator' ); ?></label></th>
1328
- <td>
1329
- <?php echo _postexpirator_expire_type( array('name' => 'expirationdate_expiretype-' . $type, 'selected' => $defaults['expireType']) ); ?>
1330
- </select>
1331
- <br/>
1332
- <?php _e( 'Select the default expire action for the post type.', 'post-expirator' ); ?>
1333
- </td>
1334
- </tr>
1335
- <tr valign="top">
1336
- <th scope="row"><label for="expirationdate_autoenable-<?php echo $type; ?>"><?php _e( 'Auto-Enable?', 'post-expirator' ); ?></label></th>
1337
- <td>
1338
- <input type="radio" name="expirationdate_autoenable-<?php echo $type; ?>" id="expirationdate_autoenable-true-<?php echo $type; ?>" value="1" <?php echo $expiredautoenabled; ?>/> <label for="expired-auto-enable-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
1339
- <br/>
1340
- <input type="radio" name="expirationdate_autoenable-<?php echo $type; ?>" id="expirationdate_autoenable-false-<?php echo $type; ?>" value="0" <?php echo $expiredautodisabled; ?>/> <label for="expired-auto-enable-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
1341
- <br/>
1342
- <?php _e( 'Select whether the post expirator is enabled for all new posts.', 'post-expirator' ); ?>
1343
- </td>
1344
- </tr>
1345
- <tr valign="top">
1346
- <th scope="row"><label for="expirationdate_taxonomy-<?php echo $type; ?>"><?php _e( 'Taxonomy (hierarchical):', 'post-expirator' ); ?></label></th>
1347
- <td>
1348
- <?php echo _postexpirator_taxonomy( array('type' => $type, 'name' => 'expirationdate_taxonomy-' . $type, 'selected' => $defaults['taxonomy']) ); ?>
1349
- </td>
1350
- </tr>
1351
- <tr valign="top">
1352
- <th scope="row"><label for="expirationdate_emailnotification-<?php echo $type; ?>"><?php _e( 'Who to notify:', 'post-expirator' ); ?></label></th>
1353
- <td>
1354
- <input class="large-text" type="text" name="expirationdate_emailnotification-<?php echo $type; ?>" id="expirationdate_emailnotification-<?php echo $type; ?>" value="<?php echo $defaults['emailnotification']; ?>" />
1355
- <br/>
1356
- <?php _e( 'Enter a comma seperate list of emails that you would like to be notified when the post expires.', 'post-expirator' ); ?>
1357
- </td>
1358
- </tr>
1359
-
1360
- </table>
1361
- </fieldset>
1362
- <?php
1363
- }
1364
- ?>
1365
- <p class="submit">
1366
- <input type="submit" name="expirationdateSaveDefaults" class="button-primary" value="<?php _e( 'Save Changes', 'post-expirator' ); ?>" />
1367
- </p>
1368
- </form>
1369
- <?php
1370
- }
1371
-
1372
- /**
1373
- * Diagnostics menu.
1374
- */
1375
- function postexpirator_menu_diagnostics() {
1376
- if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
1377
- if ( ! isset( $_POST['_postExpiratorMenuDiagnostics_nonce'] ) || ! wp_verify_nonce( $_POST['_postExpiratorMenuDiagnostics_nonce'], 'postexpirator_menu_diagnostics' ) ) {
1378
- print 'Form Validation Failure: Sorry, your nonce did not verify.';
1379
- exit;
1380
- }
1381
- if ( isset( $_POST['debugging-disable'] ) ) {
1382
- update_option( 'expirationdateDebug', 0 );
1383
- echo "<div id='message' class='updated fade'><p>";
1384
- _e( 'Debugging Disabled', 'post-expirator' );
1385
- echo '</p></div>';
1386
- } elseif ( isset( $_POST['debugging-enable'] ) ) {
1387
- update_option( 'expirationdateDebug', 1 );
1388
- echo "<div id='message' class='updated fade'><p>";
1389
- _e( 'Debugging Enabled', 'post-expirator' );
1390
- echo '</p></div>';
1391
- } elseif ( isset( $_POST['purge-debug'] ) ) {
1392
- require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' );
1393
- $debug = new PostExpiratorDebug();
1394
- $debug->purge();
1395
- echo "<div id='message' class='updated fade'><p>";
1396
- _e( 'Debugging Table Emptied', 'post-expirator' );
1397
- echo '</p></div>';
1398
- }
1399
- }
1400
-
1401
- $debug = postexpirator_debug();
1402
- ?>
1403
- <form method="post" id="postExpiratorMenuUpgrade">
1404
- <?php wp_nonce_field( 'postexpirator_menu_diagnostics', '_postExpiratorMenuDiagnostics_nonce' ); ?>
1405
- <h3><?php _e( 'Advanced Diagnostics', 'post-expirator' ); ?></h3>
1406
- <table class="form-table">
1407
- <tr valign="top">
1408
- <th scope="row"><label for="postexpirator-log"><?php _e( 'Post Expirator Debug Logging:', 'post-expirator' ); ?></label></th>
1409
- <td>
1410
- <?php
1411
- if ( POSTEXPIRATOR_DEBUG ) {
1412
- echo __( 'Status: Enabled', 'post-expirator' ) . '<br/>';
1413
- echo '<input type="submit" class="button" name="debugging-disable" id="debugging-disable" value="' . __( 'Disable Debugging', 'post-expirator' ) . '" />';
1414
- } else {
1415
- echo __( 'Status: Disabled', 'post-expirator' ) . '<br/>';
1416
- echo '<input type="submit" class="button" name="debugging-enable" id="debugging-enable" value="' . __( 'Enable Debugging', 'post-expirator' ) . '" />';
1417
- }
1418
- ?>
1419
- <br/>
1420
- <a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=viewdebug' ); ?>">View Debug Logs</a>
1421
- </td>
1422
- </tr>
1423
- <tr valign="top">
1424
- <th scope="row"><?php _e( 'Purge Debug Log:', 'post-expirator' ); ?></th>
1425
- <td>
1426
- <input type="submit" class="button" name="purge-debug" id="purge-debug" value="<?php _e( 'Purge Debug Log', 'post-expirator' ); ?>" />
1427
- </td>
1428
- </tr/>
1429
- <tr valign="top">
1430
- <th scope="row"><?php _e( 'WP-Cron Status:', 'post-expirator' ); ?></th>
1431
- <td>
1432
- <?php
1433
- if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON === true ) {
1434
- _e( 'DISABLED', 'post-expirator' );
1435
- } else {
1436
- _e( 'ENABLED - OK', 'post-expirator' );
1437
- }
1438
- ?>
1439
- </td>
1440
- </tr/>
1441
- <tr valign="top">
1442
- <th scope="row"><label for="cron-schedule"><?php _e( 'Current Cron Schedule:', 'post-expirator' ); ?></label></th>
1443
- <td>
1444
- <?php _e( 'The below table will show all currently scheduled cron events with the next run time.', 'post-expirator' ); ?><br/>
1445
- <table>
1446
- <tr>
1447
- <th style="width: 200px;"><?php _e( 'Date', 'post-expirator' ); ?></th>
1448
- <th style="width: 200px;"><?php _e( 'Event', 'post-expirator' ); ?></th>
1449
- <th style="width: 500px;"><?php _e( 'Arguments / Schedule', 'post-expirator' ); ?></th>
1450
- </tr>
1451
- <?php
1452
- $cron = _get_cron_array();
1453
- foreach ( $cron as $key => $value ) {
1454
- foreach ( $value as $eventkey => $eventvalue ) {
1455
- print '<tr>';
1456
- print '<td>' . date_i18n( 'r', $key ) . '</td>';
1457
- print '<td>' . $eventkey . '</td>';
1458
- $arrkey = array_keys( $eventvalue );
1459
- print '<td>';
1460
- foreach ( $arrkey as $eventguid ) {
1461
- print '<table><tr>';
1462
- if ( empty( $eventvalue[ $eventguid ]['args'] ) ) {
1463
- print '<td>No Arguments</td>';
1464
- } else {
1465
- print '<td>';
1466
- $args = array();
1467
- foreach ( $eventvalue[ $eventguid ]['args'] as $key => $value ) {
1468
- $args[] = "$key => $value";
1469
- }
1470
- print implode( "<br/>\n", $args );
1471
- print '</td>';
1472
- }
1473
- if ( empty( $eventvalue[ $eventguid ]['schedule'] ) ) {
1474
- print '<td>' . __( 'Single Event', 'post-expirator' ) . '</td>';
1475
- } else {
1476
- print '<td>' . $eventvalue[ $eventguid ]['schedule'] . ' (' . $eventvalue[ $eventguid ]['interval'] . ')</td>';
1477
- }
1478
- print '</tr></table>';
1479
- }
1480
- print '</td>';
1481
- print '</tr>';
1482
- }
1483
- }
1484
- ?>
1485
- </table>
1486
- </td>
1487
- </tr>
1488
- </table>
1489
- </form>
1490
- <?php
1491
- }
1492
-
1493
- /**
1494
- * Debug menu.
1495
- */
1496
- function postexpirator_menu_debug() {
1497
- require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' );
1498
- print '<p>' . __( 'Below is a dump of the debugging table, this should be useful for troubleshooting.', 'post-expirator' ) . '</p>';
1499
- $debug = new PostExpiratorDebug();
1500
- $debug->getTable();
1501
- }
1502
-
1503
- /**
1504
- * Register the shortcode.
1505
- */
1506
- function postexpirator_shortcode( $atts ) {
1507
- global $post;
1508
-
1509
- $expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
1510
- if ( empty( $expirationdatets ) ) {
1511
- return false;
1512
- }
1513
-
1514
- // @TODO remove extract
1515
- // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1516
- extract(
1517
- shortcode_atts(
1518
- array(
1519
- 'dateformat' => get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT ),
1520
- 'timeformat' => get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT ),
1521
- 'type' => 'full',
1522
- 'tz' => date( 'T' ),
1523
- ), $atts
1524
- )
1525
- );
1526
-
1527
- if ( empty( $dateformat ) ) {
1528
- global $expirationdateDefaultDateFormat;
1529
- $dateformat = $expirationdateDefaultDateFormat;
1530
- }
1531
-
1532
- if ( empty( $timeformat ) ) {
1533
- global $expirationdateDefaultTimeFormat;
1534
- $timeformat = $expirationdateDefaultTimeFormat;
1535
- }
1536
-
1537
- if ( $type === 'full' ) {
1538
- $format = $dateformat . ' ' . $timeformat;
1539
- } elseif ( $type === 'date' ) {
1540
- $format = $dateformat;
1541
- } elseif ( $type === 'time' ) {
1542
- $format = $timeformat;
1543
- }
1544
-
1545
- return date_i18n( $format, $expirationdatets + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
1546
- }
1547
- add_shortcode( 'postexpirator', 'postexpirator_shortcode' );
1548
-
1549
- /**
1550
- * Add the footer.
1551
- */
1552
- function postexpirator_add_footer( $text ) {
1553
- global $post;
1554
-
1555
- // Check to see if its enabled
1556
- $displayFooter = get_option( 'expirationdateDisplayFooter' );
1557
-
1558
- // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1559
- if ( $displayFooter === false || $displayFooter == 0 ) {
1560
- return $text;
1561
- }
1562
-
1563
- $expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
1564
- if ( ! is_numeric( $expirationdatets ) ) {
1565
- return $text;
1566
- }
1567
-
1568
- $dateformat = get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT );
1569
- $timeformat = get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT );
1570
- $expirationdateFooterContents = get_option( 'expirationdateFooterContents', POSTEXPIRATOR_FOOTERCONTENTS );
1571
- $expirationdateFooterStyle = get_option( 'expirationdateFooterStyle', POSTEXPIRATOR_FOOTERSTYLE );
1572
-
1573
- $search = array(
1574
- 'EXPIRATIONFULL',
1575
- 'EXPIRATIONDATE',
1576
- 'EXPIRATIONTIME',
1577
- );
1578
- $replace = array(
1579
- get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), "$dateformat $timeformat" ),
1580
- get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), $dateformat ),
1581
- get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), $timeformat ),
1582
- );
1583
-
1584
- $add_to_footer = '<p style="' . $expirationdateFooterStyle . '">' . str_replace( $search, $replace, $expirationdateFooterContents ) . '</p>';
1585
- return $text . $add_to_footer;
1586
- }
1587
- add_action( 'the_content', 'postexpirator_add_footer', 0 );
1588
-
1589
- /**
1590
- * Check for Debug
1591
- */
1592
- function postexpirator_debug() {
1593
- $debug = get_option( 'expirationdateDebug' );
1594
- // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1595
- if ( $debug == 1 ) {
1596
- if ( ! defined( 'POSTEXPIRATOR_DEBUG' ) ) {
1597
- define( 'POSTEXPIRATOR_DEBUG', 1 );
1598
- }
1599
- require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' ); // Load Class
1600
- return new PostExpiratorDebug();
1601
- } else {
1602
- if ( ! defined( 'POSTEXPIRATOR_DEBUG' ) ) {
1603
- define( 'POSTEXPIRATOR_DEBUG', 0 );
1604
- }
1605
- return false;
1606
- }
1607
- }
1608
-
1609
-
1610
- /**
1611
- * Add Stylesheet
1612
- */
1613
- function postexpirator_css() {
1614
- $myStyleUrl = plugins_url( 'style.css', __FILE__ ); // Respects SSL, Style.css is relative to the current file
1615
- $myStyleFile = WP_PLUGIN_DIR . '/post-expirator/style.css';
1616
- if ( file_exists( $myStyleFile ) ) {
1617
- wp_register_style( 'postexpirator-css', $myStyleUrl );
1618
- wp_enqueue_style( 'postexpirator-css' );
1619
- }
1620
-
1621
- }
1622
- add_action( 'admin_init', 'postexpirator_css' );
1623
-
1624
- /**
1625
- * Post Expirator Activation/Upgrade
1626
- */
1627
- function postexpirator_upgrade() {
1628
-
1629
- // Check for current version, if not exists, run activation
1630
- $version = get_option( 'postexpiratorVersion' );
1631
- if ( $version === false ) { // not installed, run default activation
1632
- postexpirator_activate();
1633
- update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1634
- } else {
1635
- if ( version_compare( $version, '1.6.1' ) === -1 ) {
1636
- update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1637
- update_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
1638
- }
1639
-
1640
- if ( version_compare( $version, '1.6.2' ) === -1 ) {
1641
- update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1642
- }
1643
-
1644
- if ( version_compare( $version, '2.0.0-rc1' ) === -1 ) {
1645
- global $wpdb;
1646
-
1647
- // Schedule Events/Migrate Config
1648
- $results = $wpdb->get_results( $wpdb->prepare( 'select post_id, meta_value from ' . $wpdb->postmeta . ' as postmeta, ' . $wpdb->posts . ' as posts where postmeta.post_id = posts.ID AND postmeta.meta_key = %s AND postmeta.meta_value >= %d', 'expiration-date', time() ) );
1649
- foreach ( $results as $result ) {
1650
- wp_schedule_single_event( $result->meta_value, 'postExpiratorExpire', array($result->post_id) );
1651
- $opts = array();
1652
- $opts['id'] = $result->post_id;
1653
- $posttype = get_post_type( $result->post_id );
1654
- if ( $posttype === 'page' ) {
1655
- $opts['expireType'] = strtolower( get_option( 'expirationdateExpiredPageStatus', 'Draft' ) );
1656
- } else {
1657
- $opts['expireType'] = strtolower( get_option( 'expirationdateExpiredPostStatus', 'Draft' ) );
1658
- }
1659
-
1660
- $cat = get_post_meta( $result->post_id, '_expiration-date-category', true );
1661
- if ( ( isset( $cat ) && ! empty( $cat ) ) ) {
1662
- $opts['category'] = $cat;
1663
- $opts['expireType'] = 'category';
1664
- }
1665
- update_post_meta( $result->post_id, '_expiration-date-options', $opts );
1666
- }
1667
-
1668
- // update meta key to new format
1669
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_key = %s WHERE meta_key = %s", '_expiration-date', 'expiration-date' ) );
1670
-
1671
- // migrate defaults
1672
- $pagedefault = get_option( 'expirationdateExpiredPageStatus' );
1673
- $postdefault = get_option( 'expirationdateExpiredPostStatus' );
1674
- if ( $pagedefault ) {
1675
- update_option( 'expirationdateDefaultsPage', array('expireType' => $pagedefault) );
1676
- }
1677
- if ( $postdefault ) {
1678
- update_option( 'expirationdateDefaultsPost', array('expireType' => $postdefault) );
1679
- }
1680
-
1681
- delete_option( 'expirationdateCronSchedule' );
1682
- delete_option( 'expirationdateAutoEnabled' );
1683
- delete_option( 'expirationdateExpiredPageStatus' );
1684
- delete_option( 'expirationdateExpiredPostStatus' );
1685
- update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1686
- }
1687
-
1688
- if ( version_compare( $version, '2.0.1' ) === -1 ) {
1689
- // Forgot to do this in 2.0.0
1690
- if ( is_multisite() ) {
1691
- global $current_blog;
1692
- wp_clear_scheduled_hook( 'expirationdate_delete_' . $current_blog->blog_id );
1693
- } else {
1694
- wp_clear_scheduled_hook( 'expirationdate_delete' );
1695
- }
1696
-
1697
- update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1698
- }
1699
-
1700
- update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1701
-
1702
- }
1703
- }
1704
- add_action( 'admin_init', 'postexpirator_upgrade' );
1705
-
1706
- /**
1707
- * Called at plugin activation
1708
- */
1709
- function postexpirator_activate() {
1710
- if ( get_option( 'expirationdateDefaultDateFormat' ) === false ) {
1711
- update_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT );
1712
- }
1713
- if ( get_option( 'expirationdateDefaultTimeFormat' ) === false ) {
1714
- update_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT );
1715
- }
1716
- if ( get_option( 'expirationdateFooterContents' ) === false ) {
1717
- update_option( 'expirationdateFooterContents', POSTEXPIRATOR_FOOTERCONTENTS );
1718
- }
1719
- if ( get_option( 'expirationdateFooterStyle' ) === false ) {
1720
- update_option( 'expirationdateFooterStyle', POSTEXPIRATOR_FOOTERSTYLE );
1721
- }
1722
- if ( get_option( 'expirationdateDisplayFooter' ) === false ) {
1723
- update_option( 'expirationdateDisplayFooter', POSTEXPIRATOR_FOOTERDISPLAY );
1724
- }
1725
- if ( get_option( 'expirationdateDebug' ) === false ) {
1726
- update_option( 'expirationdateDebug', POSTEXPIRATOR_DEBUGDEFAULT );
1727
- }
1728
- if ( get_option( 'expirationdateDefaultDate' ) === false ) {
1729
- update_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
1730
- }
1731
- }
1732
-
1733
- /**
1734
- * Called at plugin deactivation
1735
- */
1736
- function expirationdate_deactivate() {
1737
- global $current_blog;
1738
- delete_option( 'expirationdateExpiredPostStatus' );
1739
- delete_option( 'expirationdateExpiredPageStatus' );
1740
- delete_option( 'expirationdateDefaultDateFormat' );
1741
- delete_option( 'expirationdateDefaultTimeFormat' );
1742
- delete_option( 'expirationdateDisplayFooter' );
1743
- delete_option( 'expirationdateFooterContents' );
1744
- delete_option( 'expirationdateFooterStyle' );
1745
- delete_option( 'expirationdateCategory' );
1746
- delete_option( 'expirationdateCategoryDefaults' );
1747
- delete_option( 'expirationdateDebug' );
1748
- delete_option( 'postexpiratorVersion' );
1749
- delete_option( 'expirationdateCronSchedule' );
1750
- delete_option( 'expirationdateDefaultDate' );
1751
- delete_option( 'expirationdateDefaultDateCustom' );
1752
- delete_option( 'expirationdateAutoEnabled' );
1753
- delete_option( 'expirationdateDefaultsPage' );
1754
- delete_option( 'expirationdateDefaultsPost' );
1755
- // what about custom post types? - how to cleanup?
1756
- if ( is_multisite() ) {
1757
- wp_clear_scheduled_hook( 'expirationdate_delete_' . $current_blog->blog_id );
1758
- } else {
1759
- wp_clear_scheduled_hook( 'expirationdate_delete' );
1760
- }
1761
- require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' );
1762
- $debug = new PostExpiratorDebug();
1763
- $debug->removeDbTable();
1764
- }
1765
- register_deactivation_hook( __FILE__, 'expirationdate_deactivate' );
1766
-
1767
- /**
1768
- * The walker class for category checklist.
1769
- */
1770
- class Walker_PostExpirator_Category_Checklist extends Walker {
1771
-
1772
- /**
1773
- * What the class handles.
1774
- *
1775
- * @var string
1776
- */
1777
- var $tree_type = 'category';
1778
-
1779
- /**
1780
- * DB fields to use.
1781
- *
1782
- * @var array
1783
- */
1784
- var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); // TODO: decouple this
1785
-
1786
- /**
1787
- * The disabled attribute.
1788
- *
1789
- * @var string
1790
- */
1791
- var $disabled = '';
1792
-
1793
- /**
1794
- * Set the disabled attribute.
1795
- */
1796
- function setDisabled() {
1797
- $this->disabled = 'disabled="disabled"';
1798
- }
1799
-
1800
- /**
1801
- * Starts the list before the elements are added.
1802
- *
1803
- * The $args parameter holds additional values that may be used with the child
1804
- * class methods. This method is called at the start of the output list.
1805
- *
1806
- * @param string $output Used to append additional content (passed by reference).
1807
- * @param int $depth Depth of the item.
1808
- * @param array $args An array of additional arguments.
1809
- */
1810
- function start_lvl( &$output, $depth = 0, $args = array() ) {
1811
- $indent = str_repeat( "\t", $depth );
1812
- $output .= "$indent<ul class='children'>\n";
1813
- }
1814
-
1815
- /**
1816
- * Ends the list of after the elements are added.
1817
- *
1818
- * The $args parameter holds additional values that may be used with the child
1819
- * class methods. This method finishes the list at the end of output of the elements.
1820
- *
1821
- * @param string $output Used to append additional content (passed by reference).
1822
- * @param int $depth Depth of the item.
1823
- * @param array $args An array of additional arguments.
1824
- */
1825
- function end_lvl( &$output, $depth = 0, $args = array() ) {
1826
- $indent = str_repeat( "\t", $depth );
1827
- $output .= "$indent</ul>\n";
1828
- }
1829
-
1830
- /**
1831
- * Start the element output.
1832
- *
1833
- * The $args parameter holds additional values that may be used with the child
1834
- * class methods. Includes the element output also.
1835
- *
1836
- * @param string $output Used to append additional content (passed by reference).
1837
- * @param object $category The data object.
1838
- * @param int $depth Depth of the item.
1839
- * @param array $args An array of additional arguments.
1840
- * @param int $current_object_id ID of the current item.
1841
- */
1842
- function start_el( &$output, $category, $depth = 0, $args = array(), $current_object_id = 0 ) {
1843
- // @TODO remove extract
1844
- // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1845
- extract( $args );
1846
- if ( empty( $taxonomy ) ) {
1847
- $taxonomy = 'category';
1848
- }
1849
-
1850
- $name = 'expirationdate_category';
1851
-
1852
- $class = in_array( $category->term_id, $popular_cats, true ) ? ' class="expirator-category"' : '';
1853
- $output .= "\n<li id='expirator-{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="expirator-in-' . $taxonomy . '-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats, true ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' ' . $this->disabled . '/> ' . esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
1854
- }
1855
-
1856
- /**
1857
- * Ends the element output, if needed.
1858
- *
1859
- * The $args parameter holds additional values that may be used with the child class methods.
1860
- *
1861
- * @param string $output Used to append additional content (passed by reference).
1862
- * @param object $category The data object.
1863
- * @param int $depth Depth of the item.
1864
- * @param array $args An array of additional arguments.
1865
- */
1866
- function end_el( &$output, $category, $depth = 0, $args = array() ) {
1867
- $output .= "</li>\n";
1868
- }
1869
- }
1870
-
1871
- /**
1872
- * Get the HTML for expire type.
1873
- */
1874
- function _postexpirator_expire_type( $opts ) {
1875
- if ( empty( $opts ) ) {
1876
- return false;
1877
- }
1878
-
1879
- // @TODO remove extract
1880
- // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1881
- extract( $opts );
1882
-
1883
- if ( ! isset( $name ) ) {
1884
- return false;
1885
- }
1886
- if ( ! isset( $id ) ) {
1887
- $id = $name;
1888
- }
1889
- if ( ! isset( $disabled ) ) {
1890
- $disabled = false;
1891
- }
1892
- if ( ! isset( $onchange ) ) {
1893
- $onchange = '';
1894
- }
1895
- if ( ! isset( $type ) ) {
1896
- $type = '';
1897
- }
1898
-
1899
- $rv = array();
1900
- // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1901
- $rv[] = '<select name="' . $name . '" id="' . $id . '"' . ( $disabled == true ? ' disabled="disabled"' : '' ) . ' onchange="' . $onchange . '">';
1902
- $rv[] = '<option value="draft" ' . ( $selected === 'draft' ? 'selected="selected"' : '' ) . '>' . __( 'Draft', 'post-expirator' ) . '</option>';
1903
- $rv[] = '<option value="delete" ' . ( $selected === 'delete' ? 'selected="selected"' : '' ) . '>' . __( 'Delete', 'post-expirator' ) . '</option>';
1904
- $rv[] = '<option value="trash" ' . ( $selected === 'trash' ? 'selected="selected"' : '' ) . '>' . __( 'Trash', 'post-expirator' ) . '</option>';
1905
- $rv[] = '<option value="private" ' . ( $selected === 'private' ? 'selected="selected"' : '' ) . '>' . __( 'Private', 'post-expirator' ) . '</option>';
1906
- $rv[] = '<option value="stick" ' . ( $selected === 'stick' ? 'selected="selected"' : '' ) . '>' . __( 'Stick', 'post-expirator' ) . '</option>';
1907
- $rv[] = '<option value="unstick" ' . ( $selected === 'unstick' ? 'selected="selected"' : '' ) . '>' . __( 'Unstick', 'post-expirator' ) . '</option>';
1908
- if ( $type !== 'page' ) {
1909
- $rv[] = '<option value="category" ' . ( $selected === 'category' ? 'selected="selected"' : '' ) . '>' . __( 'Category: Replace', 'post-expirator' ) . '</option>';
1910
- $rv[] = '<option value="category-add" ' . ( $selected === 'category-add' ? 'selected="selected"' : '' ) . '>' . __( 'Category: Add', 'post-expirator' ) . '</option>';
1911
- $rv[] = '<option value="category-remove" ' . ( $selected === 'category-remove' ? 'selected="selected"' : '' ) . '>' . __( 'Category: Remove', 'post-expirator' ) . '</option>';
1912
- }
1913
- $rv[] = '</select>';
1914
- return implode( "<br/>\n", $rv );
1915
- }
1916
-
1917
- /**
1918
- * Get the HTML for taxonomy.
1919
- */
1920
- function _postexpirator_taxonomy( $opts ) {
1921
- if ( empty( $opts ) ) {
1922
- return false;
1923
- }
1924
-
1925
- // @TODO remove extract
1926
- // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1927
- extract( $opts );
1928
- if ( ! isset( $name ) ) {
1929
- return false;
1930
- }
1931
- if ( ! isset( $id ) ) {
1932
- $id = $name;
1933
- }
1934
- if ( ! isset( $disabled ) ) {
1935
- $disabled = false;
1936
- }
1937
- if ( ! isset( $onchange ) ) {
1938
- $onchange = '';
1939
- }
1940
- if ( ! isset( $type ) ) {
1941
- $type = '';
1942
- }
1943
-
1944
- $taxonomies = get_object_taxonomies( $type, 'object' );
1945
- $taxonomies = wp_filter_object_list( $taxonomies, array('hierarchical' => true) );
1946
-
1947
- if ( empty( $taxonomies ) ) {
1948
- $disabled = true;
1949
- }
1950
-
1951
- $rv = array();
1952
- if ( $taxonomies ) {
1953
- // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1954
- $rv[] = '<select name="' . $name . '" id="' . $id . '"' . ( $disabled == true ? ' disabled="disabled"' : '' ) . ' onchange="' . $onchange . '">';
1955
- foreach ( $taxonomies as $taxonomy ) {
1956
- $rv[] = '<option value="' . $taxonomy->name . '" ' . ( $selected === $taxonomy->name ? 'selected="selected"' : '' ) . '>' . $taxonomy->name . '</option>';
1957
- }
1958
-
1959
- $rv[] = '</select>';
1960
- $rv[] = __( 'Select the hierarchical taxonomy to be used for "category" based expiration.', 'post-expirator' );
1961
- } else {
1962
- $rv[] = 'No taxonomies found for post type.';
1963
- }
1964
- return implode( "<br/>\n", $rv );
1965
- }
1966
-
1967
- /**
1968
- * Include the JS.
1969
- */
1970
- function postexpirator_quickedit_javascript() {
1971
- // if using code as plugin
1972
- wp_enqueue_script( 'manage-wp-posts-using-bulk-quick-edit', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'admin-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
1973
- wp_localize_script(
1974
- 'manage-wp-posts-using-bulk-quick-edit', 'config', array(
1975
- 'ajax' => array(
1976
- 'nonce' => wp_create_nonce( POSTEXPIRATOR_SLUG ),
1977
- 'bulk_edit' => 'manage_wp_posts_using_bulk_quick_save_bulk_edit',
1978
- ),
1979
- )
1980
- );
1981
- }
1982
- add_action( 'admin_print_scripts-edit.php', 'postexpirator_quickedit_javascript' );
1983
-
1984
- /**
1985
- Receieve AJAX call from bulk edit to process save
1986
- */
1987
- function postexpirator_date_save_bulk_edit() {
1988
- check_ajax_referer( POSTEXPIRATOR_SLUG, 'nonce' );
1989
-
1990
- // we need the post IDs
1991
- $post_ids = ( isset( $_POST['post_ids'] ) && ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : null;
1992
-
1993
- // if we have post IDs
1994
- if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
1995
-
1996
- // if no change, do nothing
1997
- if ( $_POST['expirationdate_month'] === 'false' ) {
1998
- return;
1999
- }
2000
-
2001
- $month = intval( $_POST['expirationdate_month'] );
2002
- $day = intval( $_POST['expirationdate_day'] );
2003
- $year = intval( $_POST['expirationdate_year'] );
2004
- $hour = intval( $_POST['expirationdate_hour'] );
2005
- $minute = intval( $_POST['expirationdate_minute'] );
2006
- $ts = get_gmt_from_date( "$year-$month-$day $hour:$minute:0", 'U' );
2007
-
2008
- if ( ! $ts ) {
2009
- return;
2010
- }
2011
-
2012
- foreach ( $post_ids as $post_id ) {
2013
- // Only update posts that already have expiration date set. Ignore Others
2014
- $ed = get_post_meta( $post_id, '_expiration-date', true );
2015
- if ( $ed ) {
2016
- update_post_meta( $post_id, '_expiration-date', $ts );
2017
- postexpirator_schedule_event( $post_id, $ts, null );
2018
- }
2019
- }
2020
- }
2021
- }
2022
- add_action( 'wp_ajax_manage_wp_posts_using_bulk_quick_save_bulk_edit', 'postexpirator_date_save_bulk_edit' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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.4.3
8
+ Author URI: http://postexpirator.tuxdocs.net/
9
+ Text Domain: post-expirator
10
+ Domain Path: /languages
11
+ */
12
+
13
+ // Default Values
14
+ define( 'POSTEXPIRATOR_VERSION', '2.4.3' );
15
+ define( 'POSTEXPIRATOR_DATEFORMAT', __( 'l F jS, Y', 'post-expirator' ) );
16
+ define( 'POSTEXPIRATOR_TIMEFORMAT', __( 'g:ia', 'post-expirator' ) );
17
+ define( 'POSTEXPIRATOR_FOOTERCONTENTS', __( 'Post expires at EXPIRATIONTIME on EXPIRATIONDATE', 'post-expirator' ) );
18
+ define( 'POSTEXPIRATOR_FOOTERSTYLE', 'font-style: italic;' );
19
+ define( 'POSTEXPIRATOR_FOOTERDISPLAY', '0' );
20
+ define( 'POSTEXPIRATOR_EMAILNOTIFICATION', '0' );
21
+ define( 'POSTEXPIRATOR_EMAILNOTIFICATIONADMINS', '0' );
22
+ define( 'POSTEXPIRATOR_DEBUGDEFAULT', '0' );
23
+ define( 'POSTEXPIRATOR_EXPIREDEFAULT', 'null' );
24
+ define( 'POSTEXPIRATOR_SLUG', 'post-expirator' );
25
+ define( 'POSTEXPIRATOR_BASEDIR', dirname( __FILE__ ) );
26
+ define( 'POSTEXPIRATOR_BASEURL', plugins_url( '/', __FILE__ ) );
27
+
28
+ require_once POSTEXPIRATOR_BASEDIR . '/functions.php';
29
+
30
+
31
+ /**
32
+ * Adds links to the plugin listing screen.
33
+ *
34
+ * @internal
35
+ *
36
+ * @access private
37
+ */
38
+ function postexpirator_plugin_action_links( $links, $file ) {
39
+ $this_plugin = basename( plugin_dir_url( __FILE__ ) ) . '/post-expirator.php';
40
+ if ( $file === $this_plugin ) {
41
+ $links[] = '<a href="options-general.php?page=post-expirator">' . __( 'Settings', 'post-expirator' ) . '</a>';
42
+ }
43
+ return $links;
44
+ }
45
+ add_filter( 'plugin_action_links', 'postexpirator_plugin_action_links', 10, 2 );
46
+
47
+ /**
48
+ * Load translation, if it exists.
49
+ *
50
+ * @internal
51
+ *
52
+ * @access private
53
+ */
54
+ function postexpirator_init() {
55
+ $plugin_dir = basename( dirname( __FILE__ ) );
56
+ load_plugin_textdomain( 'post-expirator', null, $plugin_dir . '/languages/' );
57
+ }
58
+ add_action( 'plugins_loaded', 'postexpirator_init' );
59
+
60
+ /**
61
+ * Adds an 'Expires' column to the post display table.
62
+ *
63
+ * @internal
64
+ *
65
+ * @access private
66
+ */
67
+ function postexpirator_add_column( $columns, $type ) {
68
+ $defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
69
+ if ( ! isset( $defaults['activeMetaBox'] ) || $defaults['activeMetaBox'] === 'active' ) {
70
+ $columns['expirationdate'] = __( 'Expires', 'post-expirator' );
71
+ }
72
+ return $columns;
73
+ }
74
+ add_filter( 'manage_posts_columns', 'postexpirator_add_column', 10, 2 );
75
+
76
+ /**
77
+ * Adds sortable columns.
78
+ *
79
+ * @internal
80
+ *
81
+ * @access private
82
+ */
83
+ function postexpirator_manage_sortable_columns() {
84
+ $post_types = get_post_types( array('public' => true) );
85
+ foreach ( $post_types as $post_type ) {
86
+ add_filter( 'manage_edit-' . $post_type . '_sortable_columns', 'postexpirator_sortable_column' );
87
+ }
88
+ }
89
+ add_action( 'init', 'postexpirator_manage_sortable_columns', 100 );
90
+
91
+ /**
92
+ * Adds an 'Expires' column to the post display table.
93
+ *
94
+ * @internal
95
+ *
96
+ * @access private
97
+ */
98
+ function postexpirator_sortable_column( $columns ) {
99
+ $columns['expirationdate'] = 'expirationdate';
100
+ return $columns;
101
+ }
102
+
103
+ /**
104
+ * Modify the sorting of posts.
105
+ *
106
+ * @internal
107
+ *
108
+ * @access private
109
+ */
110
+ function postexpirator_orderby( $query ) {
111
+ if ( ! is_admin() ) {
112
+ return;
113
+ }
114
+
115
+ $orderby = $query->get( 'orderby' );
116
+
117
+ if ( 'expirationdate' === $orderby ) {
118
+ $query->set(
119
+ 'meta_query', array(
120
+ 'relation' => 'OR',
121
+ array(
122
+ 'key' => '_expiration-date',
123
+ 'compare' => 'EXISTS',
124
+ ),
125
+ array(
126
+ 'key' => '_expiration-date',
127
+ 'compare' => 'NOT EXISTS',
128
+ 'value' => '',
129
+ ),
130
+ )
131
+ );
132
+ $query->set( 'orderby', 'meta_value_num' );
133
+ }
134
+ }
135
+ add_action( 'pre_get_posts', 'postexpirator_orderby' );
136
+
137
+ /**
138
+ * Adds an 'Expires' column to the page display table.
139
+ *
140
+ * @internal
141
+ *
142
+ * @access private
143
+ */
144
+ function postexpirator_add_column_page( $columns ) {
145
+ $defaults = get_option( 'expirationdateDefaultsPage' );
146
+ if ( ! isset( $defaults['activeMetaBox'] ) || $defaults['activeMetaBox'] === 'active' ) {
147
+ $columns['expirationdate'] = __( 'Expires', 'post-expirator' );
148
+ }
149
+ return $columns;
150
+ }
151
+ add_filter( 'manage_pages_columns', 'postexpirator_add_column_page' );
152
+
153
+ /**
154
+ * Fills the 'Expires' column of the post display table.
155
+ *
156
+ * @internal
157
+ *
158
+ * @access private
159
+ */
160
+ function postexpirator_show_value( $column_name ) {
161
+ global $post;
162
+ $id = $post->ID;
163
+ if ( $column_name === 'expirationdate' ) {
164
+ $display = __( 'Never', 'post-expirator' );
165
+ $ed = get_post_meta( $id, '_expiration-date', true );
166
+ if ( $ed ) {
167
+ $display = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $ed + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
168
+ }
169
+ echo $display;
170
+
171
+ // Values for Quick Edit
172
+ if ( $ed ) {
173
+ $date = gmdate( 'Y-m-d H:i:s', $ed );
174
+ $year = get_date_from_gmt( $date, 'Y' );
175
+ $month = get_date_from_gmt( $date, 'm' );
176
+ $day = get_date_from_gmt( $date, 'd' );
177
+ $hour = get_date_from_gmt( $date, 'H' );
178
+ $minute = get_date_from_gmt( $date, 'i' );
179
+ echo '<span id="expirationdate_year-' . $id . '" style="display: none;">' . $year . '</span>';
180
+ echo '<span id="expirationdate_month-' . $id . '" style="display: none;">' . $month . '</span>';
181
+ echo '<span id="expirationdate_day-' . $id . '" style="display: none;">' . $day . '</span>';
182
+ echo '<span id="expirationdate_hour-' . $id . '" style="display: none;">' . $hour . '</span>';
183
+ echo '<span id="expirationdate_minute-' . $id . '" style="display: none;">' . $minute . '</span>';
184
+ echo '<span id="expirationdate_enabled-' . $id . '" style="display: none;">true</span>';
185
+ } else {
186
+ echo '<span id="expirationdate_year-' . $id . '" style="display: none;">' . date( 'Y' ) . '</span>';
187
+ echo '<span id="expirationdate_month-' . $id . '" style="display: none;">' . date( 'm' ) . '</span>';
188
+ echo '<span id="expirationdate_day-' . $id . '" style="display: none;">' . date( 'd' ) . '</span>';
189
+ echo '<span id="expirationdate_hour-' . $id . '" style="display: none;">' . date( 'H' ) . '</span>';
190
+ echo '<span id="expirationdate_minute-' . $id . '" style="display: none;">' . date( 'i' ) . '</span>';
191
+ echo '<span id="expirationdate_enabled-' . $id . '" style="display: none;">false</span>';
192
+ }
193
+ }
194
+ }
195
+ add_action( 'manage_posts_custom_column', 'postexpirator_show_value' );
196
+ add_action( 'manage_pages_custom_column', 'postexpirator_show_value' );
197
+
198
+
199
+ /**
200
+ * Quick Edit functionality.
201
+ *
202
+ * @internal
203
+ *
204
+ * @access private
205
+ */
206
+ function postexpirator_quickedit( $column_name, $post_type ) {
207
+ if ( $column_name !== 'expirationdate' ) {
208
+ return;
209
+ }
210
+ ?>
211
+ <div style="clear:both"></div>
212
+ <fieldset class="inline-edit-col-left post-expirator-quickedit">
213
+ <div class="inline-edit-col">
214
+ <div class="inline-edit-group">
215
+ <span class="title"><?php _e( 'Post Expirator', 'post-expirator' ); ?></span>
216
+ <p><input name="enable-expirationdate" type="checkbox" /><span class="title"><?php _e( 'Enable Post Expiration', 'post-expirator' ); ?></span></p>
217
+ <fieldset class="inline-edit-date">
218
+ <legend><span class="title"><?php _e( 'Expires', 'post-expirator' ); ?></span></legend>
219
+ <div class="timestamp-wrap">
220
+ <label>
221
+ <span class="screen-reader-text"><?php _e( 'Month', 'post-expirator' ); ?></span>
222
+ <select name="expirationdate_month">
223
+ <?php
224
+ for ( $x = 1; $x <= 12; $x++ ) {
225
+ $now = mktime( 0, 0, 0, $x, 1, date_i18n( 'Y' ) );
226
+ $monthNumeric = date_i18n( 'm', $now );
227
+ $monthStr = date_i18n( 'M', $now );
228
+ ?>
229
+ <option value="<?php echo $monthNumeric; ?>" data-text="<?php echo $monthStr; ?>"><?php echo $monthNumeric; ?>-<?php echo $monthStr; ?></option>
230
+ <?php } ?>
231
+
232
+ </select>
233
+ </label>
234
+ <label>
235
+ <span class="screen-reader-text"><?php _e( 'Day', 'post-expirator' ); ?></span>
236
+ <input name="expirationdate_day" value="" size="2" maxlength="2" autocomplete="off" type="text" placeholder="<?php echo date( 'd' ); ?>">
237
+ </label>,
238
+ <label>
239
+ <span class="screen-reader-text"><?php _e( 'Year', 'post-expirator' ); ?></span>
240
+ <input name="expirationdate_year" value="" size="4" maxlength="4" autocomplete="off" type="text" placeholder="<?php echo date( 'Y' ); ?>">
241
+ </label> @
242
+ <label>
243
+ <span class="screen-reader-text"><?php _e( 'Hour', 'post-expirator' ); ?></span>
244
+ <input name="expirationdate_hour" value="" size="2" maxlength="2" autocomplete="off" type="text" placeholder="00">
245
+ </label> :
246
+ <label>
247
+ <span class="screen-reader-text"><?php _e( 'Minute', 'post-expirator' ); ?></span>
248
+ <input name="expirationdate_minute" value="" size="2" maxlength="2" autocomplete="off" type="text" placeholder="00">
249
+ </label>
250
+ </div>
251
+ <input name="expirationdate_quickedit" value="true" type="hidden"/>
252
+ </fieldset>
253
+ </div>
254
+ </div>
255
+ </fieldset>
256
+ <?php
257
+
258
+ }
259
+ add_action( 'quick_edit_custom_box', 'postexpirator_quickedit', 10, 2 );
260
+
261
+ /**
262
+ * Bulk Edit functionality.
263
+ *
264
+ * @internal
265
+ *
266
+ * @access private
267
+ */
268
+ function postexpirator_bulkedit( $column_name, $post_type ) {
269
+ if ( $column_name !== 'expirationdate' ) {
270
+ return;
271
+ }
272
+ ?>
273
+ <div style="clear:both"></div>
274
+ <div class="inline-edit-col post-expirator-quickedit">
275
+ <div class="inline-edit-col">
276
+ <div class="inline-edit-group">
277
+ <legend class="inline-edit-legend"><?php _e( 'Post Expirator', 'post-expirator' ); ?></legend>
278
+ <fieldset class="inline-edit-date">
279
+ <legend><span class="title"><?php _e( 'Expires', 'post-expirator' ); ?></span></legend>
280
+ <div class="timestamp-wrap">
281
+ <label>
282
+ <span class="screen-reader-text"><?php _e( 'Enable Post Expiration', 'post-expirator' ); ?></span>
283
+ <select name="expirationdate_status">
284
+ <option value="no-change" data-show-fields="false" selected>--<?php _e( 'No Change', 'post-expirator' ); ?>--</option>
285
+ <option value="change-only" data-show-fields="true" title="<?php _e( 'Change expiry date if enabled on posts', 'post-expirator' ); ?>"><?php _e( 'Change on posts', 'post-expirator' ); ?></option>
286
+ <option value="add-only" data-show-fields="true" title="<?php _e( 'Add expiry date if not enabled on posts', 'post-expirator' ); ?>"><?php _e( 'Add to posts', 'post-expirator' ); ?></option>
287
+ <option value="change-add" data-show-fields="true"><?php _e( 'Change & Add', 'post-expirator' ); ?></option>
288
+ <option value="remove-only" data-show-fields="false"><?php _e( 'Remove from posts', 'post-expirator' ); ?></option>
289
+ </select>
290
+ </label>
291
+ <span class="post-expirator-date-fields">
292
+ <label>
293
+ <span class="screen-reader-text"><?php _e( 'Month', 'post-expirator' ); ?></span>
294
+ <select name="expirationdate_month">
295
+ <?php
296
+ for ( $x = 1; $x <= 12; $x++ ) {
297
+ $now = mktime( 0, 0, 0, $x, 1, date_i18n( 'Y' ) );
298
+ $monthNumeric = date_i18n( 'm', $now );
299
+ $monthStr = date_i18n( 'M', $now );
300
+ ?>
301
+ <option value="<?php echo $monthNumeric; ?>" data-text="<?php echo $monthStr; ?>"><?php echo $monthNumeric; ?>-<?php echo $monthStr; ?></option>
302
+ <?php } ?>
303
+
304
+ </select>
305
+ </label>
306
+ <label>
307
+ <span class="screen-reader-text"><?php _e( 'Day', 'post-expirator' ); ?></span>
308
+ <input name="expirationdate_day" placeholder="<?php echo date( 'd' ); ?>" value="" size="2" maxlength="2" autocomplete="off" type="text">
309
+ </label>,
310
+ <label>
311
+ <span class="screen-reader-text"><?php _e( 'Year', 'post-expirator' ); ?></span>
312
+ <input name="expirationdate_year" placeholder="<?php echo date( 'Y' ); ?>" value="" size="4" maxlength="4" autocomplete="off" type="text">
313
+ </label> @
314
+ <label>
315
+ <span class="screen-reader-text"><?php _e( 'Hour', 'post-expirator' ); ?></span>
316
+ <input name="expirationdate_hour" placeholder="00" value="" size="2" maxlength="2" autocomplete="off" type="text">
317
+ </label> :
318
+ <label>
319
+ <span class="screen-reader-text"><?php _e( 'Minute', 'post-expirator' ); ?></span>
320
+ <input name="expirationdate_minute" placeholder="00" value="" size="2" maxlength="2" autocomplete="off" type="text">
321
+ </label>
322
+ </span>
323
+ </div>
324
+ <input name="expirationdate_quickedit" value="true" type="hidden"/>
325
+ </fieldset>
326
+ </div>
327
+ </div>
328
+ </div>
329
+ <?php
330
+
331
+ }
332
+ add_action( 'bulk_edit_custom_box', 'postexpirator_bulkedit', 10, 2 );
333
+
334
+ /**
335
+ * Adds hooks to get the meta box added to pages and custom post types
336
+ *
337
+ * @internal
338
+ *
339
+ * @access private
340
+ */
341
+ function postexpirator_meta_custom() {
342
+ $custom_post_types = get_post_types();
343
+ array_push( $custom_post_types, 'page' );
344
+ foreach ( $custom_post_types as $t ) {
345
+ $defaults = get_option( 'expirationdateDefaults' . ucfirst( $t ) );
346
+ if ( ! isset( $defaults['activeMetaBox'] ) || $defaults['activeMetaBox'] === 'active' ) {
347
+ add_meta_box( 'expirationdatediv', __( 'Post Expirator', 'post-expirator' ), 'postexpirator_meta_box', $t, 'side', 'core' );
348
+ }
349
+ }
350
+ }
351
+ add_action( 'add_meta_boxes', 'postexpirator_meta_custom' );
352
+
353
+ /**
354
+ * Actually adds the meta box
355
+ *
356
+ * @internal
357
+ *
358
+ * @access private
359
+ */
360
+ function postexpirator_meta_box( $post ) {
361
+ // Get default month
362
+ $expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
363
+ $firstsave = get_post_meta( $post->ID, '_expiration-date-status', true );
364
+
365
+ // nonce
366
+ wp_nonce_field( '__postexpirator', '_postexpiratornonce' );
367
+
368
+ $default = '';
369
+ $expireType = '';
370
+ $defaults = get_option( 'expirationdateDefaults' . ucfirst( $post->post_type ) );
371
+ if ( empty( $expirationdatets ) ) {
372
+ $default = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
373
+ if ( $default === 'null' ) {
374
+ $defaultmonth = date_i18n( 'm' );
375
+ $defaultday = date_i18n( 'd' );
376
+ $defaulthour = date_i18n( 'H' );
377
+ $defaultyear = date_i18n( 'Y' );
378
+ $defaultminute = date_i18n( 'i' );
379
+
380
+ } elseif ( $default === 'custom' ) {
381
+ $custom = get_option( 'expirationdateDefaultDateCustom' );
382
+ if ( $custom === false ) {
383
+ $ts = time();
384
+ } else {
385
+ $tz = get_option( 'timezone_string' );
386
+ if ( $tz ) {
387
+ // @TODO Using date_default_timezone_set() and similar isn't allowed, instead use WP internal timezone support.
388
+ // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
389
+ date_default_timezone_set( $tz );
390
+ }
391
+
392
+ // strip the quotes in case the user provides them.
393
+ $custom = str_replace( '"', '', html_entity_decode( $custom, ENT_QUOTES ) );
394
+
395
+ $ts = time() + ( strtotime( $custom ) - time() );
396
+ if ( $tz ) {
397
+ // @TODO Using date_default_timezone_set() and similar isn't allowed, instead use WP internal timezone support.
398
+ // phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set
399
+ date_default_timezone_set( 'UTC' );
400
+ }
401
+ }
402
+ $defaultmonth = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'm' );
403
+ $defaultday = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'd' );
404
+ $defaultyear = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'Y' );
405
+ $defaulthour = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'H' );
406
+ $defaultminute = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'i' );
407
+ }
408
+
409
+ $enabled = '';
410
+ $disabled = ' disabled="disabled"';
411
+ $categories = get_option( 'expirationdateCategoryDefaults' );
412
+
413
+ if ( isset( $defaults['expireType'] ) ) {
414
+ $expireType = $defaults['expireType'];
415
+ }
416
+
417
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
418
+ if ( isset( $defaults['autoEnable'] ) && ( $firstsave !== 'saved' ) && ( $defaults['autoEnable'] === true || $defaults['autoEnable'] == 1 ) ) {
419
+ $enabled = ' checked="checked"';
420
+ $disabled = '';
421
+ }
422
+ } else {
423
+ $defaultmonth = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'm' );
424
+ $defaultday = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'd' );
425
+ $defaultyear = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'Y' );
426
+ $defaulthour = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'H' );
427
+ $defaultminute = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'i' );
428
+ $enabled = ' checked="checked"';
429
+ $disabled = '';
430
+ $opts = get_post_meta( $post->ID, '_expiration-date-options', true );
431
+ if ( isset( $opts['expireType'] ) ) {
432
+ $expireType = $opts['expireType'];
433
+ }
434
+ $categories = isset( $opts['category'] ) ? $opts['category'] : false;
435
+ }
436
+
437
+ $rv = array();
438
+ $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"' . $enabled . ' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />';
439
+ $rv[] = '<label for="enable-expirationdate">' . __( 'Enable Post Expiration', 'post-expirator' ) . '</label></p>';
440
+
441
+ if ( $default === 'publish' ) {
442
+ $rv[] = '<em>' . __( 'The published date/time will be used as the expiration value', 'post-expirator' ) . '</em><br/>';
443
+ } else {
444
+ $rv[] = '<table><tr>';
445
+ $rv[] = '<th style="text-align: left;">' . __( 'Year', 'post-expirator' ) . '</th>';
446
+ $rv[] = '<th style="text-align: left;">' . __( 'Month', 'post-expirator' ) . '</th>';
447
+ $rv[] = '<th style="text-align: left;">' . __( 'Day', 'post-expirator' ) . '</th>';
448
+ $rv[] = '</tr><tr>';
449
+ $rv[] = '<td>';
450
+ $rv[] = '<select name="expirationdate_year" id="expirationdate_year"' . $disabled . '>';
451
+ $currentyear = date( 'Y' );
452
+
453
+ if ( $defaultyear < $currentyear ) {
454
+ $currentyear = $defaultyear;
455
+ }
456
+
457
+ for ( $i = $currentyear; $i <= $currentyear + 10; $i++ ) {
458
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
459
+ if ( $i == $defaultyear ) {
460
+ $selected = ' selected="selected"';
461
+ } else {
462
+ $selected = '';
463
+ }
464
+ $rv[] = '<option' . $selected . '>' . ( $i ) . '</option>';
465
+ }
466
+ $rv[] = '</select>';
467
+ $rv[] = '</td><td>';
468
+ $rv[] = '<select name="expirationdate_month" id="expirationdate_month"' . $disabled . '>';
469
+
470
+ for ( $i = 1; $i <= 12; $i++ ) {
471
+ if ( $defaultmonth === date_i18n( 'm', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) ) {
472
+ $selected = ' selected="selected"';
473
+ } else {
474
+ $selected = '';
475
+ }
476
+ $rv[] = '<option value="' . date_i18n( 'm', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) . '"' . $selected . '>' . date_i18n( 'F', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) . '</option>';
477
+ }
478
+
479
+ $rv[] = '</select>';
480
+ $rv[] = '</td><td>';
481
+ $rv[] = '<input type="text" id="expirationdate_day" name="expirationdate_day" value="' . $defaultday . '" size="2"' . $disabled . ' />,';
482
+ $rv[] = '</td></tr><tr>';
483
+ $rv[] = '<th style="text-align: left;"></th>';
484
+ $rv[] = '<th style="text-align: left;">' . __( 'Hour', 'post-expirator' ) . '(' . date_i18n( 'T', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) . ')</th>';
485
+ $rv[] = '<th style="text-align: left;">' . __( 'Minute', 'post-expirator' ) . '</th>';
486
+ $rv[] = '</tr><tr>';
487
+ $rv[] = '<td>@</td><td>';
488
+ $rv[] = '<select name="expirationdate_hour" id="expirationdate_hour"' . $disabled . '>';
489
+
490
+ for ( $i = 1; $i <= 24; $i++ ) {
491
+ if ( $defaulthour === date_i18n( 'H', mktime( $i, 0, 0, date_i18n( 'n' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) ) ) {
492
+ $selected = ' selected="selected"';
493
+ } else {
494
+ $selected = '';
495
+ }
496
+ $rv[] = '<option value="' . date_i18n( 'H', mktime( $i, 0, 0, date_i18n( 'n' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) ) . '"' . $selected . '>' . date_i18n( 'H', mktime( $i, 0, 0, date_i18n( 'n' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) ) . '</option>';
497
+ }
498
+
499
+ $rv[] = '</select></td><td>';
500
+ $rv[] = '<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="' . $defaultminute . '" size="2"' . $disabled . ' />';
501
+ $rv[] = '</td></tr></table>';
502
+ }
503
+ $rv[] = '<input type="hidden" name="expirationdate_formcheck" value="true" />';
504
+ echo implode( "\n", $rv );
505
+
506
+ echo '<br/>' . __( 'How to expire', 'post-expirator' ) . ': ';
507
+ echo _postexpirator_expire_type( array('type' => $post->post_type, 'name' => 'expirationdate_expiretype', 'selected' => $expireType, 'disabled' => $disabled, 'onchange' => 'expirationdate_toggle_category(this)') );
508
+ echo '<br/>';
509
+
510
+ if ( $post->post_type !== 'page' ) {
511
+ if ( isset( $expireType ) && ( $expireType === 'category' || $expireType === 'category-add' || $expireType === 'category-remove' ) ) {
512
+ $catdisplay = 'block';
513
+ } else {
514
+ $catdisplay = 'none';
515
+ }
516
+ echo '<div id="expired-category-selection" style="display: ' . $catdisplay . '">';
517
+ echo '<br/>' . __( 'Expiration Categories', 'post-expirator' ) . ':<br/>';
518
+
519
+ echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
520
+ echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
521
+ $walker = new Walker_PostExpirator_Category_Checklist();
522
+ if ( ! empty( $disabled ) ) {
523
+ $walker->setDisabled();
524
+ }
525
+ $taxonomies = get_object_taxonomies( $post->post_type, 'object' );
526
+ $taxonomies = wp_filter_object_list( $taxonomies, array('hierarchical' => true) );
527
+ if ( sizeof( $taxonomies ) === 0 ) {
528
+ echo '<p>' . __( 'You must assign a heirarchical taxonomy to this post type to use this feature.', 'post-expirator' ) . '</p>';
529
+ } elseif ( sizeof( $taxonomies ) > 1 && ! isset( $defaults['taxonomy'] ) ) {
530
+ echo '<p>' . __( 'More than 1 heirachical taxonomy detected. You must assign a default taxonomy on the settings screen.', 'post-expirator' ) . '</p>';
531
+ } else {
532
+ $keys = array_keys( $taxonomies );
533
+ $taxonomy = isset( $defaults['taxonomy'] ) ? $defaults['taxonomy'] : $keys[0];
534
+ wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
535
+ echo '<input type="hidden" name="taxonomy-heirarchical" value="' . $taxonomy . '" />';
536
+ }
537
+ echo '</ul>';
538
+ echo '</div>';
539
+ if ( isset( $taxonomy ) ) {
540
+ echo '<p class="post-expirator-taxonomy-name">' . __( 'Taxonomy Name', 'post-expirator' ) . ': ' . $taxonomy . '</p>';
541
+ }
542
+ echo '</div>';
543
+ }
544
+ echo '<div id="expirationdate_ajax_result"></div>';
545
+ }
546
+
547
+ /**
548
+ * Add's ajax javascript.
549
+ *
550
+ * @internal
551
+ *
552
+ * @access private
553
+ */
554
+ function postexpirator_js_admin_header() {
555
+ // Define custom JavaScript function
556
+ ?>
557
+ <script type="text/javascript">
558
+ //<![CDATA[
559
+ function expirationdate_ajax_add_meta(expireenable) {
560
+ var expire = document.getElementById(expireenable);
561
+
562
+ if (expire.checked == true) {
563
+ var enable = 'true';
564
+ if (document.getElementById('expirationdate_month')) {
565
+ document.getElementById('expirationdate_month').disabled = false;
566
+ document.getElementById('expirationdate_day').disabled = false;
567
+ document.getElementById('expirationdate_year').disabled = false;
568
+ document.getElementById('expirationdate_hour').disabled = false;
569
+ document.getElementById('expirationdate_minute').disabled = false;
570
+ }
571
+ document.getElementById('expirationdate_expiretype').disabled = false;
572
+ var cats = document.getElementsByName('expirationdate_category[]');
573
+ var max = cats.length;
574
+ for (var i=0; i<max; i++) {
575
+ cats[i].disabled = '';
576
+ }
577
+ } else {
578
+ if (document.getElementById('expirationdate_month')) {
579
+ document.getElementById('expirationdate_month').disabled = true;
580
+ document.getElementById('expirationdate_day').disabled = true;
581
+ document.getElementById('expirationdate_year').disabled = true;
582
+ document.getElementById('expirationdate_hour').disabled = true;
583
+ document.getElementById('expirationdate_minute').disabled = true;
584
+ }
585
+ document.getElementById('expirationdate_expiretype').disabled = true;
586
+ var cats = document.getElementsByName('expirationdate_category[]');
587
+ var max = cats.length;
588
+ for (var i=0; i<max; i++) {
589
+ cats[i].disabled = 'disable';
590
+ }
591
+ var enable = 'false';
592
+ }
593
+ return true;
594
+ }
595
+ function expirationdate_toggle_category(id) {
596
+ if (id.options[id.selectedIndex].value == 'category') {
597
+ jQuery('#expired-category-selection').show();
598
+ } else if (id.options[id.selectedIndex].value == 'category-add') {
599
+ jQuery('#expired-category-selection').show(); //TEMP
600
+ } else if (id.options[id.selectedIndex].value == 'category-remove') {
601
+ jQuery('#expired-category-selection').show(); //TEMP
602
+ } else {
603
+ jQuery('#expired-category-selection').hide();
604
+ }
605
+ }
606
+ function expirationdate_toggle_defaultdate(id) {
607
+ if (id.options[id.selectedIndex].value == 'custom') {
608
+ jQuery('#expired-custom-container').show();
609
+ } else {
610
+ jQuery('#expired-custom-container').hide();
611
+ }
612
+
613
+ }
614
+ //]]>
615
+ </script>
616
+ <?php
617
+ }
618
+ add_action( 'admin_head', 'postexpirator_js_admin_header' );
619
+
620
+ /**
621
+ * Get correct URL (HTTP or HTTPS)
622
+ *
623
+ * @internal
624
+ *
625
+ * @access private
626
+ */
627
+ function expirationdate_get_blog_url() {
628
+ if ( is_multisite() ) {
629
+ echo network_home_url( '/' );
630
+ } else {
631
+ echo home_url( '/' );
632
+ }
633
+ }
634
+
635
+ /**
636
+ * Called when post is saved - stores expiration-date meta value
637
+ *
638
+ * @internal
639
+ *
640
+ * @access private
641
+ */
642
+ function postexpirator_update_post_meta( $id ) {
643
+ // don't run the echo if this is an auto save
644
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
645
+ return;
646
+ }
647
+
648
+ // don't run the echo if the function is called for saving revision.
649
+ $posttype = get_post_type( $id );
650
+ if ( $posttype === 'revision' ) {
651
+ return;
652
+ }
653
+
654
+ if ( ! isset( $_POST['expirationdate_quickedit'] ) ) {
655
+ if ( ! isset( $_POST['expirationdate_formcheck'] ) ) {
656
+ return;
657
+ }
658
+ }
659
+
660
+ if ( isset( $_POST['enable-expirationdate'] ) ) {
661
+ $default = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
662
+ if ( $default === 'publish' ) {
663
+ $month = intval( $_POST['mm'] );
664
+ $day = intval( $_POST['jj'] );
665
+ $year = intval( $_POST['aa'] );
666
+ $hour = intval( $_POST['hh'] );
667
+ $minute = intval( $_POST['mn'] );
668
+ } else {
669
+ $month = intval( $_POST['expirationdate_month'] );
670
+ $day = intval( $_POST['expirationdate_day'] );
671
+ $year = intval( $_POST['expirationdate_year'] );
672
+ $hour = intval( $_POST['expirationdate_hour'] );
673
+ $minute = intval( $_POST['expirationdate_minute'] );
674
+
675
+ if ( empty( $day ) ) {
676
+ $day = date( 'd' );
677
+ }
678
+ if ( empty( $year ) ) {
679
+ $year = date( 'Y' );
680
+ }
681
+ }
682
+ $category = isset( $_POST['expirationdate_category'] ) ? $_POST['expirationdate_category'] : 0;
683
+
684
+ $ts = get_gmt_from_date( "$year-$month-$day $hour:$minute:0", 'U' );
685
+
686
+ if ( isset( $_POST['expirationdate_quickedit'] ) ) {
687
+ $ed = get_post_meta( $id, '_expiration-date', true );
688
+ if ( $ed ) {
689
+ $opts = get_post_meta( $id, '_expiration-date-options', true );
690
+ }
691
+ } else {
692
+ $opts = array();
693
+
694
+ // Schedule/Update Expiration
695
+ $opts['expireType'] = $_POST['expirationdate_expiretype'];
696
+ $opts['id'] = $id;
697
+
698
+ if ( $opts['expireType'] === 'category' || $opts['expireType'] === 'category-add' || $opts['expireType'] === 'category-remove' ) {
699
+ if ( isset( $category ) && ! empty( $category ) ) {
700
+ if ( ! empty( $category ) ) {
701
+ $opts['category'] = $category;
702
+ $opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical'];
703
+ }
704
+ }
705
+ }
706
+ }
707
+ postexpirator_schedule_event( $id, $ts, $opts );
708
+ } else {
709
+ postexpirator_unschedule_event( $id );
710
+ }
711
+ }
712
+ add_action( 'save_post', 'postexpirator_update_post_meta' );
713
+
714
+ /**
715
+ * Schedules the single event.
716
+ *
717
+ * @internal
718
+ *
719
+ * @access private
720
+ */
721
+ function postexpirator_schedule_event( $id, $ts, $opts ) {
722
+ $debug = postexpirator_debug(); // check for/load debug
723
+
724
+ $id = intval( $id );
725
+
726
+ do_action( 'postexpiratior_schedule', $id, $ts, $opts ); // allow custom actions
727
+
728
+ if ( wp_next_scheduled( 'postExpiratorExpire', array($id) ) !== false ) {
729
+ $error = wp_clear_scheduled_hook( 'postExpiratorExpire', array($id), true ); // Remove any existing hooks
730
+ if ( POSTEXPIRATOR_DEBUG ) {
731
+ $debug->save( array('message' => $id . ' -> EXISTING FOUND - UNSCHEDULED - ' . ( is_wp_error( $error ) ? $error->get_error_message() : 'no error' )) );
732
+ }
733
+ }
734
+
735
+ $error = wp_schedule_single_event( $ts, 'postExpiratorExpire', array($id), true );
736
+ if ( POSTEXPIRATOR_DEBUG ) {
737
+ $debug->save( array('message' => $id . ' -> SCHEDULED at ' . date_i18n( 'r', $ts ) . ' ' . '(' . $ts . ') with options ' . print_r( $opts, true ) . ' ' . ( is_wp_error( $error ) ? $error->get_error_message() : 'no error' ) ) );
738
+ }
739
+
740
+ // Update Post Meta
741
+ update_post_meta( $id, '_expiration-date', $ts );
742
+ if ( ! is_null( $opts ) ) {
743
+ update_post_meta( $id, '_expiration-date-options', $opts );
744
+ }
745
+ update_post_meta( $id, '_expiration-date-status', 'saved' );
746
+ }
747
+
748
+ /**
749
+ * Unschedules the single event.
750
+ *
751
+ * @internal
752
+ *
753
+ * @access private
754
+ */
755
+ function postexpirator_unschedule_event( $id ) {
756
+ $debug = postexpirator_debug(); // check for/load debug
757
+
758
+ do_action( 'postexpiratior_unschedule', $id ); // allow custom actions
759
+
760
+ delete_post_meta( $id, '_expiration-date' );
761
+ delete_post_meta( $id, '_expiration-date-options' );
762
+
763
+ // Delete Scheduled Expiration
764
+ if ( wp_next_scheduled( 'postExpiratorExpire', array($id) ) !== false ) {
765
+ wp_clear_scheduled_hook( 'postExpiratorExpire', array($id) ); // Remove any existing hooks
766
+ if ( POSTEXPIRATOR_DEBUG ) {
767
+ $debug->save( array('message' => $id . ' -> UNSCHEDULED') );
768
+ }
769
+ }
770
+ update_post_meta( $id, '_expiration-date-status', 'saved' );
771
+ }
772
+
773
+ /**
774
+ * The new expiration function, to work with single scheduled events.
775
+ *
776
+ * This was designed to hopefully be more flexible for future tweaks/modifications to the architecture.
777
+ *
778
+ * @internal
779
+ *
780
+ * @access private
781
+ */
782
+ function postexpirator_expire_post( $id ) {
783
+ $debug = postexpirator_debug(); // check for/load debug
784
+
785
+ if ( empty( $id ) ) {
786
+ if ( POSTEXPIRATOR_DEBUG ) {
787
+ $debug->save( array('message' => 'No Post ID found - exiting') );
788
+ }
789
+ return false;
790
+ }
791
+
792
+ if ( is_null( get_post( $id ) ) ) {
793
+ if ( POSTEXPIRATOR_DEBUG ) {
794
+ $debug->save( array('message' => $id . ' -> Post does not exist - exiting') );
795
+ }
796
+ return false;
797
+ }
798
+
799
+ $posttype = get_post_type( $id );
800
+ $posttitle = get_the_title( $id );
801
+ $postlink = get_post_permalink( $id );
802
+
803
+ $postoptions = get_post_meta( $id, '_expiration-date-options', true );
804
+ $expireType = $category = $categoryTaxonomy = null;
805
+
806
+ if ( isset( $postoptions['expireType'] ) ) {
807
+ $expireType = $postoptions['expireType'];
808
+ }
809
+
810
+ if ( isset( $postoptions['category'] ) ) {
811
+ $category = $postoptions['category'];
812
+ }
813
+
814
+ if ( isset( $postoptions['categoryTaxonomy'] ) ) {
815
+ $categoryTaxonomy = $postoptions['categoryTaxonomy'];
816
+ }
817
+
818
+ $ed = get_post_meta( $id, '_expiration-date', true );
819
+
820
+ // Check for default expire only if not passed in
821
+ if ( empty( $expireType ) ) {
822
+ $posttype = get_post_type( $id );
823
+ if ( $posttype === 'page' ) {
824
+ $expireType = strtolower( get_option( 'expirationdateExpiredPageStatus', POSTEXPIRATOR_PAGESTATUS ) );
825
+ } elseif ( $posttype === 'post' ) {
826
+ $expireType = strtolower( get_option( 'expirationdateExpiredPostStatus', 'draft' ) );
827
+ } else {
828
+ $expireType = apply_filters( 'postexpirator_custom_posttype_expire', $expireType, $posttype ); // hook to set defaults for custom post types
829
+ }
830
+ }
831
+
832
+ // Remove KSES - wp_cron runs as an unauthenticated user, which will by default trigger kses filtering,
833
+ // even if the post was published by a admin user. It is fairly safe here to remove the filter call since
834
+ // we are only changing the post status/meta information and not touching the content.
835
+ kses_remove_filters();
836
+
837
+ // Do Work
838
+ if ( $expireType === 'draft' ) {
839
+ if ( wp_update_post( array('ID' => $id, 'post_status' => 'draft') ) === 0 ) {
840
+ if ( POSTEXPIRATOR_DEBUG ) {
841
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
842
+ }
843
+ } else {
844
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post status has been successfully changed to "%4$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', strtoupper( $expireType ) );
845
+ if ( POSTEXPIRATOR_DEBUG ) {
846
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
847
+ }
848
+ }
849
+ } elseif ( $expireType === 'private' ) {
850
+ if ( wp_update_post( array('ID' => $id, 'post_status' => 'private') ) === 0 ) {
851
+ if ( POSTEXPIRATOR_DEBUG ) {
852
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
853
+ }
854
+ } else {
855
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post status has been successfully changed to "%4$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', strtoupper( $expireType ) );
856
+ if ( POSTEXPIRATOR_DEBUG ) {
857
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
858
+ }
859
+ }
860
+ } elseif ( $expireType === 'delete' ) {
861
+ if ( wp_delete_post( $id ) === false ) {
862
+ if ( POSTEXPIRATOR_DEBUG ) {
863
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
864
+ }
865
+ } else {
866
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post status has been successfully changed to "%4$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', strtoupper( $expireType ) );
867
+ if ( POSTEXPIRATOR_DEBUG ) {
868
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
869
+ }
870
+ }
871
+ } elseif ( $expireType === 'trash' ) {
872
+ if ( wp_trash_post( $id ) === false ) {
873
+ if ( POSTEXPIRATOR_DEBUG ) {
874
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
875
+ }
876
+ } else {
877
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post status has been successfully changed to "%4$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', strtoupper( $expireType ) );
878
+ if ( POSTEXPIRATOR_DEBUG ) {
879
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
880
+ }
881
+ }
882
+ } elseif ( $expireType === 'stick' ) {
883
+ if ( stick_post( $id ) === false ) {
884
+ if ( POSTEXPIRATOR_DEBUG ) {
885
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
886
+ }
887
+ } else {
888
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post "%4$s" status has been successfully set.', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'STICKY' );
889
+ if ( POSTEXPIRATOR_DEBUG ) {
890
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
891
+ }
892
+ }
893
+ } elseif ( $expireType === 'unstick' ) {
894
+ if ( unstick_post( $id ) === false ) {
895
+ if ( POSTEXPIRATOR_DEBUG ) {
896
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
897
+ }
898
+ } else {
899
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post "%4$s" status has been successfully removed.', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'STICKY' );
900
+ if ( POSTEXPIRATOR_DEBUG ) {
901
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
902
+ }
903
+ }
904
+ } elseif ( $expireType === 'category' ) {
905
+ if ( ! empty( $category ) ) {
906
+ if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
907
+ if ( wp_update_post( array('ID' => $id, 'post_category' => $category) ) === 0 ) {
908
+ if ( POSTEXPIRATOR_DEBUG ) {
909
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
910
+ }
911
+ } else {
912
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post "%4$s" have now been set to "%5$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ) );
913
+ if ( POSTEXPIRATOR_DEBUG ) {
914
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
915
+ $debug->save( array('message' => $id . ' -> CATEGORIES REPLACED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
916
+ $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
917
+ }
918
+ }
919
+ } else {
920
+ $terms = array_map( 'intval', $category );
921
+ if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, false ) ) ) {
922
+ if ( POSTEXPIRATOR_DEBUG ) {
923
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
924
+ }
925
+ } else {
926
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. Post "%4$s" have now been set to "%5$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ) );
927
+ if ( POSTEXPIRATOR_DEBUG ) {
928
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
929
+ $debug->save( array('message' => $id . ' -> CATEGORIES REPLACED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
930
+ $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
931
+ }
932
+ }
933
+ }
934
+ } else {
935
+ if ( POSTEXPIRATOR_DEBUG ) {
936
+ $debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
937
+ }
938
+ }
939
+ } elseif ( $expireType === 'category-add' ) {
940
+ if ( ! empty( $category ) ) {
941
+ if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
942
+ $cats = wp_get_post_categories( $id );
943
+ $merged = array_merge( $cats, $category );
944
+ if ( wp_update_post( array('ID' => $id, 'post_category' => $merged) ) === 0 ) {
945
+ if ( POSTEXPIRATOR_DEBUG ) {
946
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
947
+ }
948
+ } else {
949
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. The following post "%4$s" have now been added: "%5$s". The full list of categories on the post are: "%6$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ), implode( ',', _postexpirator_get_cat_names( $merged ) ) );
950
+ if ( POSTEXPIRATOR_DEBUG ) {
951
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
952
+ $debug->save( array('message' => $id . ' -> CATEGORIES ADDED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
953
+ $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $merged ), true )) );
954
+ }
955
+ }
956
+ } else {
957
+ $terms = array_map( 'intval', $category );
958
+ if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, true ) ) ) {
959
+ if ( POSTEXPIRATOR_DEBUG ) {
960
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
961
+ }
962
+ } else {
963
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. The following post "%4$s" have now been added: "%5$s". The full list of categories on the post are: "%6$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ), implode( ',', _postexpirator_get_cat_names( $merged ) ) );
964
+ if ( POSTEXPIRATOR_DEBUG ) {
965
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
966
+ $debug->save( array('message' => $id . ' -> CATEGORIES ADDED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
967
+ $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
968
+ }
969
+ }
970
+ }
971
+ } else {
972
+ if ( POSTEXPIRATOR_DEBUG ) {
973
+ $debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
974
+ }
975
+ }
976
+ } elseif ( $expireType === 'category-remove' ) {
977
+ if ( ! empty( $category ) ) {
978
+ if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
979
+ $cats = wp_get_post_categories( $id );
980
+ $merged = array();
981
+ foreach ( $cats as $cat ) {
982
+ if ( ! in_array( $cat, $category, true ) ) {
983
+ $merged[] = $cat;
984
+ }
985
+ }
986
+ if ( wp_update_post( array('ID' => $id, 'post_category' => $merged) ) === 0 ) {
987
+ if ( POSTEXPIRATOR_DEBUG ) {
988
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
989
+ }
990
+ } else {
991
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. The following post "%4$s" have now been removed: "%5$s". The full list of categories on the post are: "%6$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ), implode( ',', _postexpirator_get_cat_names( $merged ) ) );
992
+ if ( POSTEXPIRATOR_DEBUG ) {
993
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
994
+ $debug->save( array('message' => $id . ' -> CATEGORIES REMOVED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
995
+ $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $merged ), true )) );
996
+ }
997
+ }
998
+ } else {
999
+ $terms = wp_get_object_terms( $id, $categoryTaxonomy, array('fields' => 'ids') );
1000
+ $merged = array();
1001
+ foreach ( $terms as $term ) {
1002
+ if ( ! in_array( $term, $category, true ) ) {
1003
+ $merged[] = $term;
1004
+ }
1005
+ }
1006
+ $terms = array_map( 'intval', $merged );
1007
+ if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, false ) ) ) {
1008
+ if ( POSTEXPIRATOR_DEBUG ) {
1009
+ $debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
1010
+ }
1011
+ } else {
1012
+ $emailBody = sprintf( __( '%1$s (%2$s) has expired at %3$s. The following post "%4$s" have now been removed: "%5$s". The full list of categories on the post are: "%6$s".', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'CATEGORIES', implode( ',', _postexpirator_get_cat_names( $category ) ), implode( ',', _postexpirator_get_cat_names( $merged ) ) );
1013
+ if ( POSTEXPIRATOR_DEBUG ) {
1014
+ $debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
1015
+ $debug->save( array('message' => $id . ' -> CATEGORIES REMOVED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
1016
+ $debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
1017
+ }
1018
+ }
1019
+ }
1020
+ } else {
1021
+ if ( POSTEXPIRATOR_DEBUG ) {
1022
+ $debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
1023
+ }
1024
+ }
1025
+ }
1026
+
1027
+ // Process Email
1028
+ $emailenabled = get_option( 'expirationdateEmailNotification', POSTEXPIRATOR_EMAILNOTIFICATION );
1029
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1030
+ if ( $emailenabled == 1 && isset( $emailBody ) ) {
1031
+ $subj = sprintf( __( 'Post Expiration Complete "%s"', 'post-expirator' ), $posttitle );
1032
+ $emailBody = str_replace( '##POSTTITLE##', $posttitle, $emailBody );
1033
+ $emailBody = str_replace( '##POSTLINK##', $postlink, $emailBody );
1034
+ $emailBody = str_replace( '##EXPIRATIONDATE##', get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ed ), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ), $emailBody );
1035
+
1036
+ $emails = array();
1037
+ // Get Blog Admins
1038
+ $emailadmins = get_option( 'expirationdateEmailNotificationAdmins', POSTEXPIRATOR_EMAILNOTIFICATIONADMINS );
1039
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1040
+ if ( $emailadmins == 1 ) {
1041
+ $blogusers = get_users( 'role=Administrator' );
1042
+ foreach ( $blogusers as $user ) {
1043
+ $emails[] = $user->user_email;
1044
+ }
1045
+ }
1046
+
1047
+ // Get Global Notification Emails
1048
+ $emaillist = get_option( 'expirationdateEmailNotificationList' );
1049
+ if ( ! empty( $emaillist ) ) {
1050
+ $vals = explode( ',', $emaillist );
1051
+ foreach ( $vals as $val ) {
1052
+ $emails[] = trim( $val );
1053
+ }
1054
+ }
1055
+
1056
+ // Get Post Type Notification Emails
1057
+ $defaults = get_option( 'expirationdateDefaults' . ucfirst( $posttype ) );
1058
+ if ( isset( $defaults['emailnotification'] ) && ! empty( $defaults['emailnotification'] ) ) {
1059
+ $vals = explode( ',', $defaults['emailnotification'] );
1060
+ foreach ( $vals as $val ) {
1061
+ $emails[] = trim( $val );
1062
+ }
1063
+ }
1064
+
1065
+ // Send Emails
1066
+ foreach ( $emails as $email ) {
1067
+ if ( wp_mail( $email, sprintf( __( '[%1$s] %2$s' ), get_option( 'blogname' ), $subj ), $emailBody ) ) {
1068
+ if ( POSTEXPIRATOR_DEBUG ) {
1069
+ $debug->save( array('message' => $id . ' -> EXPIRATION EMAIL SENT (' . $email . ')') );
1070
+ }
1071
+ } else {
1072
+ if ( POSTEXPIRATOR_DEBUG ) {
1073
+ $debug->save( array('message' => $id . ' -> EXPIRATION EMAIL FAILED (' . $email . ')') );
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+
1079
+ }
1080
+ add_action( 'postExpiratorExpire', 'postexpirator_expire_post' );
1081
+
1082
+ /**
1083
+ * Internal method to get category names corresponding to the category IDs.
1084
+ *
1085
+ * @internal
1086
+ *
1087
+ * @access private
1088
+ */
1089
+ function _postexpirator_get_cat_names( $cats ) {
1090
+ $out = array();
1091
+ foreach ( $cats as $cat ) {
1092
+ $out[ $cat ] = get_the_category_by_id( $cat );
1093
+ }
1094
+ return $out;
1095
+ }
1096
+
1097
+ /**
1098
+ * Build the menu for the options page
1099
+ *
1100
+ * @internal
1101
+ *
1102
+ * @access private
1103
+ */
1104
+ function postexpirator_menu_tabs( $tab ) {
1105
+ echo '<p>';
1106
+ if ( empty( $tab ) ) {
1107
+ $tab = 'general';
1108
+ }
1109
+ echo '<a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=general' ) . '"' . ( $tab === 'general' ? ' style="font-weight: bold; text-decoration:none;"' : '' ) . '>' . __( 'General Settings', 'post-expirator' ) . '</a> | ';
1110
+ echo '<a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=defaults' ) . '"' . ( $tab === 'defaults' ? ' style="font-weight: bold; text-decoration:none;"' : '' ) . '>' . __( 'Defaults', 'post-expirator' ) . '</a> | ';
1111
+ echo '<a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=diagnostics' ) . '"' . ( $tab === 'diagnostics' ? ' style="font-weight: bold; text-decoration:none;"' : '' ) . '>' . __( 'Diagnostics', 'post-expirator' ) . '</a> | ';
1112
+ echo '<a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=viewdebug' ) . '"' . ( $tab === 'viewdebug' ? ' style="font-weight: bold; text-decoration:none;"' : '' ) . '>' . __( 'View Debug Logs', 'post-expirator' ) . '</a>';
1113
+ echo '</p><hr/>';
1114
+ }
1115
+
1116
+ /**
1117
+ * Show the menu.
1118
+ *
1119
+ * @internal
1120
+ *
1121
+ * @access private
1122
+ */
1123
+ function postexpirator_menu() {
1124
+ $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : '';
1125
+
1126
+ echo '<div class="wrap">';
1127
+ echo '<h2>' . __( 'Post Expirator Options', 'post-expirator' ) . '</h2>';
1128
+
1129
+ postexpirator_menu_tabs( $tab );
1130
+ if ( empty( $tab ) || $tab === 'general' ) {
1131
+ postexpirator_menu_general();
1132
+ } elseif ( $tab === 'defaults' ) {
1133
+ postexpirator_menu_defaults();
1134
+ } elseif ( $tab === 'diagnostics' ) {
1135
+ postexpirator_menu_diagnostics();
1136
+ } elseif ( $tab === 'viewdebug' ) {
1137
+ postexpirator_menu_debug();
1138
+ }
1139
+ echo '</div>';
1140
+ }
1141
+
1142
+ /**
1143
+ * Hook's to add plugin page menu
1144
+ *
1145
+ * @internal
1146
+ *
1147
+ * @access private
1148
+ */
1149
+ function postexpirator_add_menu() {
1150
+ add_submenu_page( 'options-general.php', __( 'Post Expirator Options', 'post-expirator' ), __( 'Post Expirator', 'post-expirator' ), 'manage_options', basename( __FILE__ ), 'postexpirator_menu' );
1151
+ }
1152
+ add_action( 'admin_menu', 'postexpirator_add_menu' );
1153
+
1154
+ /**
1155
+ * Show the Expiration Date options page
1156
+ *
1157
+ * @internal
1158
+ *
1159
+ * @access private
1160
+ */
1161
+ function postexpirator_menu_general() {
1162
+ if ( isset( $_POST['expirationdateSave'] ) && $_POST['expirationdateSave'] ) {
1163
+ if ( ! isset( $_POST['_postExpiratorMenuGeneral_nonce'] ) || ! wp_verify_nonce( $_POST['_postExpiratorMenuGeneral_nonce'], 'postexpirator_menu_general' ) ) {
1164
+ print 'Form Validation Failure: Sorry, your nonce did not verify.';
1165
+ exit;
1166
+ } else {
1167
+ // Filter Content
1168
+ $_POST = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING );
1169
+
1170
+ update_option( 'expirationdateDefaultDateFormat', $_POST['expired-default-date-format'] );
1171
+ update_option( 'expirationdateDefaultTimeFormat', $_POST['expired-default-time-format'] );
1172
+ update_option( 'expirationdateDisplayFooter', $_POST['expired-display-footer'] );
1173
+ update_option( 'expirationdateEmailNotification', $_POST['expired-email-notification'] );
1174
+ update_option( 'expirationdateEmailNotificationAdmins', $_POST['expired-email-notification-admins'] );
1175
+ update_option( 'expirationdateEmailNotificationList', trim( $_POST['expired-email-notification-list'] ) );
1176
+ update_option( 'expirationdateFooterContents', $_POST['expired-footer-contents'] );
1177
+ update_option( 'expirationdateFooterStyle', $_POST['expired-footer-style'] );
1178
+ if ( isset( $_POST['expirationdate_category'] ) ) {
1179
+ update_option( 'expirationdateCategoryDefaults', $_POST['expirationdate_category'] );
1180
+ }
1181
+ update_option( 'expirationdateDefaultDate', $_POST['expired-default-expiration-date'] );
1182
+ if ( $_POST['expired-custom-expiration-date'] ) {
1183
+ update_option( 'expirationdateDefaultDateCustom', $_POST['expired-custom-expiration-date'] );
1184
+ }
1185
+ echo "<div id='message' class='updated fade'><p>";
1186
+ _e( 'Saved Options!', 'post-expirator' );
1187
+ echo '</p></div>';
1188
+ }
1189
+ }
1190
+
1191
+ // phpcs:disable WordPress.NamingConventions.ValidVariableName.InterpolatedVariableNotSnakeCase
1192
+ // phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
1193
+
1194
+ // Get Option
1195
+ $expirationdateDefaultDateFormat = get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT );
1196
+ $expirationdateDefaultTimeFormat = get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT );
1197
+ $expireddisplayfooter = get_option( 'expirationdateDisplayFooter', POSTEXPIRATOR_FOOTERDISPLAY );
1198
+ $expiredemailnotification = get_option( 'expirationdateEmailNotification', POSTEXPIRATOR_EMAILNOTIFICATION );
1199
+ $expiredemailnotificationadmins = get_option( 'expirationdateEmailNotificationAdmins', POSTEXPIRATOR_EMAILNOTIFICATIONADMINS );
1200
+ $expiredemailnotificationlist = get_option( 'expirationdateEmailNotificationList', '' );
1201
+ $expirationdateFooterContents = get_option( 'expirationdateFooterContents', POSTEXPIRATOR_FOOTERCONTENTS );
1202
+ $expirationdateFooterStyle = get_option( 'expirationdateFooterStyle', POSTEXPIRATOR_FOOTERSTYLE );
1203
+ $expirationdateDefaultDate = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
1204
+ $expirationdateDefaultDateCustom = get_option( 'expirationdateDefaultDateCustom' );
1205
+
1206
+ $categories = get_option( 'expirationdateCategoryDefaults' );
1207
+
1208
+ $expireddisplayfooterenabled = '';
1209
+ $expireddisplayfooterdisabled = '';
1210
+ if ( $expireddisplayfooter == 0 ) {
1211
+ $expireddisplayfooterdisabled = 'checked="checked"';
1212
+ } elseif ( $expireddisplayfooter == 1 ) {
1213
+ $expireddisplayfooterenabled = 'checked="checked"';
1214
+ }
1215
+
1216
+ $expiredemailnotificationenabled = '';
1217
+ $expiredemailnotificationdisabled = '';
1218
+ if ( $expiredemailnotification == 0 ) {
1219
+ $expiredemailnotificationdisabled = 'checked="checked"';
1220
+ } elseif ( $expiredemailnotification == 1 ) {
1221
+ $expiredemailnotificationenabled = 'checked="checked"';
1222
+ }
1223
+
1224
+ $expiredemailnotificationadminsenabled = '';
1225
+ $expiredemailnotificationadminsdisabled = '';
1226
+ if ( $expiredemailnotificationadmins == 0 ) {
1227
+ $expiredemailnotificationadminsdisabled = 'checked="checked"';
1228
+ } elseif ( $expiredemailnotificationadmins == 1 ) {
1229
+ $expiredemailnotificationadminsenabled = 'checked="checked"';
1230
+ }
1231
+ ?>
1232
+ <p>
1233
+ <?php _e( 'The post expirator plugin sets a custom meta value, and then optionally allows you to select if you want the post changed to a draft status or deleted when it expires.', 'post-expirator' ); ?>
1234
+ </p>
1235
+ <p>
1236
+ <?php _e( 'Valid [postexpirator] attributes:', 'post-expirator' ); ?>
1237
+ <ul>
1238
+ <li><?php _e( 'type - defaults to full - valid options are full,date,time', 'post-expirator' ); ?></li>
1239
+ <li><?php _e( 'dateformat - format set here will override the value set on the settings page', 'post-expirator' ); ?></li>
1240
+ <li><?php _e( 'timeformat - format set here will override the value set on the settings page', 'post-expirator' ); ?></li>
1241
+ </ul>
1242
+ </p>
1243
+ <form method="post" id="expirationdate_save_options">
1244
+ <?php wp_nonce_field( 'postexpirator_menu_general', '_postExpiratorMenuGeneral_nonce' ); ?>
1245
+ <h3><?php _e( 'Defaults', 'post-expirator' ); ?></h3>
1246
+ <table class="form-table">
1247
+ <tr valign="top">
1248
+ <th scope="row"><label for="expired-default-date-format"><?php _e( 'Date Format:', 'post-expirator' ); ?></label></th>
1249
+ <td>
1250
+ <input type="text" name="expired-default-date-format" id="expired-default-date-format" value="<?php echo $expirationdateDefaultDateFormat; ?>" size="25" /> (<?php echo date_i18n( "$expirationdateDefaultDateFormat" ); ?>)
1251
+ <br/>
1252
+ <?php _e( 'The default format to use when displaying the expiration date within a post using the [postexpirator] shortcode or within the footer. For information on valid formatting options, see: <a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>.', 'post-expirator' ); ?>
1253
+ </td>
1254
+ </tr>
1255
+ <tr valign="top">
1256
+ <th scope="row"><label for="expired-default-time-format"><?php _e( 'Time Format:', 'post-expirator' ); ?></label></th>
1257
+ <td>
1258
+ <input type="text" name="expired-default-time-format" id="expired-default-time-format" value="<?php echo $expirationdateDefaultTimeFormat; ?>" size="25" /> (<?php echo date_i18n( "$expirationdateDefaultTimeFormat" ); ?>)
1259
+ <br/>
1260
+ <?php _e( 'The default format to use when displaying the expiration time within a post using the [postexpirator] shortcode or within the footer. For information on valid formatting options, see: <a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>.', 'post-expirator' ); ?>
1261
+ </td>
1262
+ </tr>
1263
+ <tr valign="top">
1264
+ <th scope="row"><label for="expired-default-expiration-date"><?php _e( 'Default Date/Time Duration:', 'post-expirator' ); ?></label></th>
1265
+ <td>
1266
+ <select name="expired-default-expiration-date" id="expired-default-expiration-date" onchange="expirationdate_toggle_defaultdate(this)">
1267
+ <option value="null" <?php echo ( $expirationdateDefaultDate == 'null' ) ? ' selected="selected"' : ''; ?>><?php _e( 'None', 'post-expirator' ); ?></option>
1268
+ <option value="custom" <?php echo ( $expirationdateDefaultDate == 'custom' ) ? ' selected="selected"' : ''; ?>><?php _e( 'Custom', 'post-expirator' ); ?></option>
1269
+ <option value="publish" <?php echo ( $expirationdateDefaultDate == 'publish' ) ? ' selected="selected"' : ''; ?>><?php _e( 'Post/Page Publish Time', 'post-expirator' ); ?></option>
1270
+ </select>
1271
+ <br/>
1272
+ <?php _e( 'Set the default expiration date to be used when creating new posts and pages. Defaults to none.', 'post-expirator' ); ?>
1273
+ <?php $show = ( $expirationdateDefaultDate == 'custom' ) ? 'block' : 'none'; ?>
1274
+ <div id="expired-custom-container" style="display: <?php echo $show; ?>;">
1275
+ <br/><label for="expired-custom-expiration-date">Custom:</label> <input type="text" value="<?php echo $expirationdateDefaultDateCustom; ?>" name="expired-custom-expiration-date" id="expired-custom-expiration-date" />
1276
+ <br/>
1277
+ <?php echo sprintf( __( 'Set the custom value to use for the default expiration date. For information on formatting, see %1$s. For example, you could enter %2$s+1 month%3$s or %4$s+1 week 2 days 4 hours 2 seconds%5$s or %6$snext Thursday%7$s.', 'post-expirator' ), '<a href="http://php.net/manual/en/function.strtotime.php" target="_new">PHP strtotime function</a>', '<code>', '</code>', '<code>', '</code>', '<code>', '</code>' ); ?>
1278
+ </div>
1279
+ </td>
1280
+ </tr>
1281
+ </table>
1282
+ <h3><?php _e( 'Category Expiration', 'post-expirator' ); ?></h3>
1283
+ <table class="form-table">
1284
+ <tr valign="top">
1285
+ <th scope="row"><?php _e( 'Default Expiration Category', 'post-expirator' ); ?>:</th>
1286
+ <td>
1287
+ <?php
1288
+ echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
1289
+ echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
1290
+ $walker = new Walker_PostExpirator_Category_Checklist();
1291
+ wp_terms_checklist( 0, array( 'taxonomy' => 'category', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
1292
+ echo '</ul>';
1293
+ echo '</div>';
1294
+ ?>
1295
+ <br/>
1296
+ <?php _e( "Set's the default expiration category for the post.", 'post-expirator' ); ?>
1297
+ </td>
1298
+ </tr>
1299
+ </table>
1300
+
1301
+ <h3><?php _e( 'Expiration Email Notification', 'post-expirator' ); ?></h3>
1302
+ <p><?php _e( 'Whenever a post expires, an email can be sent to alert users of the expiration.', 'post-expirator' ); ?></p>
1303
+ <table class="form-table">
1304
+ <tr valign="top">
1305
+ <th scope="row"><?php _e( 'Enable Email Notification?', 'post-expirator' ); ?></th>
1306
+ <td>
1307
+ <input type="radio" name="expired-email-notification" id="expired-email-notification-true" value="1" <?php echo $expiredemailnotificationenabled; ?>/> <label for="expired-email-notification-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
1308
+ <br/>
1309
+ <input type="radio" name="expired-email-notification" id="expired-email-notification-false" value="0" <?php echo $expiredemailnotificationdisabled; ?>/> <label for="expired-email-notification-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
1310
+ <br/>
1311
+ <?php _e( 'This will enable or disable the send of email notification on post expiration.', 'post-expirator' ); ?>
1312
+ </td>
1313
+ </tr>
1314
+ <tr valign="top">
1315
+ <th scope="row"><?php _e( 'Include Blog Administrators?', 'post-expirator' ); ?></th>
1316
+ <td>
1317
+ <input type="radio" name="expired-email-notification-admins" id="expired-email-notification-admins-true" value="1" <?php echo $expiredemailnotificationadminsenabled; ?>/> <label for="expired-email-notification-admins-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
1318
+ <br/>
1319
+ <input type="radio" name="expired-email-notification-admins" id="expired-email-notification-admins-false" value="0" <?php echo $expiredemailnotificationadminsdisabled; ?>/> <label for="expired-email-notification-admins-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
1320
+ <br/>
1321
+ <?php _e( 'This will include all users with the role of "Administrator" in the post expiration email.', 'post-expirator' ); ?>
1322
+ </td>
1323
+ </tr>
1324
+ <tr valign="top">
1325
+ <th scope="row"><label for="expired-email-notification-list"><?php _e( 'Who to notify:', 'post-expirator' ); ?></label></th>
1326
+ <td>
1327
+ <input class="large-text" type="text" name="expired-email-notification-list" id="expired-email-notification-list" value="<?php echo $expiredemailnotificationlist; ?>" />
1328
+ <br/>
1329
+ <?php _e( 'Enter a comma seperate list of emails that you would like to be notified when the post expires. This will be applied to ALL post types. You can set post type specific emails on the Defaults tab.', 'post-expirator' ); ?>
1330
+ </td>
1331
+ </tr>
1332
+ </table>
1333
+
1334
+ <h3><?php _e( 'Post Footer Display', 'post-expirator' ); ?></h3>
1335
+ <p><?php _e( 'Enabling this below will display the expiration date automatically at the end of any post which is set to expire.', 'post-expirator' ); ?></p>
1336
+ <table class="form-table">
1337
+ <tr valign="top">
1338
+ <th scope="row"><?php _e( 'Show in post footer?', 'post-expirator' ); ?></th>
1339
+ <td>
1340
+ <input type="radio" name="expired-display-footer" id="expired-display-footer-true" value="1" <?php echo $expireddisplayfooterenabled; ?>/> <label for="expired-display-footer-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
1341
+ <br/>
1342
+ <input type="radio" name="expired-display-footer" id="expired-display-footer-false" value="0" <?php echo $expireddisplayfooterdisabled; ?>/> <label for="expired-display-footer-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
1343
+ <br/>
1344
+ <?php _e( 'This will enable or disable displaying the post expiration date in the post footer.', 'post-expirator' ); ?>
1345
+ </td>
1346
+ </tr>
1347
+ <tr valign="top">
1348
+ <th scope="row"><label for="expired-footer-contents"><?php _e( 'Footer Contents:', 'post-expirator' ); ?></label></th>
1349
+ <td>
1350
+ <textarea id="expired-footer-contents" name="expired-footer-contents" rows="3" cols="50"><?php echo $expirationdateFooterContents; ?></textarea>
1351
+ <br/>
1352
+ <?php _e( 'Enter the text you would like to appear at the bottom of every post that will expire. The following placeholders will be replaced with the post expiration date in the following format:', 'post-expirator' ); ?>
1353
+ <ul>
1354
+ <li>EXPIRATIONFULL -> <?php echo date_i18n( "$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat" ); ?></li>
1355
+ <li>EXPIRATIONDATE -> <?php echo date_i18n( "$expirationdateDefaultDateFormat" ); ?></li>
1356
+ <li>EXPIRATIONTIME -> <?php echo date_i18n( "$expirationdateDefaultTimeFormat" ); ?></li>
1357
+ </ul>
1358
+ </td>
1359
+ </tr>
1360
+ <tr valign="top">
1361
+ <th scope="row"><label for="expired-footer-style"><?php _e( 'Footer Style:', 'post-expirator' ); ?></label></th>
1362
+ <td>
1363
+ <input type="text" name="expired-footer-style" id="expired-footer-style" value="<?php echo $expirationdateFooterStyle; ?>" size="25" />
1364
+ (<span style="<?php echo $expirationdateFooterStyle; ?>"><?php _e( 'This post will expire on', 'post-expirator' ); ?> <?php echo date_i18n( "$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat" ); ?></span>)
1365
+ <br/>
1366
+ <?php _e( 'The inline css which will be used to style the footer text.', 'post-expirator' ); ?>
1367
+ </td>
1368
+ </tr>
1369
+ </table>
1370
+ <p class="submit">
1371
+ <input type="submit" name="expirationdateSave" class="button-primary" value="<?php _e( 'Save Changes', 'post-expirator' ); ?>" />
1372
+ </p>
1373
+ </form>
1374
+ <?php
1375
+ // phpcs:enable
1376
+ }
1377
+
1378
+ /**
1379
+ * The default menu.
1380
+ *
1381
+ * @internal
1382
+ *
1383
+ * @access private
1384
+ */
1385
+ function postexpirator_menu_defaults() {
1386
+ $debug = postexpirator_debug();
1387
+ $types = get_post_types( array('public' => true, '_builtin' => false) );
1388
+ array_unshift( $types, 'post', 'page' );
1389
+
1390
+ if ( isset( $_POST['expirationdateSaveDefaults'] ) ) {
1391
+ if ( ! isset( $_POST['_postExpiratorMenuDefaults_nonce'] ) || ! wp_verify_nonce( $_POST['_postExpiratorMenuDefaults_nonce'], 'postexpirator_menu_defaults' ) ) {
1392
+ print 'Form Validation Failure: Sorry, your nonce did not verify.';
1393
+ exit;
1394
+ } else {
1395
+ // Filter Content
1396
+ $_POST = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING );
1397
+
1398
+ $defaults = array();
1399
+ foreach ( $types as $type ) {
1400
+ if ( isset( $_POST[ 'expirationdate_expiretype-' . $type ] ) ) {
1401
+ $defaults[ $type ]['expireType'] = $_POST[ 'expirationdate_expiretype-' . $type ];
1402
+ }
1403
+ if ( isset( $_POST[ 'expirationdate_autoenable-' . $type ] ) ) {
1404
+ $defaults[ $type ]['autoEnable'] = intval( $_POST[ 'expirationdate_autoenable-' . $type ] );
1405
+ }
1406
+ if ( isset( $_POST[ 'expirationdate_taxonomy-' . $type ] ) ) {
1407
+ $defaults[ $type ]['taxonomy'] = $_POST[ 'expirationdate_taxonomy-' . $type ];
1408
+ }
1409
+ if ( isset( $_POST[ 'expirationdate_activemeta-' . $type ] ) ) {
1410
+ $defaults[ $type ]['activeMetaBox'] = $_POST[ 'expirationdate_activemeta-' . $type ];
1411
+ }
1412
+ $defaults[ $type ]['emailnotification'] = trim( $_POST[ 'expirationdate_emailnotification-' . $type ] );
1413
+
1414
+ // Save Settings
1415
+ update_option( 'expirationdateDefaults' . ucfirst( $type ), $defaults[ $type ] );
1416
+ }
1417
+ echo "<div id='message' class='updated fade'><p>";
1418
+ _e( 'Saved Options!', 'post-expirator' );
1419
+ echo '</p></div>';
1420
+ }
1421
+ }
1422
+
1423
+ ?>
1424
+ <form method="post">
1425
+ <?php wp_nonce_field( 'postexpirator_menu_defaults', '_postExpiratorMenuDefaults_nonce' ); ?>
1426
+ <h3><?php _e( 'Default Expiration Values', 'post-expirator' ); ?></h3>
1427
+ <p>
1428
+ <?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' ); ?>
1429
+ </p>
1430
+ <?php
1431
+ foreach ( $types as $type ) {
1432
+ echo "<fieldset style='border: 1px solid black; border-radius: 6px; padding: 0px 12px; margin-bottom: 20px;'>";
1433
+ echo "<legend>Post Type: $type</legend>";
1434
+ $defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
1435
+
1436
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1437
+ if ( isset( $defaults['autoEnable'] ) && $defaults['autoEnable'] == 1 ) {
1438
+ $expiredautoenabled = 'checked = "checked"';
1439
+ $expiredautodisabled = '';
1440
+ } else {
1441
+ $expiredautoenabled = '';
1442
+ $expiredautodisabled = 'checked = "checked"';
1443
+ }
1444
+ if ( isset( $defaults['activeMetaBox'] ) && $defaults['activeMetaBox'] === 'inactive' ) {
1445
+ $expiredactivemetaenabled = '';
1446
+ $expiredactivemetadisabled = 'checked = "checked"';
1447
+ } else {
1448
+ $expiredactivemetaenabled = 'checked = "checked"';
1449
+ $expiredactivemetadisabled = '';
1450
+ }
1451
+ if ( ! isset( $defaults['taxonomy'] ) ) {
1452
+ $defaults['taxonomy'] = false;
1453
+ }
1454
+ if ( ! isset( $defaults['emailnotification'] ) ) {
1455
+ $defaults['emailnotification'] = '';
1456
+ }
1457
+ ?>
1458
+ <table class="form-table">
1459
+ <tr valign="top">
1460
+ <th scope="row"><label for="expirationdate_activemeta-<?php echo $type; ?>"><?php _e( 'Active:', 'post-expirator' ); ?></label></th>
1461
+ <td>
1462
+ <input type="radio" name="expirationdate_activemeta-<?php echo $type; ?>" id="expirationdate_activemeta-true-<?php echo $type; ?>" value="active" <?php echo $expiredactivemetaenabled; ?>/> <label for="expired-active-meta-true"><?php _e( 'Active', 'post-expirator' ); ?></label>
1463
+ <br/>
1464
+ <input type="radio" name="expirationdate_activemeta-<?php echo $type; ?>" id="expirationdate_activemeta-false-<?php echo $type; ?>" value="inactive" <?php echo $expiredactivemetadisabled; ?>/> <label for="expired-active-meta-false"><?php _e( 'Inactive', 'post-expirator' ); ?></label>
1465
+ <br/>
1466
+ <?php _e( 'Select whether the post expirator meta box is active for this post type.', 'post-expirator' ); ?>
1467
+ </td>
1468
+ </tr>
1469
+ <tr valign="top">
1470
+ <th scope="row"><label for="expirationdate_expiretype-<?php echo $type; ?>"><?php _e( 'How to expire:', 'post-expirator' ); ?></label></th>
1471
+ <td>
1472
+ <?php echo _postexpirator_expire_type( array('name' => 'expirationdate_expiretype-' . $type, 'selected' => $defaults['expireType']) ); ?>
1473
+ </select>
1474
+ <br/>
1475
+ <?php _e( 'Select the default expire action for the post type.', 'post-expirator' ); ?>
1476
+ </td>
1477
+ </tr>
1478
+ <tr valign="top">
1479
+ <th scope="row"><label for="expirationdate_autoenable-<?php echo $type; ?>"><?php _e( 'Auto-Enable?', 'post-expirator' ); ?></label></th>
1480
+ <td>
1481
+ <input type="radio" name="expirationdate_autoenable-<?php echo $type; ?>" id="expirationdate_autoenable-true-<?php echo $type; ?>" value="1" <?php echo $expiredautoenabled; ?>/> <label for="expired-auto-enable-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
1482
+ <br/>
1483
+ <input type="radio" name="expirationdate_autoenable-<?php echo $type; ?>" id="expirationdate_autoenable-false-<?php echo $type; ?>" value="0" <?php echo $expiredautodisabled; ?>/> <label for="expired-auto-enable-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
1484
+ <br/>
1485
+ <?php _e( 'Select whether the post expirator is enabled for all new posts.', 'post-expirator' ); ?>
1486
+ </td>
1487
+ </tr>
1488
+ <tr valign="top">
1489
+ <th scope="row"><label for="expirationdate_taxonomy-<?php echo $type; ?>"><?php _e( 'Taxonomy (hierarchical):', 'post-expirator' ); ?></label></th>
1490
+ <td>
1491
+ <?php echo _postexpirator_taxonomy( array('type' => $type, 'name' => 'expirationdate_taxonomy-' . $type, 'selected' => $defaults['taxonomy']) ); ?>
1492
+ </td>
1493
+ </tr>
1494
+ <tr valign="top">
1495
+ <th scope="row"><label for="expirationdate_emailnotification-<?php echo $type; ?>"><?php _e( 'Who to notify:', 'post-expirator' ); ?></label></th>
1496
+ <td>
1497
+ <input class="large-text" type="text" name="expirationdate_emailnotification-<?php echo $type; ?>" id="expirationdate_emailnotification-<?php echo $type; ?>" value="<?php echo $defaults['emailnotification']; ?>" />
1498
+ <br/>
1499
+ <?php _e( 'Enter a comma seperate list of emails that you would like to be notified when the post expires.', 'post-expirator' ); ?>
1500
+ </td>
1501
+ </tr>
1502
+
1503
+ </table>
1504
+ </fieldset>
1505
+ <?php
1506
+ }
1507
+ ?>
1508
+ <p class="submit">
1509
+ <input type="submit" name="expirationdateSaveDefaults" class="button-primary" value="<?php _e( 'Save Changes', 'post-expirator' ); ?>" />
1510
+ </p>
1511
+ </form>
1512
+ <?php
1513
+ }
1514
+
1515
+ /**
1516
+ * Diagnostics menu.
1517
+ *
1518
+ * @internal
1519
+ *
1520
+ * @access private
1521
+ */
1522
+ function postexpirator_menu_diagnostics() {
1523
+ if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
1524
+ if ( ! isset( $_POST['_postExpiratorMenuDiagnostics_nonce'] ) || ! wp_verify_nonce( $_POST['_postExpiratorMenuDiagnostics_nonce'], 'postexpirator_menu_diagnostics' ) ) {
1525
+ print 'Form Validation Failure: Sorry, your nonce did not verify.';
1526
+ exit;
1527
+ }
1528
+ if ( isset( $_POST['debugging-disable'] ) ) {
1529
+ update_option( 'expirationdateDebug', 0 );
1530
+ echo "<div id='message' class='updated fade'><p>";
1531
+ _e( 'Debugging Disabled', 'post-expirator' );
1532
+ echo '</p></div>';
1533
+ } elseif ( isset( $_POST['debugging-enable'] ) ) {
1534
+ update_option( 'expirationdateDebug', 1 );
1535
+ echo "<div id='message' class='updated fade'><p>";
1536
+ _e( 'Debugging Enabled', 'post-expirator' );
1537
+ echo '</p></div>';
1538
+ } elseif ( isset( $_POST['purge-debug'] ) ) {
1539
+ require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' );
1540
+ $debug = new PostExpiratorDebug();
1541
+ $debug->purge();
1542
+ echo "<div id='message' class='updated fade'><p>";
1543
+ _e( 'Debugging Table Emptied', 'post-expirator' );
1544
+ echo '</p></div>';
1545
+ }
1546
+ }
1547
+
1548
+ $debug = postexpirator_debug();
1549
+ ?>
1550
+ <form method="post" id="postExpiratorMenuUpgrade">
1551
+ <?php wp_nonce_field( 'postexpirator_menu_diagnostics', '_postExpiratorMenuDiagnostics_nonce' ); ?>
1552
+ <h3><?php _e( 'Advanced Diagnostics', 'post-expirator' ); ?></h3>
1553
+ <table class="form-table">
1554
+ <tr valign="top">
1555
+ <th scope="row"><label for="postexpirator-log"><?php _e( 'Post Expirator Debug Logging:', 'post-expirator' ); ?></label></th>
1556
+ <td>
1557
+ <?php
1558
+ if ( POSTEXPIRATOR_DEBUG ) {
1559
+ echo __( 'Status: Enabled', 'post-expirator' ) . '<br/>';
1560
+ echo '<input type="submit" class="button" name="debugging-disable" id="debugging-disable" value="' . __( 'Disable Debugging', 'post-expirator' ) . '" />';
1561
+ } else {
1562
+ echo __( 'Status: Disabled', 'post-expirator' ) . '<br/>';
1563
+ echo '<input type="submit" class="button" name="debugging-enable" id="debugging-enable" value="' . __( 'Enable Debugging', 'post-expirator' ) . '" />';
1564
+ }
1565
+ ?>
1566
+ <br/>
1567
+ <a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=viewdebug' ); ?>">View Debug Logs</a>
1568
+ </td>
1569
+ </tr>
1570
+ <tr valign="top">
1571
+ <th scope="row"><?php _e( 'Purge Debug Log:', 'post-expirator' ); ?></th>
1572
+ <td>
1573
+ <input type="submit" class="button" name="purge-debug" id="purge-debug" value="<?php _e( 'Purge Debug Log', 'post-expirator' ); ?>" />
1574
+ </td>
1575
+ </tr/>
1576
+ <tr valign="top">
1577
+ <th scope="row"><?php _e( 'WP-Cron Status:', 'post-expirator' ); ?></th>
1578
+ <td>
1579
+ <?php
1580
+ if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON === true ) {
1581
+ _e( 'DISABLED', 'post-expirator' );
1582
+ } else {
1583
+ _e( 'ENABLED - OK', 'post-expirator' );
1584
+ }
1585
+ ?>
1586
+ </td>
1587
+ </tr/>
1588
+ <tr valign="top">
1589
+ <th scope="row"><label for="cron-schedule"><?php _e( 'Current Cron Schedule:', 'post-expirator' ); ?></label></th>
1590
+ <td>
1591
+ <?php _e( 'The below table will show all currently scheduled cron events with the next run time.', 'post-expirator' ); ?><br/>
1592
+ <table>
1593
+ <tr>
1594
+ <th style="width: 200px;"><?php _e( 'Date', 'post-expirator' ); ?></th>
1595
+ <th style="width: 200px;"><?php _e( 'Event', 'post-expirator' ); ?></th>
1596
+ <th style="width: 500px;"><?php _e( 'Arguments / Schedule', 'post-expirator' ); ?></th>
1597
+ </tr>
1598
+ <?php
1599
+ $cron = _get_cron_array();
1600
+ foreach ( $cron as $key => $value ) {
1601
+ foreach ( $value as $eventkey => $eventvalue ) {
1602
+ print '<tr>';
1603
+ print '<td>' . date_i18n( 'r', $key ) . '</td>';
1604
+ print '<td>' . $eventkey . '</td>';
1605
+ $arrkey = array_keys( $eventvalue );
1606
+ print '<td>';
1607
+ foreach ( $arrkey as $eventguid ) {
1608
+ print '<table><tr>';
1609
+ if ( empty( $eventvalue[ $eventguid ]['args'] ) ) {
1610
+ print '<td>No Arguments</td>';
1611
+ } else {
1612
+ print '<td>';
1613
+ $args = array();
1614
+ foreach ( $eventvalue[ $eventguid ]['args'] as $key => $value ) {
1615
+ $args[] = "$key => $value";
1616
+ }
1617
+ print implode( "<br/>\n", $args );
1618
+ print '</td>';
1619
+ }
1620
+ if ( empty( $eventvalue[ $eventguid ]['schedule'] ) ) {
1621
+ print '<td>' . __( 'Single Event', 'post-expirator' ) . '</td>';
1622
+ } else {
1623
+ print '<td>' . $eventvalue[ $eventguid ]['schedule'] . ' (' . $eventvalue[ $eventguid ]['interval'] . ')</td>';
1624
+ }
1625
+ print '</tr></table>';
1626
+ }
1627
+ print '</td>';
1628
+ print '</tr>';
1629
+ }
1630
+ }
1631
+ ?>
1632
+ </table>
1633
+ </td>
1634
+ </tr>
1635
+ </table>
1636
+ </form>
1637
+ <?php
1638
+ }
1639
+
1640
+ /**
1641
+ * Debug menu.
1642
+ *
1643
+ * @internal
1644
+ *
1645
+ * @access private
1646
+ */
1647
+ function postexpirator_menu_debug() {
1648
+ require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' );
1649
+ print '<p>' . __( 'Below is a dump of the debugging table, this should be useful for troubleshooting.', 'post-expirator' ) . '</p>';
1650
+ $debug = new PostExpiratorDebug();
1651
+ $debug->getTable();
1652
+ }
1653
+
1654
+ /**
1655
+ * Register the shortcode.
1656
+ *
1657
+ * @internal
1658
+ *
1659
+ * @access private
1660
+ */
1661
+ function postexpirator_shortcode( $atts ) {
1662
+ global $post;
1663
+
1664
+ $expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
1665
+ if ( empty( $expirationdatets ) ) {
1666
+ return false;
1667
+ }
1668
+
1669
+ // @TODO remove extract
1670
+ // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
1671
+ extract(
1672
+ shortcode_atts(
1673
+ array(
1674
+ 'dateformat' => get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT ),
1675
+ 'timeformat' => get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT ),
1676
+ 'type' => 'full',
1677
+ 'tz' => date( 'T' ),
1678
+ ), $atts
1679
+ )
1680
+ );
1681
+
1682
+ if ( empty( $dateformat ) ) {
1683
+ global $expirationdateDefaultDateFormat;
1684
+ $dateformat = $expirationdateDefaultDateFormat;
1685
+ }
1686
+
1687
+ if ( empty( $timeformat ) ) {
1688
+ global $expirationdateDefaultTimeFormat;
1689
+ $timeformat = $expirationdateDefaultTimeFormat;
1690
+ }
1691
+
1692
+ if ( $type === 'full' ) {
1693
+ $format = $dateformat . ' ' . $timeformat;
1694
+ } elseif ( $type === 'date' ) {
1695
+ $format = $dateformat;
1696
+ } elseif ( $type === 'time' ) {
1697
+ $format = $timeformat;
1698
+ }
1699
+
1700
+ return date_i18n( $format, $expirationdatets + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
1701
+ }
1702
+ add_shortcode( 'postexpirator', 'postexpirator_shortcode' );
1703
+
1704
+ /**
1705
+ * Add the footer.
1706
+ *
1707
+ * @internal
1708
+ *
1709
+ * @access private
1710
+ */
1711
+ function postexpirator_add_footer( $text ) {
1712
+ global $post;
1713
+
1714
+ // Check to see if its enabled
1715
+ $displayFooter = get_option( 'expirationdateDisplayFooter' );
1716
+
1717
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1718
+ if ( $displayFooter === false || $displayFooter == 0 ) {
1719
+ return $text;
1720
+ }
1721
+
1722
+ $expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
1723
+ if ( ! is_numeric( $expirationdatets ) ) {
1724
+ return $text;
1725
+ }
1726
+
1727
+ $dateformat = get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT );
1728
+ $timeformat = get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT );
1729
+ $expirationdateFooterContents = get_option( 'expirationdateFooterContents', POSTEXPIRATOR_FOOTERCONTENTS );
1730
+ $expirationdateFooterStyle = get_option( 'expirationdateFooterStyle', POSTEXPIRATOR_FOOTERSTYLE );
1731
+
1732
+ $search = array(
1733
+ 'EXPIRATIONFULL',
1734
+ 'EXPIRATIONDATE',
1735
+ 'EXPIRATIONTIME',
1736
+ );
1737
+ $replace = array(
1738
+ get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), "$dateformat $timeformat" ),
1739
+ get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), $dateformat ),
1740
+ get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), $timeformat ),
1741
+ );
1742
+
1743
+ $add_to_footer = '<p style="' . $expirationdateFooterStyle . '">' . str_replace( $search, $replace, $expirationdateFooterContents ) . '</p>';
1744
+ return $text . $add_to_footer;
1745
+ }
1746
+ add_action( 'the_content', 'postexpirator_add_footer', 0 );
1747
+
1748
+ /**
1749
+ * Check for Debug
1750
+ *
1751
+ * @internal
1752
+ *
1753
+ * @access private
1754
+ */
1755
+ function postexpirator_debug() {
1756
+ $debug = get_option( 'expirationdateDebug' );
1757
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1758
+ if ( $debug == 1 ) {
1759
+ if ( ! defined( 'POSTEXPIRATOR_DEBUG' ) ) {
1760
+ define( 'POSTEXPIRATOR_DEBUG', 1 );
1761
+ }
1762
+ require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' ); // Load Class
1763
+ return new PostExpiratorDebug();
1764
+ } else {
1765
+ if ( ! defined( 'POSTEXPIRATOR_DEBUG' ) ) {
1766
+ define( 'POSTEXPIRATOR_DEBUG', 0 );
1767
+ }
1768
+ return false;
1769
+ }
1770
+ }
1771
+
1772
+
1773
+ /**
1774
+ * Add Stylesheet
1775
+ *
1776
+ * @internal
1777
+ *
1778
+ * @access private
1779
+ */
1780
+ function postexpirator_css( $screen_id ) {
1781
+ switch ( $screen_id ) {
1782
+ case 'post.php':
1783
+ case 'post-new.php':
1784
+ case 'settings_page_post-expirator':
1785
+ wp_enqueue_style( 'postexpirator-css', POSTEXPIRATOR_BASEURL . '/assets/css/style.css', array(), POSTEXPIRATOR_VERSION );
1786
+ break;
1787
+ case 'edit.php':
1788
+ wp_enqueue_style( 'postexpirator-edit', POSTEXPIRATOR_BASEURL . '/assets/css/edit.css', array(), POSTEXPIRATOR_VERSION );
1789
+ break;
1790
+ }
1791
+ }
1792
+ add_action( 'admin_enqueue_scripts', 'postexpirator_css', 10, 1 );
1793
+
1794
+ /**
1795
+ * Post Expirator Activation/Upgrade
1796
+ *
1797
+ * @internal
1798
+ *
1799
+ * @access private
1800
+ */
1801
+ function postexpirator_upgrade() {
1802
+
1803
+ // Check for current version, if not exists, run activation
1804
+ $version = get_option( 'postexpiratorVersion' );
1805
+ if ( $version === false ) { // not installed, run default activation
1806
+ postexpirator_activate();
1807
+ update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1808
+ } else {
1809
+ if ( version_compare( $version, '1.6.1' ) === -1 ) {
1810
+ update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1811
+ update_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
1812
+ }
1813
+
1814
+ if ( version_compare( $version, '1.6.2' ) === -1 ) {
1815
+ update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1816
+ }
1817
+
1818
+ if ( version_compare( $version, '2.0.0-rc1' ) === -1 ) {
1819
+ global $wpdb;
1820
+
1821
+ // Schedule Events/Migrate Config
1822
+ $results = $wpdb->get_results( $wpdb->prepare( 'select post_id, meta_value from ' . $wpdb->postmeta . ' as postmeta, ' . $wpdb->posts . ' as posts where postmeta.post_id = posts.ID AND postmeta.meta_key = %s AND postmeta.meta_value >= %d', 'expiration-date', time() ) );
1823
+ foreach ( $results as $result ) {
1824
+ wp_schedule_single_event( $result->meta_value, 'postExpiratorExpire', array($result->post_id) );
1825
+ $opts = array();
1826
+ $opts['id'] = $result->post_id;
1827
+ $posttype = get_post_type( $result->post_id );
1828
+ if ( $posttype === 'page' ) {
1829
+ $opts['expireType'] = strtolower( get_option( 'expirationdateExpiredPageStatus', 'Draft' ) );
1830
+ } else {
1831
+ $opts['expireType'] = strtolower( get_option( 'expirationdateExpiredPostStatus', 'Draft' ) );
1832
+ }
1833
+
1834
+ $cat = get_post_meta( $result->post_id, '_expiration-date-category', true );
1835
+ if ( ( isset( $cat ) && ! empty( $cat ) ) ) {
1836
+ $opts['category'] = $cat;
1837
+ $opts['expireType'] = 'category';
1838
+ }
1839
+ update_post_meta( $result->post_id, '_expiration-date-options', $opts );
1840
+ }
1841
+
1842
+ // update meta key to new format
1843
+ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_key = %s WHERE meta_key = %s", '_expiration-date', 'expiration-date' ) );
1844
+
1845
+ // migrate defaults
1846
+ $pagedefault = get_option( 'expirationdateExpiredPageStatus' );
1847
+ $postdefault = get_option( 'expirationdateExpiredPostStatus' );
1848
+ if ( $pagedefault ) {
1849
+ update_option( 'expirationdateDefaultsPage', array('expireType' => $pagedefault) );
1850
+ }
1851
+ if ( $postdefault ) {
1852
+ update_option( 'expirationdateDefaultsPost', array('expireType' => $postdefault) );
1853
+ }
1854
+
1855
+ delete_option( 'expirationdateCronSchedule' );
1856
+ delete_option( 'expirationdateAutoEnabled' );
1857
+ delete_option( 'expirationdateExpiredPageStatus' );
1858
+ delete_option( 'expirationdateExpiredPostStatus' );
1859
+ update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1860
+ }
1861
+
1862
+ if ( version_compare( $version, '2.0.1' ) === -1 ) {
1863
+ // Forgot to do this in 2.0.0
1864
+ if ( is_multisite() ) {
1865
+ global $current_blog;
1866
+ wp_clear_scheduled_hook( 'expirationdate_delete_' . $current_blog->blog_id );
1867
+ } else {
1868
+ wp_clear_scheduled_hook( 'expirationdate_delete' );
1869
+ }
1870
+
1871
+ update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1872
+ }
1873
+
1874
+ update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
1875
+
1876
+ }
1877
+ }
1878
+ add_action( 'admin_init', 'postexpirator_upgrade' );
1879
+
1880
+ /**
1881
+ * Called at plugin activation
1882
+ *
1883
+ * @internal
1884
+ *
1885
+ * @access private
1886
+ */
1887
+ function postexpirator_activate() {
1888
+ if ( get_option( 'expirationdateDefaultDateFormat' ) === false ) {
1889
+ update_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT );
1890
+ }
1891
+ if ( get_option( 'expirationdateDefaultTimeFormat' ) === false ) {
1892
+ update_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT );
1893
+ }
1894
+ if ( get_option( 'expirationdateFooterContents' ) === false ) {
1895
+ update_option( 'expirationdateFooterContents', POSTEXPIRATOR_FOOTERCONTENTS );
1896
+ }
1897
+ if ( get_option( 'expirationdateFooterStyle' ) === false ) {
1898
+ update_option( 'expirationdateFooterStyle', POSTEXPIRATOR_FOOTERSTYLE );
1899
+ }
1900
+ if ( get_option( 'expirationdateDisplayFooter' ) === false ) {
1901
+ update_option( 'expirationdateDisplayFooter', POSTEXPIRATOR_FOOTERDISPLAY );
1902
+ }
1903
+ if ( get_option( 'expirationdateDebug' ) === false ) {
1904
+ update_option( 'expirationdateDebug', POSTEXPIRATOR_DEBUGDEFAULT );
1905
+ }
1906
+ if ( get_option( 'expirationdateDefaultDate' ) === false ) {
1907
+ update_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
1908
+ }
1909
+ }
1910
+
1911
+ /**
1912
+ * Called at plugin deactivation
1913
+ *
1914
+ * @internal
1915
+ *
1916
+ * @access private
1917
+ */
1918
+ function expirationdate_deactivate() {
1919
+ global $current_blog;
1920
+ delete_option( 'expirationdateExpiredPostStatus' );
1921
+ delete_option( 'expirationdateExpiredPageStatus' );
1922
+ delete_option( 'expirationdateDefaultDateFormat' );
1923
+ delete_option( 'expirationdateDefaultTimeFormat' );
1924
+ delete_option( 'expirationdateDisplayFooter' );
1925
+ delete_option( 'expirationdateFooterContents' );
1926
+ delete_option( 'expirationdateFooterStyle' );
1927
+ delete_option( 'expirationdateCategory' );
1928
+ delete_option( 'expirationdateCategoryDefaults' );
1929
+ delete_option( 'expirationdateDebug' );
1930
+ delete_option( 'postexpiratorVersion' );
1931
+ delete_option( 'expirationdateCronSchedule' );
1932
+ delete_option( 'expirationdateDefaultDate' );
1933
+ delete_option( 'expirationdateDefaultDateCustom' );
1934
+ delete_option( 'expirationdateAutoEnabled' );
1935
+ delete_option( 'expirationdateDefaultsPage' );
1936
+ delete_option( 'expirationdateDefaultsPost' );
1937
+ // what about custom post types? - how to cleanup?
1938
+ if ( is_multisite() ) {
1939
+ wp_clear_scheduled_hook( 'expirationdate_delete_' . $current_blog->blog_id );
1940
+ } else {
1941
+ wp_clear_scheduled_hook( 'expirationdate_delete' );
1942
+ }
1943
+ require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' );
1944
+ $debug = new PostExpiratorDebug();
1945
+ $debug->removeDbTable();
1946
+ }
1947
+ register_deactivation_hook( __FILE__, 'expirationdate_deactivate' );
1948
+
1949
+ /**
1950
+ * The walker class for category checklist.
1951
+ *
1952
+ * @internal
1953
+ *
1954
+ * @access private
1955
+ */
1956
+ class Walker_PostExpirator_Category_Checklist extends Walker {
1957
+
1958
+ /**
1959
+ * What the class handles.
1960
+ *
1961
+ * @var string
1962
+ */
1963
+ var $tree_type = 'category';
1964
+
1965
+ /**
1966
+ * DB fields to use.
1967
+ *
1968
+ * @var array
1969
+ */
1970
+ var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); // TODO: decouple this
1971
+
1972
+ /**
1973
+ * The disabled attribute.
1974
+ *
1975
+ * @var string
1976
+ */
1977
+ var $disabled = '';
1978
+
1979
+ /**
1980
+ * Set the disabled attribute.
1981
+ */
1982
+ function setDisabled() {
1983
+ $this->disabled = 'disabled="disabled"';
1984
+ }
1985
+
1986
+ /**
1987
+ * Starts the list before the elements are added.
1988
+ *
1989
+ * The $args parameter holds additional values that may be used with the child
1990
+ * class methods. This method is called at the start of the output list.
1991
+ *
1992
+ * @param string $output Used to append additional content (passed by reference).
1993
+ * @param int $depth Depth of the item.
1994
+ * @param array $args An array of additional arguments.
1995
+ */
1996
+ function start_lvl( &$output, $depth = 0, $args = array() ) {
1997
+ $indent = str_repeat( "\t", $depth );
1998
+ $output .= "$indent<ul class='children'>\n";
1999
+ }
2000
+
2001
+ /**
2002
+ * Ends the list of after the elements are added.
2003
+ *
2004
+ * The $args parameter holds additional values that may be used with the child
2005
+ * class methods. This method finishes the list at the end of output of the elements.
2006
+ *
2007
+ * @param string $output Used to append additional content (passed by reference).
2008
+ * @param int $depth Depth of the item.
2009
+ * @param array $args An array of additional arguments.
2010
+ */
2011
+ function end_lvl( &$output, $depth = 0, $args = array() ) {
2012
+ $indent = str_repeat( "\t", $depth );
2013
+ $output .= "$indent</ul>\n";
2014
+ }
2015
+
2016
+ /**
2017
+ * Start the element output.
2018
+ *
2019
+ * The $args parameter holds additional values that may be used with the child
2020
+ * class methods. Includes the element output also.
2021
+ *
2022
+ * @param string $output Used to append additional content (passed by reference).
2023
+ * @param object $category The data object.
2024
+ * @param int $depth Depth of the item.
2025
+ * @param array $args An array of additional arguments.
2026
+ * @param int $current_object_id ID of the current item.
2027
+ */
2028
+ function start_el( &$output, $category, $depth = 0, $args = array(), $current_object_id = 0 ) {
2029
+ // @TODO remove extract
2030
+ // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
2031
+ extract( $args );
2032
+ if ( empty( $taxonomy ) ) {
2033
+ $taxonomy = 'category';
2034
+ }
2035
+
2036
+ $name = 'expirationdate_category';
2037
+
2038
+ $class = in_array( $category->term_id, $popular_cats, true ) ? ' class="expirator-category"' : '';
2039
+ $output .= "\n<li id='expirator-{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="expirator-in-' . $taxonomy . '-' . $category->term_id . '"' . checked( in_array( $category->term_id, $selected_cats, true ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' ' . $this->disabled . '/> ' . esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';
2040
+ }
2041
+
2042
+ /**
2043
+ * Ends the element output, if needed.
2044
+ *
2045
+ * The $args parameter holds additional values that may be used with the child class methods.
2046
+ *
2047
+ * @param string $output Used to append additional content (passed by reference).
2048
+ * @param object $category The data object.
2049
+ * @param int $depth Depth of the item.
2050
+ * @param array $args An array of additional arguments.
2051
+ */
2052
+ function end_el( &$output, $category, $depth = 0, $args = array() ) {
2053
+ $output .= "</li>\n";
2054
+ }
2055
+ }
2056
+
2057
+ /**
2058
+ * Get the HTML for expire type.
2059
+ *
2060
+ * @internal
2061
+ *
2062
+ * @access private
2063
+ */
2064
+ function _postexpirator_expire_type( $opts ) {
2065
+ if ( empty( $opts ) ) {
2066
+ return false;
2067
+ }
2068
+
2069
+ // @TODO remove extract
2070
+ // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
2071
+ extract( $opts );
2072
+
2073
+ if ( ! isset( $name ) ) {
2074
+ return false;
2075
+ }
2076
+ if ( ! isset( $id ) ) {
2077
+ $id = $name;
2078
+ }
2079
+ if ( ! isset( $disabled ) ) {
2080
+ $disabled = false;
2081
+ }
2082
+ if ( ! isset( $onchange ) ) {
2083
+ $onchange = '';
2084
+ }
2085
+ if ( ! isset( $type ) ) {
2086
+ $type = '';
2087
+ }
2088
+
2089
+ $rv = array();
2090
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
2091
+ $rv[] = '<select name="' . $name . '" id="' . $id . '"' . ( $disabled == true ? ' disabled="disabled"' : '' ) . ' onchange="' . $onchange . '">';
2092
+ $rv[] = '<option value="draft" ' . ( $selected === 'draft' ? 'selected="selected"' : '' ) . '>' . __( 'Draft', 'post-expirator' ) . '</option>';
2093
+ $rv[] = '<option value="delete" ' . ( $selected === 'delete' ? 'selected="selected"' : '' ) . '>' . __( 'Delete', 'post-expirator' ) . '</option>';
2094
+ $rv[] = '<option value="trash" ' . ( $selected === 'trash' ? 'selected="selected"' : '' ) . '>' . __( 'Trash', 'post-expirator' ) . '</option>';
2095
+ $rv[] = '<option value="private" ' . ( $selected === 'private' ? 'selected="selected"' : '' ) . '>' . __( 'Private', 'post-expirator' ) . '</option>';
2096
+ $rv[] = '<option value="stick" ' . ( $selected === 'stick' ? 'selected="selected"' : '' ) . '>' . __( 'Stick', 'post-expirator' ) . '</option>';
2097
+ $rv[] = '<option value="unstick" ' . ( $selected === 'unstick' ? 'selected="selected"' : '' ) . '>' . __( 'Unstick', 'post-expirator' ) . '</option>';
2098
+ if ( $type !== 'page' ) {
2099
+ $rv[] = '<option value="category" ' . ( $selected === 'category' ? 'selected="selected"' : '' ) . '>' . __( 'Category: Replace', 'post-expirator' ) . '</option>';
2100
+ $rv[] = '<option value="category-add" ' . ( $selected === 'category-add' ? 'selected="selected"' : '' ) . '>' . __( 'Category: Add', 'post-expirator' ) . '</option>';
2101
+ $rv[] = '<option value="category-remove" ' . ( $selected === 'category-remove' ? 'selected="selected"' : '' ) . '>' . __( 'Category: Remove', 'post-expirator' ) . '</option>';
2102
+ }
2103
+ $rv[] = '</select>';
2104
+ return implode( "<br/>\n", $rv );
2105
+ }
2106
+
2107
+ /**
2108
+ * Get the HTML for taxonomy.
2109
+ *
2110
+ * @internal
2111
+ *
2112
+ * @access private
2113
+ */
2114
+ function _postexpirator_taxonomy( $opts ) {
2115
+ if ( empty( $opts ) ) {
2116
+ return false;
2117
+ }
2118
+
2119
+ // @TODO remove extract
2120
+ // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
2121
+ extract( $opts );
2122
+ if ( ! isset( $name ) ) {
2123
+ return false;
2124
+ }
2125
+ if ( ! isset( $id ) ) {
2126
+ $id = $name;
2127
+ }
2128
+ if ( ! isset( $disabled ) ) {
2129
+ $disabled = false;
2130
+ }
2131
+ if ( ! isset( $onchange ) ) {
2132
+ $onchange = '';
2133
+ }
2134
+ if ( ! isset( $type ) ) {
2135
+ $type = '';
2136
+ }
2137
+
2138
+ $taxonomies = get_object_taxonomies( $type, 'object' );
2139
+ $taxonomies = wp_filter_object_list( $taxonomies, array('hierarchical' => true) );
2140
+
2141
+ if ( empty( $taxonomies ) ) {
2142
+ $disabled = true;
2143
+ }
2144
+
2145
+ $rv = array();
2146
+ if ( $taxonomies ) {
2147
+ // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
2148
+ $rv[] = '<select name="' . $name . '" id="' . $id . '"' . ( $disabled == true ? ' disabled="disabled"' : '' ) . ' onchange="' . $onchange . '">';
2149
+ foreach ( $taxonomies as $taxonomy ) {
2150
+ $rv[] = '<option value="' . $taxonomy->name . '" ' . ( $selected === $taxonomy->name ? 'selected="selected"' : '' ) . '>' . $taxonomy->name . '</option>';
2151
+ }
2152
+
2153
+ $rv[] = '</select>';
2154
+ $rv[] = __( 'Select the hierarchical taxonomy to be used for "category" based expiration.', 'post-expirator' );
2155
+ } else {
2156
+ $rv[] = 'No taxonomies found for post type.';
2157
+ }
2158
+ return implode( "<br/>\n", $rv );
2159
+ }
2160
+
2161
+ /**
2162
+ * Include the JS.
2163
+ *
2164
+ * @internal
2165
+ *
2166
+ * @access private
2167
+ */
2168
+ function postexpirator_quickedit_javascript() {
2169
+ // if using code as plugin
2170
+ wp_enqueue_script( 'postexpirator-edit', POSTEXPIRATOR_BASEURL . '/admin-edit.js', array( 'jquery', 'inline-edit-post' ), POSTEXPIRATOR_VERSION, true );
2171
+ wp_localize_script(
2172
+ 'postexpirator-edit', 'config', array(
2173
+ 'ajax' => array(
2174
+ 'nonce' => wp_create_nonce( POSTEXPIRATOR_SLUG ),
2175
+ 'bulk_edit' => 'manage_wp_posts_using_bulk_quick_save_bulk_edit',
2176
+ ),
2177
+ )
2178
+ );
2179
+ }
2180
+ add_action( 'admin_print_scripts-edit.php', 'postexpirator_quickedit_javascript' );
2181
+
2182
+ /**
2183
+ * Receives AJAX call from bulk edit to process save.
2184
+ *
2185
+ * @internal
2186
+ *
2187
+ * @access private
2188
+ */
2189
+ function postexpirator_date_save_bulk_edit() {
2190
+ check_ajax_referer( POSTEXPIRATOR_SLUG, 'nonce' );
2191
+
2192
+ // we need the post IDs
2193
+ $post_ids = ( isset( $_POST['post_ids'] ) && ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : null;
2194
+
2195
+ // if we have post IDs
2196
+ if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
2197
+
2198
+ $status = $_POST['expirationdate_status'];
2199
+
2200
+ // if no change, do nothing
2201
+ if ( $status === 'no-change' ) {
2202
+ return;
2203
+ }
2204
+
2205
+ $month = intval( $_POST['expirationdate_month'] );
2206
+ $day = intval( $_POST['expirationdate_day'] );
2207
+ $year = intval( $_POST['expirationdate_year'] );
2208
+ $hour = intval( $_POST['expirationdate_hour'] );
2209
+ $minute = intval( $_POST['expirationdate_minute'] );
2210
+
2211
+ // default to current date and/or year if not provided by user.
2212
+ if ( empty( $day ) ) {
2213
+ $day = date( 'd' );
2214
+ }
2215
+ if ( empty( $year ) ) {
2216
+ $year = date( 'Y' );
2217
+ }
2218
+
2219
+ $ts = get_gmt_from_date( "$year-$month-$day $hour:$minute:0", 'U' );
2220
+
2221
+ if ( ! $ts ) {
2222
+ return;
2223
+ }
2224
+
2225
+ foreach ( $post_ids as $post_id ) {
2226
+ $ed = get_post_meta( $post_id, '_expiration-date', true );
2227
+ $update_expiry = false;
2228
+
2229
+ switch ( $status ) {
2230
+ case 'change-only':
2231
+ $update_expiry = ! empty( $ed );
2232
+ break;
2233
+ case 'add-only':
2234
+ $update_expiry = empty( $ed );
2235
+ break;
2236
+ case 'change-add':
2237
+ $update_expiry = true;
2238
+ break;
2239
+ case 'remove-only':
2240
+ delete_post_meta( $post_id, '_expiration-date' );
2241
+ postexpirator_unschedule_event( $post_id );
2242
+ break;
2243
+ }
2244
+
2245
+ if ( $update_expiry ) {
2246
+ update_post_meta( $post_id, '_expiration-date', $ts );
2247
+ postexpirator_schedule_event( $post_id, $ts, null );
2248
+ }
2249
+ }
2250
+ }
2251
+ }
2252
+ add_action( 'wp_ajax_manage_wp_posts_using_bulk_quick_save_bulk_edit', 'postexpirator_date_save_bulk_edit' );
readme.txt CHANGED
@@ -4,41 +4,67 @@ Author: PublishPress
4
  Author URI: https://publishpress.com
5
  Tags: expire, posts, pages, schedule
6
  Requires at least: 4.0
7
- Tested up to: 5.7
8
- Stable tag: 2.4.2
9
 
10
  Add an expiration date to posts. When your post is automatically unpublished, you can delete the post, change the status, or update the post categories.
11
 
12
  == Description ==
13
 
14
- The Post Expirator plugin allows you to add an expiration date to posts. When your post is automatically unpublished, you can delete the post, change the status, or update the post categories.
15
 
16
- There are a number of different ways that the posts can expire:
17
 
18
- * Draft
19
- * Delete
20
- * Trash
21
- * Private
22
- * Stick
23
- * Unstick
24
- * Categories: Replace
25
- * Categories: Add
26
- * Categories: Remove
27
 
28
- For each expiration event, a custom cron job will be schedule which will help reduce server overhead for busy sites.
29
 
30
- The expiration date can be displayed within the actual post by using the [postexpirator] tag. The format attribute will override the plugin
31
- default display format. See the [PHP Date Function](http://us2.php.net/manual/en/function.date.php) for valid date/time format options.
32
 
33
- NOTE: This plugin REQUIRES that WP-CRON is setup and functional on your web host. Some hosts do not support this, so please check and confirm if you run into issues using the plugin.
 
 
 
 
 
 
 
 
34
 
35
- **[postexpirator] shortcode attributes**
36
 
37
- * type - defaults to full - valid options are full,date,time
38
- * dateformat - format set here will override the value set on the settings page
39
- * timeformat - format set here will override the value set on the settings page
40
 
41
- This plugin is fully compatible with WordPress Multisite Mode.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  == Installation ==
44
 
@@ -55,6 +81,15 @@ This section describes how to install the plugin and get it working.
55
 
56
  == Changelog ==
57
 
 
 
 
 
 
 
 
 
 
58
  **Version 2.4.2**
59
 
60
  * Fixed: Bulk edit does not change scheduled event bug, #29;
@@ -122,7 +157,7 @@ This section describes how to install the plugin and get it working.
122
 
123
  * New: Added support for hierarchical custom taxonomy
124
  * New: Enhanced custom post type support
125
- * Fix: Updated debug function to be friendly for scripted calls
126
  * Fix: Change to only show public custom post types on defaults screen
127
  * Fix: Removed category expiration options for 'pages', which is currently unsupported
128
  * Fix: Some date calls were getting "double" converted for the timezone pending how other plugins handled date - this issue should now be resolved
@@ -261,7 +296,6 @@ Quick Edit/Bulk Edit Added. Sortable Expiration Date Fields Added
261
  Fixed PHP Strict errors with 5.4+
262
  Removed temporary timezone conversion functions
263
 
264
-
265
  = 2.1.3 =
266
  Default category selection now saves correctly on default settings screen
267
 
4
  Author URI: https://publishpress.com
5
  Tags: expire, posts, pages, schedule
6
  Requires at least: 4.0
7
+ Tested up to: 5.8
8
+ Stable tag: 2.4.3
9
 
10
  Add an expiration date to posts. When your post is automatically unpublished, you can delete the post, change the status, or update the post categories.
11
 
12
  == Description ==
13
 
14
+ The Post Expirator plugin allows you to add an expiration date to posts. pages and other content type. When your post is automatically unpublished, you can delete the post, change the status, or update the post categories.
15
 
16
+ Here's an overview of what you can do with Post Expirator:
17
 
18
+ * Choose expiry dates for content in any post type.
19
+ * Select expiry dates in the right sidebar when editing posts.
20
+ * Modify, remove or completely delete content when the expiry date arrives.
21
+ * Modify expiry dates using "Quick Edit" and "Bulk Edit".
22
+ * Receive email notifications when your content expires.
23
+ * Show expiry dates in your content, automatically or with shortcodes.
 
 
 
24
 
25
+ ## Options for Expiring Posts
26
 
27
+ When your posts expire, you can perform these changes on your content:
 
28
 
29
+ * Change the status to "Draft".
30
+ * Delete the post.
31
+ * Send the post to the Trash.
32
+ * Change the status to "Private".
33
+ * Enable the “Stick to the top of the blog” option.
34
+ * Disable the “Stick to the top of the blog” option.
35
+ * Remove all existing categories, and add new categories.
36
+ * Keep all existing categories, and add new categories.
37
+ * Keep all existing categories, except for those specified in this change.
38
 
39
+ [Click here for more details on expiring posts](https://publishpress.com/knowledge-base/ways-to-expire-posts/).
40
 
41
+ ## Display the Expiry Date in Your Content
 
 
42
 
43
+ Post Expirator allows you to place automatically show the expiry date inside your articles. The expiry will be added at the bottom of your post.
44
+
45
+ [Click here to see the Footer Display options](https://publishpress.com/knowledge-base/footer-display/).
46
+
47
+ You can use shortcodes to show the expiration date inside your posts. You can customize the shortcode output with several formatting options.
48
+
49
+ [Click here to see the shortcode options](https://publishpress.com/knowledge-base/shortcodes-to-show-expiration-date/).
50
+
51
+ ## Expiry Defaults for Post Types
52
+
53
+ Post Expirator can support any post type in WordPress. Go to Settings > Post Expirator > Defaults and you can choose default expiry options for each post type.
54
+
55
+ [Click here to see the default options](https://publishpress.com/knowledge-base/defaults-for-post-types/).
56
+
57
+ ## Post Expirator Email Notifications
58
+
59
+ The Post Expirator plugin can send you email notifications when your content is unpublished. You can control the emails by going to Settings > Post Expirator > General Settings.
60
+
61
+ [Click here to see the notification options](https://publishpress.com/knowledge-base/email-notifications/).
62
+
63
+ ## Details on How Post Expiry Works
64
+
65
+ For each expiration event, a custom cron job is scheduled. This can help reduce server overhead for busy sites. This plugin REQUIRES that WP-CRON is setup and functional on your webhost. Some hosts do not support this, so please check and confirm if you run into issues using the plugin.
66
+
67
+ [Click here to see the technical details for this plugin](https://publishpress.com/knowledge-base/scheduling-cron-jobs/).
68
 
69
  == Installation ==
70
 
81
 
82
  == Changelog ==
83
 
84
+ **Version 2.4.3**
85
+
86
+ * Added: Expose wrappers for legacy functions, #40;
87
+ * Added: Support for quotes in Default expiry, #43;
88
+ * Fixed: Default expiry duration is broken for future years, #39;
89
+ * Fixed: Translation bug, #5;
90
+ * Fixed: Post expiring one year early, #24;
91
+ * Changed: Bulk and Quick Edit boxes default to current date/year, #46;
92
+
93
  **Version 2.4.2**
94
 
95
  * Fixed: Bulk edit does not change scheduled event bug, #29;
157
 
158
  * New: Added support for hierarchical custom taxonomy
159
  * New: Enhanced custom post type support
160
+ * Fix: Updated debug function to be friendly for scripted calls
161
  * Fix: Change to only show public custom post types on defaults screen
162
  * Fix: Removed category expiration options for 'pages', which is currently unsupported
163
  * Fix: Some date calls were getting "double" converted for the timezone pending how other plugins handled date - this issue should now be resolved
296
  Fixed PHP Strict errors with 5.4+
297
  Removed temporary timezone conversion functions
298
 
 
299
  = 2.1.3 =
300
  Default category selection now saves correctly on default settings screen
301