Post Expirator - Version 2.4.2

Version Description

Download this release

Release Info

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

Code changes from version 2.4.1 to 2.4.2

Files changed (5) hide show
  1. admin-edit.js +6 -5
  2. languages/post-expirator.pot +274 -120
  3. post-expirator-debug.php +46 -22
  4. post-expirator.php +1208 -915
  5. readme.txt +17 -11
admin-edit.js CHANGED
@@ -1,4 +1,4 @@
1
- (function($) {
2
 
3
  // we create a copy of the WP inline edit post function
4
  var $wp_inline_edit = inlineEditPost.edit;
@@ -55,7 +55,7 @@
55
  var $bulk_row = $( '#bulk-edit' );
56
 
57
  // get the selected post ids that are being edited
58
- var $post_ids = new Array();
59
  $bulk_row.find( '#bulk-titles' ).children().each( function() {
60
  $post_ids.push( $( this ).attr( 'id' ).replace( /^(ttle)/i, '' ) );
61
  });
@@ -74,16 +74,17 @@
74
  async: false,
75
  cache: false,
76
  data: {
77
- action: 'manage_wp_posts_using_bulk_quick_save_bulk_edit', // this is the name of our WP AJAX function that we'll set up next
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
  }
85
  });
86
 
87
  });
88
 
89
- })(jQuery);
1
+ (function($, config) {
2
 
3
  // we create a copy of the WP inline edit post function
4
  var $wp_inline_edit = inlineEditPost.edit;
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
  });
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);
languages/post-expirator.pot CHANGED
@@ -1,393 +1,555 @@
1
- # Copyright (C) 2013 Post Expirator
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.0.0\n"
6
- "Report-Msgid-Bugs-To: http://wordpress.org/tag/post-expirator\n"
7
- "POT-Creation-Date: 2013-03-09 22:46:54+00:00\n"
 
8
  "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2013-MO-DA HO:MI+ZONE\n"
12
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
- "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
- #: post-expirator-debug.php:47
16
  msgid "Debugging table is currently empty."
17
  msgstr ""
18
 
19
- #: post-expirator-debug.php:51
20
  msgid "Timestamp"
21
  msgstr ""
22
 
23
- #: post-expirator-debug.php:52
24
  msgid "Message"
25
  msgstr ""
26
 
27
- #: post-expirator.php:22
28
  msgid "l F jS, Y"
29
  msgstr ""
30
 
31
- #: post-expirator.php:23
32
  msgid "g:ia"
33
  msgstr ""
34
 
35
- #: post-expirator.php:24
36
  msgid "Post expires at EXPIRATIONTIME on EXPIRATIONDATE"
37
  msgstr ""
38
 
39
- #: post-expirator.php:33
40
  msgid "Settings"
41
  msgstr ""
42
 
43
- #: post-expirator.php:51
44
  msgid "Expires"
45
  msgstr ""
46
 
47
- #: post-expirator.php:65
48
  msgid "Never"
49
  msgstr ""
50
 
51
- #. #-#-#-#-# plugin.pot (Post Expirator 2.0.0) #-#-#-#-#
52
- #. Plugin Name of the plugin/theme
53
- #: post-expirator.php:77 post-expirator.php:79 post-expirator.php:562
54
- msgid "Post Expirator"
55
  msgstr ""
56
 
57
- #: post-expirator.php:150
58
  msgid "Enable Post Expiration"
59
  msgstr ""
60
 
61
- #: post-expirator.php:153
62
  msgid "The published date/time will be used as the expiration value"
63
  msgstr ""
64
 
65
- #: post-expirator.php:156
66
  msgid "Year"
67
  msgstr ""
68
 
69
- #: post-expirator.php:157
70
  msgid "Month"
71
  msgstr ""
72
 
73
- #: post-expirator.php:158
74
  msgid "Day"
75
  msgstr ""
76
 
77
- #: post-expirator.php:190
78
  msgid "Hour"
79
  msgstr ""
80
 
81
- #: post-expirator.php:191
82
  msgid "Minute"
83
  msgstr ""
84
 
85
- #: post-expirator.php:211
86
  msgid "How to expire"
87
  msgstr ""
88
 
89
- #: post-expirator.php:222
90
  msgid "Expiration Categories"
91
  msgstr ""
92
 
93
- #: post-expirator.php:529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  msgid "General Settings"
95
  msgstr ""
96
 
97
- #: post-expirator.php:530 post-expirator.php:623
98
  msgid "Defaults"
99
  msgstr ""
100
 
101
- #: post-expirator.php:531
102
  msgid "Diagnostics"
103
  msgstr ""
104
 
105
- #: post-expirator.php:532
106
  msgid "View Debug Logs"
107
  msgstr ""
108
 
109
- #: post-expirator.php:543 post-expirator.php:562
110
  msgid "Post Expirator Options"
111
  msgstr ""
112
 
113
- #: post-expirator.php:581
114
  msgid "Saved Options!"
115
  msgstr ""
116
 
117
- #: post-expirator.php:612
118
  msgid ""
119
  "The post expirator plugin sets a custom meta value, and then optionally "
120
  "allows you to select if you want the post changed to a draft status or "
121
  "deleted when it expires."
122
  msgstr ""
123
 
124
- #: post-expirator.php:615
125
  msgid "Valid [postexpirator] attributes:"
126
  msgstr ""
127
 
128
- #: post-expirator.php:617
129
  msgid "type - defaults to full - valid options are full,date,time"
130
  msgstr ""
131
 
132
- #: post-expirator.php:618
133
  msgid ""
134
- "dateformat - format set here will override the value set on the settings page"
 
135
  msgstr ""
136
 
137
- #: post-expirator.php:619
138
  msgid ""
139
- "timeformat - format set here will override the value set on the settings page"
 
140
  msgstr ""
141
 
142
- #: post-expirator.php:626
143
  msgid "Date Format:"
144
  msgstr ""
145
 
146
- #: post-expirator.php:630
147
  msgid ""
148
  "The default format to use when displaying the expiration date within a post "
149
  "using the [postexpirator] shortcode or within the footer. For information "
150
- "on valid formatting options, see: <a href=\"http://us2.php.net/manual/en/"
151
- "function.date.php\" target=\"_blank\">PHP Date Function</a>."
 
152
  msgstr ""
153
 
154
- #: post-expirator.php:634
155
  msgid "Time Format:"
156
  msgstr ""
157
 
158
- #: post-expirator.php:638
159
  msgid ""
160
  "The default format to use when displaying the expiration time within a post "
161
  "using the [postexpirator] shortcode or within the footer. For information "
162
- "on valid formatting options, see: <a href=\"http://us2.php.net/manual/en/"
163
- "function.date.php\" target=\"_blank\">PHP Date Function</a>."
 
164
  msgstr ""
165
 
166
- #: post-expirator.php:642
167
  msgid "Default Date/Time Duration:"
168
  msgstr ""
169
 
170
- #: post-expirator.php:645
171
  msgid "None"
172
  msgstr ""
173
 
174
- #: post-expirator.php:646
175
  msgid "Custom"
176
  msgstr ""
177
 
178
- #: post-expirator.php:647
179
  msgid "Post/Page Publish Time"
180
  msgstr ""
181
 
182
- #: post-expirator.php:650
183
  msgid ""
184
  "Set the default expiration date to be used when creating new posts and "
185
  "pages. Defaults to none."
186
  msgstr ""
187
 
188
- #: post-expirator.php:655
189
  msgid ""
190
  "Set the custom value to use for the default expiration date. For "
191
- "information on formatting, see <a href=\"http://php.net/manual/en/function."
192
- "strtotime.php\">PHP strtotime function</a>."
 
 
193
  msgstr ""
194
 
195
- #: post-expirator.php:660
196
  msgid "Category Expiration"
197
  msgstr ""
198
 
199
- #: post-expirator.php:663
200
  msgid "Default Expiration Category"
201
  msgstr ""
202
 
203
- #: post-expirator.php:674
204
  msgid "Set's the default expiration category for the post."
205
  msgstr ""
206
 
207
- #: post-expirator.php:679
208
- msgid "Post Footer Display"
209
  msgstr ""
210
 
211
- #: post-expirator.php:680
212
  msgid ""
213
- "Enabling this below will display the expiration date automatically at the "
214
- "end of any post which is set to expire."
215
  msgstr ""
216
 
217
- #: post-expirator.php:683
218
- msgid "Show in post footer?"
219
  msgstr ""
220
 
221
- #: post-expirator.php:685 post-expirator.php:772
 
222
  msgid "Enabled"
223
  msgstr ""
224
 
225
- #: post-expirator.php:686 post-expirator.php:773
 
226
  msgid "Disabled"
227
  msgstr ""
228
 
229
- #: post-expirator.php:688
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  msgid ""
231
  "This will enable or disable displaying the post expiration date in the post "
232
  "footer."
233
  msgstr ""
234
 
235
- #: post-expirator.php:692
236
  msgid "Footer Contents:"
237
  msgstr ""
238
 
239
- #: post-expirator.php:696
240
  msgid ""
241
  "Enter the text you would like to appear at the bottom of every post that "
242
  "will expire. The following placeholders will be replaced with the post "
243
  "expiration date in the following format:"
244
  msgstr ""
245
 
246
- #: post-expirator.php:705
247
  msgid "Footer Style:"
248
  msgstr ""
249
 
250
- #: post-expirator.php:708
251
  msgid "This post will expire on"
252
  msgstr ""
253
 
254
- #: post-expirator.php:710
255
  msgid "The inline css which will be used to style the footer text."
256
  msgstr ""
257
 
258
- #: post-expirator.php:715 post-expirator.php:783
259
  msgid "Save Changes"
260
  msgstr ""
261
 
262
- #: post-expirator.php:743
263
  msgid "Default Expiration Values"
264
  msgstr ""
265
 
266
- #: post-expirator.php:745
267
  msgid ""
268
  "Use the values below to set the default actions/values to be used for each "
269
- "for the corresponding post types. These values can all be overwridden when "
270
  "creating/editing the post/page."
271
  msgstr ""
272
 
273
- #: post-expirator.php:761
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  msgid "How to expire:"
275
  msgstr ""
276
 
277
- #: post-expirator.php:766
278
  msgid "Select the default expire action for the post type."
279
  msgstr ""
280
 
281
- #: post-expirator.php:770
282
  msgid "Auto-Enable?"
283
  msgstr ""
284
 
285
- #: post-expirator.php:775
286
  msgid "Select whether the post expirator is enabled for all new posts."
287
  msgstr ""
288
 
289
- #: post-expirator.php:792
 
 
 
 
 
 
 
 
 
 
290
  msgid "Debugging Disabled"
291
  msgstr ""
292
 
293
- #: post-expirator.php:795
294
  msgid "Debugging Enabled"
295
  msgstr ""
296
 
297
- #: post-expirator.php:800
298
  msgid "Debugging Table Emptied"
299
  msgstr ""
300
 
301
- #: post-expirator.php:806
302
  msgid "Advanced Diagnostics"
303
  msgstr ""
304
 
305
- #: post-expirator.php:809
306
  msgid "Post Expirator Debug Logging:"
307
  msgstr ""
308
 
309
- #: post-expirator.php:813
310
  msgid "Status: Enabled"
311
  msgstr ""
312
 
313
- #: post-expirator.php:814
314
  msgid "Disable Debugging"
315
  msgstr ""
316
 
317
- #: post-expirator.php:816
318
  msgid "Status: Disabled"
319
  msgstr ""
320
 
321
- #: post-expirator.php:817
322
  msgid "Enable Debugging"
323
  msgstr ""
324
 
325
- #: post-expirator.php:825
326
  msgid "Purge Debug Log:"
327
  msgstr ""
328
 
329
- #: post-expirator.php:827
330
  msgid "Purge Debug Log"
331
  msgstr ""
332
 
333
- #: post-expirator.php:831
 
 
 
 
 
 
 
 
 
 
 
 
334
  msgid "Current Cron Schedule:"
335
  msgstr ""
336
 
337
- #: post-expirator.php:833
338
  msgid ""
339
  "The below table will show all currently scheduled cron events with the next "
340
  "run time."
341
  msgstr ""
342
 
343
- #: post-expirator.php:837
344
  msgid "Date"
345
  msgstr ""
346
 
347
- #: post-expirator.php:838
348
  msgid "Event"
349
  msgstr ""
350
 
351
- #: post-expirator.php:839
352
  msgid "Arguments / Schedule"
353
  msgstr ""
354
 
355
- #: post-expirator.php:864
356
  msgid "Single Event"
357
  msgstr ""
358
 
359
- #: post-expirator.php:885
360
  msgid ""
361
  "Below is a dump of the debugging table, this should be useful for "
362
  "troubleshooting."
363
  msgstr ""
364
 
365
- #: post-expirator.php:1146
366
  msgid "Draft"
367
  msgstr ""
368
 
369
- #: post-expirator.php:1147
370
  msgid "Delete"
371
  msgstr ""
372
 
373
- #: post-expirator.php:1148
 
 
 
 
374
  msgid "Private"
375
  msgstr ""
376
 
377
- #: post-expirator.php:1149
 
 
 
 
 
 
 
 
378
  msgid "Category: Replace"
379
  msgstr ""
380
 
381
- #: post-expirator.php:1150
382
  msgid "Category: Add"
383
  msgstr ""
384
 
385
- #: post-expirator.php:1151
386
  msgid "Category: Remove"
387
  msgstr ""
388
 
389
- #. Plugin URI of the plugin/theme
390
- msgid "http://wordpress.org/extend/plugins/post-expirator/"
 
 
391
  msgstr ""
392
 
393
  #. Description of the plugin/theme
@@ -395,12 +557,4 @@ msgid ""
395
  "Allows you to add an expiration date (minute) to posts which you can "
396
  "configure to either delete the post, change it to a draft, or update the "
397
  "post categories at expiration time."
398
- msgstr ""
399
-
400
- #. Author of the plugin/theme
401
- msgid "Aaron Axelsen"
402
- msgstr ""
403
-
404
- #. Author URI of the plugin/theme
405
- msgid "http://postexpirator.tuxdocs.net/"
406
- 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.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
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 ""
 
 
 
 
 
 
 
 
post-expirator-debug.php CHANGED
@@ -1,64 +1,88 @@
1
  <?php
2
 
3
- class postExpiratorDebug {
4
 
 
 
 
 
 
 
 
 
5
  function __construct() {
6
  global $wpdb;
7
  $this->debug_table = $wpdb->prefix . 'postexpirator_debug';
8
  $this->createDBTable();
9
  }
10
-
11
  /**
12
  * Create Database Table to store debugging information if it does not already exist.
13
  */
14
  private function createDBTable() {
15
  global $wpdb;
16
 
17
- if ($wpdb->get_var("SHOW TABLES LIKE '".$this->debug_table."'") != $this->debug_table) {
18
- $sql = "CREATE TABLE `".$this->debug_table."` (
19
  `id` INT(9) NOT NULL AUTO_INCREMENT PRIMARY KEY,
20
  `timestamp` TIMESTAMP NOT NULL,
21
  `blog` INT(9) NOT NULL,
22
  `message` text NOT NULL
23
- );";
24
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
25
- dbDelta($sql);
26
  }
27
  }
28
 
 
 
 
29
  public function removeDBTable() {
30
  global $wpdb;
31
- $wpdb->query('DROP TABLE IF EXISTS '.$this->debug_table);
32
- }
33
 
34
- public function save($data) {
 
 
 
35
  global $wpdb;
36
- if (is_multisite()) {
37
  global $current_blog;
38
  $blog = $current_blog->blog_id;
39
- } else $blog = 0;
40
- $wpdb->query($wpdb->prepare('INSERT INTO '.$this->debug_table.' (`timestamp`,`message`,`blog`) VALUES (FROM_UNIXTIME(%d),%s,%s)',time(),$data['message'],$blog));
 
 
41
  }
42
 
 
 
 
43
  public function getTable() {
44
  global $wpdb;
45
- $results = $wpdb->get_results("SELECT * FROM {$this->debug_table} ORDER BY `id` DESC");
46
- if (empty($results)) {
47
- print '<p>'.__('Debugging table is currently empty.','post-expirator').'</p>';
48
  return;
49
  }
50
  print '<table class="post-expirator-debug">';
51
- print '<tr><th class="post-expirator-timestamp">'.__('Timestamp','post-expirator').'</th>';
52
- print '<th>'.__('Message','post-expirator').'</th></tr>';
53
- foreach ($results as $result) {
54
- print '<tr><td>'.$result->timestamp.'</td>';
55
- print '<td>'.$result->message.'</td></tr>';
56
  }
57
  print '</table>';
58
  }
59
 
 
 
 
60
  public function purge() {
61
  global $wpdb;
62
- $wpdb->query("TRUNCATE TABLE {$this->debug_table}");
63
  }
64
  }
 
 
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
@@ -4,154 +4,164 @@ 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.1
8
  Author URI: http://postexpirator.tuxdocs.net/
9
  Text Domain: post-expirator
 
10
  */
11
 
12
- /* Load translation, if it exists */
13
- function postExpirator_init() {
14
- $plugin_dir = basename(dirname(__FILE__));
15
- load_plugin_textdomain( 'post-expirator', null, $plugin_dir.'/languages/' );
16
- }
17
- add_action('plugins_loaded', 'postExpirator_init');
18
-
19
  // Default Values
20
- define('POSTEXPIRATOR_VERSION','2.4.1');
21
- define('POSTEXPIRATOR_DATEFORMAT',__('l F jS, Y','post-expirator'));
22
- define('POSTEXPIRATOR_TIMEFORMAT',__('g:ia','post-expirator'));
23
- define('POSTEXPIRATOR_FOOTERCONTENTS',__('Post expires at EXPIRATIONTIME on EXPIRATIONDATE','post-expirator'));
24
- define('POSTEXPIRATOR_FOOTERSTYLE','font-style: italic;');
25
- define('POSTEXPIRATOR_FOOTERDISPLAY','0');
26
- define('POSTEXPIRATOR_EMAILNOTIFICATION','0');
27
- define('POSTEXPIRATOR_EMAILNOTIFICATIONADMINS','0');
28
- define('POSTEXPIRATOR_DEBUGDEFAULT','0');
29
- define('POSTEXPIRATOR_EXPIREDEFAULT','null');
30
-
31
- function postExpirator_plugin_action_links($links, $file) {
32
- $this_plugin = basename(plugin_dir_url(__FILE__)) . '/post-expirator.php';
33
- if($file == $this_plugin) {
34
- $links[] = '<a href="options-general.php?page=post-expirator">' . __('Settings', 'post-expirator') . '</a>';
35
- }
36
- return $links;
 
 
 
 
37
  }
38
- add_filter('plugin_action_links', 'postExpirator_plugin_action_links', 10, 2);
39
 
40
  /**
41
- * Add admin notice hook if cron schedule needs to be reset
42
  */
43
- add_action('admin_notices','postExpirationAdminNotice');
44
- function postExpirationAdminNotice() {
45
- // Check if WP-Cron is Enabled
46
- #if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true) {
47
- # $class = 'notice notice-error';
48
- # $message = __( 'POST EXPIRATOR ERROR: WP-Cron is disabled on this server. This plugin requires WP-Cron and will not function until it is corrected.','post-expirator');
49
- # $message .= '<br/><br/>' . __( ' If you have manually configured cron click here to dismiss this message.', 'post-expirator' );
50
- # printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), $message );
51
- #}
52
  }
 
53
 
54
  /**
55
- * adds an 'Expires' column to the post display table.
56
  */
57
- add_filter ('manage_posts_columns', 'expirationdate_add_column', 10, 2);
58
- function expirationdate_add_column ($columns,$type) {
59
- $defaults = get_option('expirationdateDefaults'.ucfirst($type));
60
- if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
61
- $columns['expirationdate'] = __('Expires','post-expirator');
62
  }
63
- return $columns;
64
  }
 
65
 
66
- add_action( 'init', 'init_managesortablecolumns', 100 );
67
- function init_managesortablecolumns (){
68
- $post_types = get_post_types(array('public'=>true));
69
- foreach( $post_types as $post_type ){
70
- add_filter( 'manage_edit-' . $post_type . '_sortable_columns', 'expirationdate_sortable_column' );
71
- }
 
 
72
  }
73
- function expirationdate_sortable_column($columns) {
 
 
 
 
 
74
  $columns['expirationdate'] = 'expirationdate';
75
  return $columns;
76
  }
77
 
78
- add_action( 'pre_get_posts', 'my_expirationdate_orderby' );
79
- function my_expirationdate_orderby( $query ) {
80
- if( ! is_admin() )
81
- return;
82
-
83
- $orderby = $query->get( 'orderby');
84
-
85
- if( 'expirationdate' == $orderby ) {
86
- $query->set('meta_query',array(
87
- 'relation' => 'OR',
88
- array(
89
- 'key' => '_expiration-date',
90
- 'compare' => 'EXISTS'
91
- ),
92
- array(
93
- 'key' => '_expiration-date',
94
- 'compare' => 'NOT EXISTS',
95
- 'value' => ''
96
- )
97
- ));
98
- $query->set('orderby','meta_value_num');
99
- }
 
 
 
 
 
100
  }
 
101
 
102
  /**
103
- * adds an 'Expires' column to the page display table.
104
  */
105
- add_filter ('manage_pages_columns', 'expirationdate_add_column_page');
106
- function expirationdate_add_column_page ($columns) {
107
- $defaults = get_option('expirationdateDefaultsPage');
108
- if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
109
- $columns['expirationdate'] = __('Expires','post-expirator');
110
  }
111
- return $columns;
112
  }
 
113
 
114
  /**
115
- * fills the 'Expires' column of the post display table.
116
  */
117
- add_action ('manage_posts_custom_column', 'expirationdate_show_value');
118
- add_action ('manage_pages_custom_column', 'expirationdate_show_value');
119
- function expirationdate_show_value ($column_name) {
120
  global $post;
121
  $id = $post->ID;
122
- if ($column_name === 'expirationdate') {
123
- $ed = get_post_meta($id,'_expiration-date',true);
124
- 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'));
125
-
126
- //Values for Quick Edit
127
- if ($ed) {
128
- $year = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'Y');
129
- $month = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'m');
130
- $day = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'d');
131
- $hour = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'H');
132
- $minute = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ed),'i');
133
- echo '<span id="expirationdate_year-'.$id.'" style="display: none;">'.$year.'</span>';
134
- echo '<span id="expirationdate_month-'.$id.'" style="display: none;">'.$month.'</span>';
135
- echo '<span id="expirationdate_day-'.$id.'" style="display: none;">'.$day.'</span>';
136
- echo '<span id="expirationdate_hour-'.$id.'" style="display: none;">'.$hour.'</span>';
137
- echo '<span id="expirationdate_minute-'.$id.'" style="display: none;">'.$minute.'</span>';
138
- echo '<span id="expirationdate_enabled-'.$id.'" style="display: none;">true</span>';
139
  } else {
140
- echo '<span id="expirationdate_year-'.$id.'" style="display: none;">'.date('Y').'</span>';
141
- echo '<span id="expirationdate_month-'.$id.'" style="display: none;">'.date('m').'</span>';
142
- echo '<span id="expirationdate_day-'.$id.'" style="display: none;">'.date('d').'</span>';
143
- echo '<span id="expirationdate_hour-'.$id.'" style="display: none;">'.date('H').'</span>';
144
- echo '<span id="expirationdate_minute-'.$id.'" style="display: none;">'.date('i').'</span>';
145
- echo '<span id="expirationdate_enabled-'.$id.'" style="display: none;">false</span>';
146
  }
147
- }
148
  }
 
 
149
 
150
 
151
- add_action( 'quick_edit_custom_box', 'display_expirationdate_quickedit', 10, 2 );
152
- function display_expirationdate_quickedit( $column_name, $post_type ) {
153
- if ($column_name != 'expirationdate') return;
154
- ?>
 
 
 
 
155
  <div style="clear:both"></div>
156
  <fieldset class="inline-edit-col-left post-expirator-quickedit">
157
  <div class="inline-edit-col">
@@ -161,8 +171,8 @@ function display_expirationdate_quickedit( $column_name, $post_type ) {
161
  <fieldset class="inline-edit-date">
162
  <legend><span class="title">Expires</span></legend>
163
  <div class="timestamp-wrap">
164
- <label><span class="screen-reader-text">Month</span>
165
- <select name="expirationdate_month">
166
  <option value="01" data-text="Jan">01-Jan</option>
167
  <option value="02" data-text="Feb">02-Feb</option>
168
  <option value="03" data-text="Mar">03-Mar</option>
@@ -175,12 +185,12 @@ function display_expirationdate_quickedit( $column_name, $post_type ) {
175
  <option value="10" data-text="Oct">10-Oct</option>
176
  <option value="11" data-text="Nov">11-Nov</option>
177
  <option value="12" data-text="Dec">12-Dec</option>
178
- </select>
179
- </label>
180
- <label><span class="screen-reader-text">Day</span>
181
- <input name="expirationdate_day" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>,
182
  <label><span class="screen-reader-text">Year</span>
183
- <input name="expirationdate_year" value="" size="4" maxlength="4" autocomplete="off" type="text"></label> @
184
  <label><span class="screen-reader-text">Hour</span>
185
  <input name="expirationdate_hour" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>:
186
  <label><span class="screen-reader-text">Minute</span>
@@ -190,24 +200,29 @@ function display_expirationdate_quickedit( $column_name, $post_type ) {
190
  </div>
191
  </div>
192
  </fieldset>
193
- <?php
194
 
195
  }
 
196
 
197
- add_action( 'bulk_edit_custom_box', 'display_expirationdate_bulkedit', 10, 2 );
198
- function display_expirationdate_bulkedit( $column_name, $post_type ) {
199
- if ($column_name != 'expirationdate') return;
200
- ?>
 
 
 
 
201
  <div style="clear:both"></div>
202
  <div class="inline-edit-col post-expirator-quickedit">
203
  <div class="inline-edit-col">
204
  <div class="inline-edit-group">
205
- <span class="title"><?php echo __('Post Expirator: Will only update expiration date if already configured on post.','post-expirator'); ?></span>
206
  <fieldset class="inline-edit-date">
207
  <legend><span class="title">Expires</span></legend>
208
  <div class="timestamp-wrap">
209
- <label><span class="screen-reader-text">Month</span>
210
- <select name="expirationdate_month">
211
  <option value="false">- No Change -</option>
212
  <option value="01" data-text="Jan">01-Jan</option>
213
  <option value="02" data-text="Feb">02-Feb</option>
@@ -221,12 +236,12 @@ function display_expirationdate_bulkedit( $column_name, $post_type ) {
221
  <option value="10" data-text="Oct">10-Oct</option>
222
  <option value="11" data-text="Nov">11-Nov</option>
223
  <option value="12" data-text="Dec">12-Dec</option>
224
- </select>
225
- </label>
226
- <label><span class="screen-reader-text">Day</span>
227
- <input name="expirationdate_day" placeholder="Day" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>,
228
  <label><span class="screen-reader-text">Year</span>
229
- <input name="expirationdate_year" placeholder="Year" value="" size="4" maxlength="4" autocomplete="off" type="text"></label> @
230
  <label><span class="screen-reader-text">Hour</span>
231
  <input name="expirationdate_hour" placeholder="Hour" value="" size="2" maxlength="2" autocomplete="off" type="text"></label>:
232
  <label><span class="screen-reader-text">Minute</span>
@@ -236,196 +251,215 @@ function display_expirationdate_bulkedit( $column_name, $post_type ) {
236
  </div>
237
  </div>
238
  </div>
239
- <?php
240
 
241
  }
 
242
 
243
  /**
244
  * Adds hooks to get the meta box added to pages and custom post types
245
  */
246
- function expirationdate_meta_custom() {
247
  $custom_post_types = get_post_types();
248
- array_push($custom_post_types,'page');
249
- foreach ($custom_post_types as $t) {
250
- $defaults = get_option('expirationdateDefaults'.ucfirst($t));
251
- if (!isset($defaults['activeMetaBox']) || $defaults['activeMetaBox'] == 'active') {
252
- add_meta_box('expirationdatediv', __('Post Expirator','post-expirator'), 'expirationdate_meta_box', $t, 'side', 'core');
253
  }
254
  }
255
  }
256
- add_action ('add_meta_boxes','expirationdate_meta_custom');
257
 
258
  /**
259
  * Actually adds the meta box
260
  */
261
- function expirationdate_meta_box($post) {
262
  // Get default month
263
- $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
264
- $firstsave = get_post_meta($post->ID,'_expiration-date-status',true);
265
 
266
  // nonce
267
  wp_nonce_field( '__postexpirator', '_postexpiratornonce' );
268
 
269
  $default = '';
270
  $expireType = '';
271
- $defaults = get_option('expirationdateDefaults'.ucfirst($post->post_type));
272
- if (empty($expirationdatets)) {
273
- $default = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
274
- if ($default == 'null') {
275
- $defaultmonth = date_i18n('m');
276
- $defaultday = date_i18n('d');
277
- $defaulthour = date_i18n('H');
278
- $defaultyear = date_i18n('Y');
279
- $defaultminute = date_i18n('i');
280
-
281
- } elseif ($default == 'custom') {
282
- $custom = get_option('expirationdateDefaultDateCustom');
283
- if ($custom === false) $ts = time();
284
- else {
285
- $tz = get_option('timezone_string');
286
- if ( $tz ) date_default_timezone_set( $tz );
287
- $ts = time() + (strtotime($custom) - time());
288
- if ( $tz ) date_default_timezone_set('UTC');
 
 
 
 
 
 
 
 
 
289
  }
290
- $defaultmonth = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'m');
291
- $defaultday = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'d');
292
- $defaultyear = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'Y');
293
- $defaulthour = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'H');
294
- $defaultminute = get_date_from_gmt(gmdate('Y-m-d H:i:s',$ts),'i');
295
  }
296
 
297
  $enabled = '';
298
  $disabled = ' disabled="disabled"';
299
- $categories = get_option('expirationdateCategoryDefaults');
300
 
301
- if (isset($defaults['expireType'])) {
302
  $expireType = $defaults['expireType'];
303
  }
304
 
305
- if (isset($defaults['autoEnable']) && ($firstsave !== 'saved') && ($defaults['autoEnable'] === true || $defaults['autoEnable'] == 1)) {
306
- $enabled = ' checked="checked"';
307
- $disabled='';
308
- }
 
309
  } else {
310
- $defaultmonth = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'m');
311
- $defaultday = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'d');
312
- $defaultyear = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'Y');
313
- $defaulthour = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'H');
314
- $defaultminute = get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),'i');
315
- $enabled = ' checked="checked"';
316
- $disabled = '';
317
- $opts = get_post_meta($post->ID,'_expiration-date-options',true);
318
- if (isset($opts['expireType'])) {
319
- $expireType = $opts['expireType'];
320
  }
321
- $categories = isset($opts['category']) ? $opts['category'] : false;
322
  }
323
 
324
  $rv = array();
325
- $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"'.$enabled.' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />';
326
- $rv[] = '<label for="enable-expirationdate">'.__('Enable Post Expiration','post-expirator').'</label></p>';
327
 
328
- if ($default == 'publish') {
329
- $rv[] = '<em>'.__('The published date/time will be used as the expiration value','post-expirator').'</em><br/>';
330
  } else {
331
  $rv[] = '<table><tr>';
332
- $rv[] = '<th style="text-align: left;">'.__('Year','post-expirator').'</th>';
333
- $rv[] = '<th style="text-align: left;">'.__('Month','post-expirator').'</th>';
334
- $rv[] = '<th style="text-align: left;">'.__('Day','post-expirator').'</th>';
335
  $rv[] = '</tr><tr>';
336
  $rv[] = '<td>';
337
- $rv[] = '<select name="expirationdate_year" id="expirationdate_year"'.$disabled.'>';
338
- $currentyear = date('Y');
339
 
340
- if ($defaultyear < $currentyear) $currentyear = $defaultyear;
 
 
341
 
342
- for($i = $currentyear; $i <= $currentyear + 10; $i++) {
343
- if ($i == $defaultyear)
344
  $selected = ' selected="selected"';
345
- else
346
  $selected = '';
347
- $rv[] = '<option'.$selected.'>'.($i).'</option>';
 
348
  }
349
  $rv[] = '</select>';
350
  $rv[] = '</td><td>';
351
- $rv[] = '<select name="expirationdate_month" id="expirationdate_month"'.$disabled.'>';
352
 
353
- for($i = 1; $i <= 12; $i++) {
354
- if ($defaultmonth == date_i18n('m',mktime(0, 0, 0, $i, 1, date_i18n('Y'))))
355
  $selected = ' selected="selected"';
356
- else
357
  $selected = '';
358
- $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>';
 
359
  }
360
 
361
  $rv[] = '</select>';
362
  $rv[] = '</td><td>';
363
- $rv[] = '<input type="text" id="expirationdate_day" name="expirationdate_day" value="'.$defaultday.'" size="2"'.$disabled.' />,';
364
  $rv[] = '</td></tr><tr>';
365
  $rv[] = '<th style="text-align: left;"></th>';
366
- $rv[] = '<th style="text-align: left;">'.__('Hour','post-expirator').'('.date_i18n('T',mktime(0, 0, 0, $i, 1, date_i18n('Y'))).')</th>';
367
- $rv[] = '<th style="text-align: left;">'.__('Minute','post-expirator').'</th>';
368
  $rv[] = '</tr><tr>';
369
  $rv[] = '<td>@</td><td>';
370
- $rv[] = '<select name="expirationdate_hour" id="expirationdate_hour"'.$disabled.'>';
371
 
372
- for($i = 1; $i <= 24; $i++) {
373
- if ($defaulthour == date_i18n('H',mktime($i, 0, 0, date_i18n('n'), date_i18n('j'), date_i18n('Y'))))
374
  $selected = ' selected="selected"';
375
- else
376
  $selected = '';
377
- $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>';
 
378
  }
379
 
380
  $rv[] = '</select></td><td>';
381
- $rv[] = '<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="'.$defaultminute.'" size="2"'.$disabled.' />';
382
  $rv[] = '</td></tr></table>';
383
  }
384
  $rv[] = '<input type="hidden" name="expirationdate_formcheck" value="true" />';
385
- echo implode("\n",$rv);
386
 
387
- echo '<br/>'.__('How to expire','post-expirator').': ';
388
- echo _postExpiratorExpireType(array('type' => $post->post_type, 'name'=>'expirationdate_expiretype','selected'=>$expireType,'disabled'=>$disabled,'onchange' => 'expirationdate_toggle_category(this)'));
389
  echo '<br/>';
390
 
391
- if ($post->post_type != 'page') {
392
- if (isset($expireType) && ($expireType == 'category' || $expireType == 'category-add' || $expireType == 'category-remove')) {
393
  $catdisplay = 'block';
394
  } else {
395
  $catdisplay = 'none';
396
  }
397
- echo '<div id="expired-category-selection" style="display: '.$catdisplay.'">';
398
- echo '<br/>'.__('Expiration Categories','post-expirator').':<br/>';
399
 
400
  echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
401
  echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
402
  $walker = new Walker_PostExpirator_Category_Checklist();
403
- if (!empty($disabled)) $walker->setDisabled();
404
- $taxonomies = get_object_taxonomies($post->post_type,'object');
405
- $taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true));
406
- if (sizeof($taxonomies) == 0) {
407
- echo '<p>'.__('You must assign a heirarchical taxonomy to this post type to use this feature.','post-expirator').'</p>';
408
- } elseif (sizeof($taxonomies) > 1 && !isset($defaults['taxonomy'])) {
409
- echo '<p>'.__('More than 1 heirachical taxonomy detected. You must assign a default taxonomy on the settings screen.','post-expirator').'</p>';
 
 
410
  } else {
411
- $keys = array_keys($taxonomies);
412
- $taxonomy = isset($defaults['taxonomy']) ? $defaults['taxonomy'] : $keys[0];
413
- wp_terms_checklist(0, array( 'taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
414
- echo '<input type="hidden" name="taxonomy-heirarchical" value="'.$taxonomy.'" />';
415
  }
416
  echo '</ul>';
417
  echo '</div>';
418
- if (isset($taxonomy))
419
- echo '<p class="post-expirator-taxonomy-name">'.__('Taxonomy Name','post-expirator').': '.$taxonomy.'</p>';
 
420
  echo '</div>';
421
  }
422
  echo '<div id="expirationdate_ajax_result"></div>';
423
  }
424
 
425
  /**
426
- * Add's ajax javascript
427
  */
428
- function expirationdate_js_admin_header() {
429
  // Define custom JavaScript function
430
  ?>
431
  <script type="text/javascript">
@@ -487,63 +521,66 @@ function expirationdate_toggle_defaultdate(id) {
487
  }
488
  //]]>
489
  </script>
490
- <?php
491
  }
492
- add_action('admin_head', 'expirationdate_js_admin_header' );
493
 
494
  /**
495
  * Get correct URL (HTTP or HTTPS)
496
  */
497
  function expirationdate_get_blog_url() {
498
- if (is_multisite())
499
- echo network_home_url('/');
500
- else
501
- echo home_url('/');
 
502
  }
503
 
504
  /**
505
  * Called when post is saved - stores expiration-date meta value
506
  */
507
- add_action('save_post','expirationdate_update_post_meta');
508
- function expirationdate_update_post_meta($id) {
509
  // don't run the echo if this is an auto save
510
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
511
  return;
 
512
 
513
  // don't run the echo if the function is called for saving revision.
514
- $posttype = get_post_type($id);
515
- if ( $posttype == 'revision' )
516
  return;
 
517
 
518
- if (!isset($_POST['expirationdate_quickedit'])) {
519
- if (!isset($_POST['expirationdate_formcheck']))
520
  return;
 
521
  }
522
 
523
- if (isset($_POST['enable-expirationdate'])) {
524
- $default = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
525
- if ($default == 'publish') {
526
- $month = intval($_POST['mm']);
527
- $day = intval($_POST['jj']);
528
- $year = intval($_POST['aa']);
529
- $hour = intval($_POST['hh']);
530
- $minute = intval($_POST['mn']);
531
  } else {
532
- $month = intval($_POST['expirationdate_month']);
533
- $day = intval($_POST['expirationdate_day']);
534
- $year = intval($_POST['expirationdate_year']);
535
- $hour = intval($_POST['expirationdate_hour']);
536
- $minute = intval($_POST['expirationdate_minute']);
537
  }
538
- $category = isset($_POST['expirationdate_category']) ? $_POST['expirationdate_category'] : 0;
539
 
540
- $ts = get_gmt_from_date("$year-$month-$day $hour:$minute:0",'U');
541
 
542
- if (isset($_POST['expirationdate_quickedit'])) {
543
- $ed = get_post_meta($id,'_expiration-date',true);
544
- if ($ed) {
545
- $opts = get_post_meta($id, '_expiration-date-options', true);
546
- }
547
  } else {
548
  $opts = array();
549
 
@@ -551,93 +588,125 @@ function expirationdate_update_post_meta($id) {
551
  $opts['expireType'] = $_POST['expirationdate_expiretype'];
552
  $opts['id'] = $id;
553
 
554
- if ($opts['expireType'] == 'category' || $opts['expireType'] == 'category-add' || $opts['expireType'] == 'category-remove') {
555
- if (isset($category) && !empty($category)) {
556
- if (!empty($category)) {
557
  $opts['category'] = $category;
558
  $opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical'];
559
  }
560
  }
561
  }
562
  }
563
- _scheduleExpiratorEvent($id,$ts,$opts);
564
  } else {
565
- _unscheduleExpiratorEvent($id);
566
  }
567
  }
 
568
 
569
- function _scheduleExpiratorEvent($id,$ts,$opts) {
570
- $debug = postExpiratorDebug(); //check for/load debug
 
 
 
 
 
571
 
572
- do_action('postexpiratior_schedule',$id,$ts,$opts); // allow custom actions
573
 
574
- if (wp_next_scheduled('postExpiratorExpire',array($id)) !== false) {
575
- wp_clear_scheduled_hook('postExpiratorExpire',array($id)); //Remove any existing hooks
576
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> EXISTING FOUND - UNSCHEDULED'));
 
 
577
  }
578
 
579
- wp_schedule_single_event($ts,'postExpiratorExpire',array($id));
580
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> SCHEDULED at '.date_i18n('r',$ts).' '.'('.$ts.') with options '.print_r($opts,true)));
 
 
581
 
582
  // Update Post Meta
583
- update_post_meta($id, '_expiration-date', $ts);
584
- update_post_meta($id, '_expiration-date-options', $opts);
585
- update_post_meta($id, '_expiration-date-status','saved');
 
 
586
  }
587
 
588
- function _unscheduleExpiratorEvent($id) {
589
- $debug = postExpiratorDebug(); // check for/load debug
 
 
 
590
 
591
- do_action('postexpiratior_unschedule',$id); // allow custom actions
592
 
593
- delete_post_meta($id, '_expiration-date');
594
- delete_post_meta($id, '_expiration-date-options');
595
 
596
  // Delete Scheduled Expiration
597
- if (wp_next_scheduled('postExpiratorExpire',array($id)) !== false) {
598
- wp_clear_scheduled_hook('postExpiratorExpire',array($id)); //Remove any existing hooks
599
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> UNSCHEDULED'));
 
 
600
  }
601
- update_post_meta($id, '_expiration-date-status','saved');
602
  }
603
 
604
  /**
605
  * The new expiration function, to work with single scheduled events.
606
  *
607
  * This was designed to hopefully be more flexible for future tweaks/modifications to the architecture.
608
- *
609
- * @param array $opts - options to pass into the expiration process, in key/value format
610
  */
611
- function postExpiratorExpire($id) {
612
- $debug = postExpiratorDebug(); //check for/load debug
613
 
614
- if (empty($id)) {
615
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => 'No Post ID found - exiting'));
 
 
616
  return false;
617
  }
618
 
619
- if (is_null(get_post($id))) {
620
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> Post does not exist - exiting'));
 
 
621
  return false;
622
  }
623
 
624
- $posttype = get_post_type($id);
625
- $posttitle = get_the_title($id);
626
- $postlink = get_post_permalink($id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
627
 
628
- $postoptions = get_post_meta($id,'_expiration-date-options',true);
629
- extract($postoptions);
630
- $ed = get_post_meta($id,'_expiration-date',true);
631
 
632
  // Check for default expire only if not passed in
633
- if (empty($expireType)) {
634
- $posttype = get_post_type($id);
635
- if ($posttype == 'page') {
636
- $expireType = strtolower(get_option('expirationdateExpiredPageStatus',POSTEXPIRATOR_PAGESTATUS));
637
- } elseif ($posttype == 'post') {
638
- $expireType = strtolower(get_option('expirationdateExpiredPostStatus','Draft'));
639
  } else {
640
- $expireType = apply_filters('postexpirator_custom_posttype_expire', $expireType, $posttype); //hook to set defaults for custom post types
641
  }
642
  }
643
 
@@ -647,206 +716,257 @@ function postExpiratorExpire($id) {
647
  kses_remove_filters();
648
 
649
  // Do Work
650
- if ($expireType == 'draft') {
651
- if (wp_update_post(array('ID' => $id, 'post_status' => 'draft')) == 0) {
652
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
653
  } else {
654
- $emailBody = sprintf( __( '%s (%s) has expired at %s. Post status has been successfully changed to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##',strtoupper($expireType) );
655
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
 
 
656
  }
657
- } elseif ($expireType == 'private') {
658
- if (wp_update_post(array('ID' => $id, 'post_status' => 'private')) == 0) {
659
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
660
  } else {
661
- $emailBody = sprintf( __( '%s (%s) has expired at %s. Post status has been successfully changed to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##',strtoupper($expireType) );
662
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
 
 
663
  }
664
- } elseif ($expireType == 'delete') {
665
- if (wp_delete_post($id) === false) {
666
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
667
  } else {
668
- $emailBody = sprintf( __( '%s (%s) has expired at %s. Post status has been successfully changed to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##',strtoupper($expireType) );
669
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
 
 
670
  }
671
- } elseif ($expireType == 'trash') {
672
- if (wp_trash_post($id) === false) {
673
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
674
  } else {
675
- $emailBody = sprintf( __( '%s (%s) has expired at %s. Post status has been successfully changed to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##',strtoupper($expireType) );
676
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
 
 
677
  }
678
- } elseif ($expireType == 'stick') {
679
- if (stick_post($id) === false) {
680
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
681
  } else {
682
- $emailBody = sprintf( __( '%s (%s) has expired at %s. Post "%s" status has been successfully set.', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','STICKY' );
683
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
 
 
684
  }
685
- } elseif ($expireType == 'unstick') {
686
- if (unstick_post($id) === false) {
687
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
688
  } else {
689
- $emailBody = sprintf( __( '%s (%s) has expired at %s. Post "%s" status has been successfully removed.', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','STICKY' );
690
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
 
 
691
  }
692
- } elseif ($expireType == 'category') {
693
- if (!empty($category)) {
694
- if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
695
- if (wp_update_post(array('ID' => $id, 'post_category' => $category)) == 0) {
696
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
697
  } else {
698
- $emailBody = sprintf( __( '%s (%s) has expired at %s. Post "%s" have now been set to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)));
699
- if (POSTEXPIRATOR_DEBUG) {
700
- $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
701
- $debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
702
- $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
703
  }
704
  }
705
  } else {
706
- $terms = array_map('intval', $category);
707
- if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,false))) {
708
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
709
  } else {
710
- $emailBody = sprintf( __( '%s (%s) has expired at %s. Post "%s" have now been set to "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)));
711
- if (POSTEXPIRATOR_DEBUG) {
712
- $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
713
- $debug->save(array('message' => $id.' -> CATEGORIES REPLACED '.print_r(_postExpiratorGetCatNames($category),true)));
714
- $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
715
  }
716
  }
717
  }
718
  } else {
719
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
 
 
720
  }
721
- } elseif ($expireType == 'category-add') {
722
- if (!empty($category)) {
723
- if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
724
- $cats = wp_get_post_categories($id);
725
- $merged = array_merge($cats,$category);
726
- if (wp_update_post(array('ID' => $id, 'post_category' => $merged)) == 0) {
727
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
728
  } else {
729
- $emailBody = sprintf( __( '%s (%s) has expired at %s. The following post "%s" have now been added: "%s". The full list of categories on the post are: "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)),implode(',',_postExpiratorGetCatNames($merged)));
730
- if (POSTEXPIRATOR_DEBUG) {
731
- $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
732
- $debug->save(array('message' => $id.' -> CATEGORIES ADDED '.print_r(_postExpiratorGetCatNames($category),true)));
733
- $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($merged),true)));
734
  }
735
  }
736
  } else {
737
- $terms = array_map('intval', $category);
738
- if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,true))) {
739
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
740
  } else {
741
- $emailBody = sprintf( __( '%s (%s) has expired at %s. The following post "%s" have now been added: "%s". The full list of categories on the post are: "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)),implode(',',_postExpiratorGetCatNames($merged)));
742
- if (POSTEXPIRATOR_DEBUG) {
743
- $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
744
- $debug->save(array('message' => $id.' -> CATEGORIES ADDED '.print_r(_postExpiratorGetCatNames($category),true)));
745
- $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
746
  }
747
  }
748
  }
749
  } else {
750
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
 
 
751
  }
752
- } elseif ($expireType == 'category-remove') {
753
- if (!empty($category)) {
754
- if (!isset($categoryTaxonomy) || $categoryTaxonomy == 'category') {
755
- $cats = wp_get_post_categories($id);
756
  $merged = array();
757
- foreach ($cats as $cat) {
758
- if (!in_array($cat,$category)) {
759
  $merged[] = $cat;
760
  }
761
  }
762
- if (wp_update_post(array('ID' => $id, 'post_category' => $merged)) == 0) {
763
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
764
- } else {
765
- $emailBody = sprintf( __( '%s (%s) has expired at %s. The following post "%s" have now been removed: "%s". The full list of categories on the post are: "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)),implode(',',_postExpiratorGetCatNames($merged)));
766
- if (POSTEXPIRATOR_DEBUG) {
767
- $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
768
- $debug->save(array('message' => $id.' -> CATEGORIES REMOVED '.print_r(_postExpiratorGetCatNames($category),true)));
769
- $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($merged),true)));
 
 
770
  }
771
- }
772
  } else {
773
- $terms = wp_get_object_terms($id, $categoryTaxonomy, array('fields' => 'ids'));
774
  $merged = array();
775
- foreach ($terms as $term) {
776
- if (!in_array($term,$category)) {
777
  $merged[] = $term;
778
  }
779
  }
780
- $terms = array_map('intval', $merged);
781
- if (is_wp_error(wp_set_object_terms($id,$terms,$categoryTaxonomy,false))) {
782
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> FAILED '.$expireType.' '.print_r($postoptions,true)));
 
 
783
  } else {
784
- $emailBody = sprintf( __( '%s (%s) has expired at %s. The following post "%s" have now been removed: "%s". The full list of categories on the post are: "%s".', 'post-expirator' ),'##POSTTITLE##','##POSTLINK##','##EXPIRATIONDATE##','CATEGORIES', implode(',',_postExpiratorGetCatNames($category)),implode(',',_postExpiratorGetCatNames($merged)));
785
- if (POSTEXPIRATOR_DEBUG) {
786
- $debug->save(array('message' => $id.' -> PROCESSED '.$expireType.' '.print_r($postoptions,true)));
787
- $debug->save(array('message' => $id.' -> CATEGORIES REMOVED '.print_r(_postExpiratorGetCatNames($category),true)));
788
- $debug->save(array('message' => $id.' -> CATEGORIES COMPLETE '.print_r(_postExpiratorGetCatNames($category),true)));
789
  }
790
  }
791
  }
792
- } else {
793
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> CATEGORIES MISSING '.$expireType.' '.print_r($postoptions,true)));
794
- }
 
 
795
  }
796
 
797
- //Process Email
798
- $emailenabled = get_option('expirationdateEmailNotification',POSTEXPIRATOR_EMAILNOTIFICATION);
799
- if ($emailenabled == 1 && isset($emailBody)) {
800
- $subj = sprintf( __('Post Expiration Complete "%s"', 'post-expirator'), $posttitle);
801
- $emailBody = str_replace( "##POSTTITLE##", $posttitle, $emailBody );
802
- $emailBody = str_replace( "##POSTLINK##", $postlink, $emailBody );
803
- $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 );
 
804
 
805
  $emails = array();
806
  // Get Blog Admins
807
- $emailadmins = get_option('expirationdateEmailNotificationAdmins',POSTEXPIRATOR_EMAILNOTIFICATIONADMINS);
808
- if ($emailadmins == 1) {
809
- $blogusers = get_users('role=Administrator');
810
- foreach ($blogusers as $user) {
 
811
  $emails[] = $user->user_email;
812
  }
813
  }
814
 
815
  // Get Global Notification Emails
816
- $emaillist = get_option('expirationdateEmailNotificationList');
817
- if (!empty($emaillist)) {
818
- $vals = explode(',',$emaillist);
819
- foreach ($vals as $val) {
820
- $emails[] = trim($val);
821
  }
822
  }
823
 
824
  // Get Post Type Notification Emails
825
- $defaults = get_option('expirationdateDefaults'.ucfirst($posttype));
826
- if (isset($defaults['emailnotification']) && !empty($defaults['emailnotification'])) {
827
- $vals = explode(',',$defaults['emailnotification']);
828
- foreach ($vals as $val) {
829
- $emails[] = trim($val);
830
  }
831
  }
832
 
833
  // Send Emails
834
- foreach ($emails as $email) {
835
- if (wp_mail($email, sprintf(__('[%s] %s'), get_option('blogname'), $subj), $emailBody)) {
836
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> EXPIRATION EMAIL SENT ('.$email.')'));
 
 
837
  } else {
838
- if (POSTEXPIRATOR_DEBUG) $debug->save(array('message' => $id.' -> EXPIRATION EMAIL FAILED ('.$email.')'));
 
 
839
  }
840
  }
841
  }
842
 
843
  }
844
- add_action('postExpiratorExpire','postExpiratorExpire');
845
 
846
- function _postExpiratorGetCatNames($cats) {
 
 
 
847
  $out = array();
848
- foreach ($cats as $cat) {
849
- $out[$cat] = get_the_category_by_id($cat);
850
  }
851
  return $out;
852
  }
@@ -854,34 +974,36 @@ function _postExpiratorGetCatNames($cats) {
854
  /**
855
  * Build the menu for the options page
856
  */
857
- function postExpiratorMenuTabs($tab) {
858
- echo '<p>';
859
- if (empty($tab)) $tab = 'general';
860
- 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> | ';
861
- 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> | ';
862
- 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> | ';
863
- 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>';
864
- echo '</p><hr/>';
 
 
865
  }
866
 
867
  /**
868
- *
869
  */
870
- function postExpiratorMenu() {
871
- $tab = isset($_GET['tab']) ? $_GET['tab'] : '';
872
 
873
  echo '<div class="wrap">';
874
- echo '<h2>'.__('Post Expirator Options','post-expirator').'</h2>';
875
-
876
- postExpiratorMenuTabs($tab);
877
- if (empty($tab) || $tab == 'general') {
878
- postExpiratorMenuGeneral();
879
- } elseif ($tab == 'defaults') {
880
- postExpiratorMenuDefaults();
881
- } elseif ($tab == 'diagnostics') {
882
- postExpiratorMenuDiagnostics();
883
- } elseif ($tab == 'viewdebug') {
884
- postExpiratorMenuViewdebug();
885
  }
886
  echo '</div>';
887
  }
@@ -889,330 +1011,349 @@ function postExpiratorMenu() {
889
  /**
890
  * Hook's to add plugin page menu
891
  */
892
- function postExpiratorPluginMenu() {
893
- add_submenu_page('options-general.php',__('Post Expirator Options','post-expirator'),__('Post Expirator','post-expirator'),'manage_options',basename(__FILE__),'postExpiratorMenu');
894
  }
895
- add_action('admin_menu', 'postExpiratorPluginMenu');
896
 
897
  /**
898
  * Show the Expiration Date options page
899
  */
900
- function postExpiratorMenuGeneral() {
901
- if (isset($_POST['expirationdateSave']) && $_POST['expirationdateSave']) {
902
- if ( !isset($_POST['_postExpiratorMenuGeneral_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuGeneral_nonce'],'postExpiratorMenuGeneral') ) {
903
  print 'Form Validation Failure: Sorry, your nonce did not verify.';
904
  exit;
905
  } else {
906
- //Filter Content
907
- $_POST = filter_input_array(INPUT_POST,FILTER_SANITIZE_STRING);
908
-
909
- update_option('expirationdateDefaultDateFormat',$_POST['expired-default-date-format']);
910
- update_option('expirationdateDefaultTimeFormat',$_POST['expired-default-time-format']);
911
- update_option('expirationdateDisplayFooter',$_POST['expired-display-footer']);
912
- update_option('expirationdateEmailNotification',$_POST['expired-email-notification']);
913
- update_option('expirationdateEmailNotificationAdmins',$_POST['expired-email-notification-admins']);
914
- update_option('expirationdateEmailNotificationList',trim($_POST['expired-email-notification-list']));
915
- update_option('expirationdateFooterContents',$_POST['expired-footer-contents']);
916
- update_option('expirationdateFooterStyle',$_POST['expired-footer-style']);
917
- if (isset($_POST['expirationdate_category'])) update_option('expirationdateCategoryDefaults',$_POST['expirationdate_category']);
918
- update_option('expirationdateDefaultDate',$_POST['expired-default-expiration-date']);
919
- if ($_POST['expired-custom-expiration-date']) update_option('expirationdateDefaultDateCustom',$_POST['expired-custom-expiration-date']);
920
- echo "<div id='message' class='updated fade'><p>";
921
- _e('Saved Options!','post-expirator');
922
- echo "</p></div>";
 
 
 
 
923
  }
924
  }
925
 
 
 
 
926
  // Get Option
927
- $expirationdateDefaultDateFormat = get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
928
- $expirationdateDefaultTimeFormat = get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
929
- $expireddisplayfooter = get_option('expirationdateDisplayFooter',POSTEXPIRATOR_FOOTERDISPLAY);
930
- $expiredemailnotification = get_option('expirationdateEmailNotification',POSTEXPIRATOR_EMAILNOTIFICATION);
931
- $expiredemailnotificationadmins = get_option('expirationdateEmailNotificationAdmins',POSTEXPIRATOR_EMAILNOTIFICATIONADMINS);
932
- $expiredemailnotificationlist = get_option('expirationdateEmailNotificationList','');
933
- $expirationdateFooterContents = get_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
934
- $expirationdateFooterStyle = get_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
935
- $expirationdateDefaultDate = get_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
936
- $expirationdateDefaultDateCustom = get_option('expirationdateDefaultDateCustom');
937
-
938
- $categories = get_option('expirationdateCategoryDefaults');
939
 
940
  $expireddisplayfooterenabled = '';
941
  $expireddisplayfooterdisabled = '';
942
- if ($expireddisplayfooter == 0)
943
  $expireddisplayfooterdisabled = 'checked="checked"';
944
- else if ($expireddisplayfooter == 1)
945
  $expireddisplayfooterenabled = 'checked="checked"';
 
946
 
947
  $expiredemailnotificationenabled = '';
948
  $expiredemailnotificationdisabled = '';
949
- if ($expiredemailnotification == 0)
950
  $expiredemailnotificationdisabled = 'checked="checked"';
951
- else if ($expiredemailnotification == 1)
952
  $expiredemailnotificationenabled = 'checked="checked"';
 
953
 
954
  $expiredemailnotificationadminsenabled = '';
955
  $expiredemailnotificationadminsdisabled = '';
956
- if ($expiredemailnotificationadmins == 0)
957
  $expiredemailnotificationadminsdisabled = 'checked="checked"';
958
- else if ($expiredemailnotificationadmins == 1)
959
  $expiredemailnotificationadminsenabled = 'checked="checked"';
 
960
  ?>
961
  <p>
962
- <?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'); ?>
963
  </p>
964
  <p>
965
- <?php _e('Valid [postexpirator] attributes:','post-expirator'); ?>
966
  <ul>
967
- <li><?php _e('type - defaults to full - valid options are full,date,time','post-expirator');?></li>
968
- <li><?php _e('dateformat - format set here will override the value set on the settings page','post-expirator');?></li>
969
- <li><?php _e('timeformat - format set here will override the value set on the settings page','post-expirator');?></li>
970
  </ul>
971
  </p>
972
  <form method="post" id="expirationdate_save_options">
973
- <?php wp_nonce_field('postExpiratorMenuGeneral','_postExpiratorMenuGeneral_nonce'); ?>
974
- <h3><?php _e('Defaults','post-expirator'); ?></h3>
975
  <table class="form-table">
976
  <tr valign="top">
977
- <th scope="row"><label for="expired-default-date-format"><?php _e('Date Format:','post-expirator');?></label></th>
978
  <td>
979
- <input type="text" name="expired-default-date-format" id="expired-default-date-format" value="<?php echo $expirationdateDefaultDateFormat ?>" size="25" /> (<?php echo date_i18n("$expirationdateDefaultDateFormat") ?>)
980
  <br/>
981
- <?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'); ?>
982
  </td>
983
  </tr>
984
  <tr valign="top">
985
- <th scope="row"><label for="expired-default-time-format"><?php _e('Time Format:','post-expirator');?></label></th>
986
  <td>
987
- <input type="text" name="expired-default-time-format" id="expired-default-time-format" value="<?php echo $expirationdateDefaultTimeFormat ?>" size="25" /> (<?php echo date_i18n("$expirationdateDefaultTimeFormat") ?>)
988
  <br/>
989
- <?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'); ?>
990
  </td>
991
  </tr>
992
  <tr valign="top">
993
- <th scope="row"><label for="expired-default-expiration-date"><?php _e('Default Date/Time Duration:','post-expirator');?></label></th>
994
  <td>
995
  <select name="expired-default-expiration-date" id="expired-default-expiration-date" onchange="expirationdate_toggle_defaultdate(this)">
996
- <option value="null" <?php echo ($expirationdateDefaultDate == 'null') ? ' selected="selected"' : ''; ?>><?php _e('None','post-expirator');?></option>
997
- <option value="custom" <?php echo ($expirationdateDefaultDate == 'custom') ? ' selected="selected"' : ''; ?>><?php _e('Custom','post-expirator');?></option>
998
- <option value="publish" <?php echo ($expirationdateDefaultDate == 'publish') ? ' selected="selected"' : ''; ?>><?php _e('Post/Page Publish Time','post-expirator');?></option>
999
  </select>
1000
  <br/>
1001
- <?php _e('Set the default expiration date to be used when creating new posts and pages. Defaults to none.','post-expirator'); ?>
1002
- <?php $show = ($expirationdateDefaultDate == 'custom') ? 'block' : 'none'; ?>
1003
  <div id="expired-custom-container" style="display: <?php echo $show; ?>;">
1004
  <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" />
1005
  <br/>
1006
- <?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'); ?>
1007
  </div>
1008
  </td>
1009
  </tr>
1010
  </table>
1011
- <h3><?php _e('Category Expiration','post-expirator');?></h3>
1012
  <table class="form-table">
1013
  <tr valign="top">
1014
- <th scope="row"><?php _e('Default Expiration Category','post-expirator');?>:</th>
1015
  <td>
1016
  <?php
1017
- echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
1018
- echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
1019
- $walker = new Walker_PostExpirator_Category_Checklist();
1020
- wp_terms_checklist(0, array( 'taxonomy' => 'category', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
1021
- echo '</ul>';
1022
- echo '</div>';
1023
  ?>
1024
  <br/>
1025
- <?php _e("Set's the default expiration category for the post.",'post-expirator');?>
1026
  </td>
1027
  </tr>
1028
  </table>
1029
 
1030
- <h3><?php _e('Expiration Email Notification','post-expirator');?></h3>
1031
- <p><?php _e('Whenever a post expires, an email can be sent to alert users of the expiration.','post-expirator');?></p>
1032
  <table class="form-table">
1033
  <tr valign="top">
1034
- <th scope="row"><?php _e('Enable Email Notification?','post-expirator');?></th>
1035
  <td>
1036
- <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>
1037
  <br/>
1038
- <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>
1039
  <br/>
1040
- <?php _e('This will enable or disable the send of email notification on post expiration.','post-expirator');?>
1041
  </td>
1042
  </tr>
1043
  <tr valign="top">
1044
- <th scope="row"><?php _e('Include Blog Administrators?','post-expirator');?></th>
1045
  <td>
1046
- <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>
1047
  <br/>
1048
- <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>
1049
  <br/>
1050
- <?php _e('This will include all users with the role of "Administrator" in the post expiration email.','post-expirator');?>
1051
  </td>
1052
  </tr>
1053
  <tr valign="top">
1054
- <th scope="row"><label for="expired-email-notification-list"><?php _e('Who to notify:','post-expirator'); ?></label></th>
1055
- <td>
1056
- <input class="large-text" type="text" name="expired-email-notification-list" id="expired-email-notification-list" value="<?php echo $expiredemailnotificationlist ?>" />
1057
- <br/>
1058
- <?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');?>
1059
- </td>
1060
  </tr>
1061
  </table>
1062
 
1063
- <h3><?php _e('Post Footer Display','post-expirator');?></h3>
1064
- <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>
1065
  <table class="form-table">
1066
  <tr valign="top">
1067
- <th scope="row"><?php _e('Show in post footer?','post-expirator');?></th>
1068
  <td>
1069
- <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>
1070
  <br/>
1071
- <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>
1072
  <br/>
1073
- <?php _e('This will enable or disable displaying the post expiration date in the post footer.','post-expirator');?>
1074
  </td>
1075
  </tr>
1076
  <tr valign="top">
1077
- <th scope="row"><label for="expired-footer-contents"><?php _e('Footer Contents:','post-expirator');?></label></th>
1078
  <td>
1079
  <textarea id="expired-footer-contents" name="expired-footer-contents" rows="3" cols="50"><?php echo $expirationdateFooterContents; ?></textarea>
1080
  <br/>
1081
- <?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');?>
1082
  <ul>
1083
- <li>EXPIRATIONFULL -> <?php echo date_i18n("$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat") ?></li>
1084
- <li>EXPIRATIONDATE -> <?php echo date_i18n("$expirationdateDefaultDateFormat") ?></li>
1085
- <li>EXPIRATIONTIME -> <?php echo date_i18n("$expirationdateDefaultTimeFormat") ?></li>
1086
  </ul>
1087
  </td>
1088
  </tr>
1089
  <tr valign="top">
1090
- <th scope="row"><label for="expired-footer-style"><?php _e('Footer Style:','post-expirator');?></label></th>
1091
  <td>
1092
- <input type="text" name="expired-footer-style" id="expired-footer-style" value="<?php echo $expirationdateFooterStyle ?>" size="25" />
1093
- (<span style="<?php echo $expirationdateFooterStyle ?>"><?php _e('This post will expire on','post-expirator');?> <?php echo date_i18n("$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat"); ?></span>)
1094
  <br/>
1095
- <?php _e('The inline css which will be used to style the footer text.','post-expirator');?>
1096
  </td>
1097
  </tr>
1098
  </table>
1099
  <p class="submit">
1100
- <input type="submit" name="expirationdateSave" class="button-primary" value="<?php _e('Save Changes','post-expirator');?>" />
1101
  </p>
1102
  </form>
1103
  <?php
 
1104
  }
1105
 
1106
- function postExpiratorMenuDefaults() {
1107
- $debug = postExpiratorDebug();
1108
- $types = get_post_types(array('public' => true, '_builtin' => false));
1109
- array_unshift($types,'post','page');
 
 
 
1110
 
1111
- if (isset($_POST['expirationdateSaveDefaults'])) {
1112
- if ( !isset($_POST['_postExpiratorMenuDefaults_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuDefaults_nonce'],'postExpiratorMenuDefaults') ) {
1113
  print 'Form Validation Failure: Sorry, your nonce did not verify.';
1114
  exit;
1115
  } else {
1116
- //Filter Content
1117
- $_POST = filter_input_array(INPUT_POST,FILTER_SANITIZE_STRING);
1118
 
1119
  $defaults = array();
1120
- foreach ($types as $type) {
1121
- if (isset($_POST['expirationdate_expiretype-'.$type])) {
1122
- $defaults[$type]['expireType'] = $_POST['expirationdate_expiretype-'.$type];
1123
  }
1124
- if (isset($_POST['expirationdate_autoenable-'.$type])) {
1125
- $defaults[$type]['autoEnable'] = intval($_POST['expirationdate_autoenable-'.$type]);
1126
  }
1127
- if (isset($_POST['expirationdate_taxonomy-'.$type])) {
1128
- $defaults[$type]['taxonomy'] = $_POST['expirationdate_taxonomy-'.$type];
1129
  }
1130
- if (isset($_POST['expirationdate_activemeta-'.$type])) {
1131
- $defaults[$type]['activeMetaBox'] = $_POST['expirationdate_activemeta-'.$type];
1132
  }
1133
- $defaults[$type]['emailnotification'] = trim($_POST['expirationdate_emailnotification-'.$type]);
1134
 
1135
- //Save Settings
1136
- update_option('expirationdateDefaults'.ucfirst($type),$defaults[$type]);
1137
  }
1138
- echo "<div id='message' class='updated fade'><p>";
1139
- _e('Saved Options!','post-expirator');
1140
- echo "</p></div>";
1141
  }
1142
  }
1143
 
1144
  ?>
1145
- <form method="post">
1146
- <?php wp_nonce_field('postExpiratorMenuDefaults','_postExpiratorMenuDefaults_nonce'); ?>
1147
- <h3><?php _e('Default Expiration Values','post-expirator');?></h3>
1148
  <p>
1149
- <?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'); ?>
1150
  </p>
1151
  <?php
1152
- foreach ($types as $type) {
1153
  echo "<fieldset style='border: 1px solid black; border-radius: 6px; padding: 0px 12px; margin-bottom: 20px;'>";
1154
  echo "<legend>Post Type: $type</legend>";
1155
- $defaults = get_option('expirationdateDefaults'.ucfirst($type));
1156
 
1157
- if (isset($defaults['autoEnable']) && $defaults['autoEnable'] == 1) {
 
1158
  $expiredautoenabled = 'checked = "checked"';
1159
  $expiredautodisabled = '';
1160
  } else {
1161
  $expiredautoenabled = '';
1162
  $expiredautodisabled = 'checked = "checked"';
1163
  }
1164
- if (isset($defaults['activeMetaBox']) && $defaults['activeMetaBox'] == 'inactive') {
1165
  $expiredactivemetaenabled = '';
1166
  $expiredactivemetadisabled = 'checked = "checked"';
1167
  } else {
1168
  $expiredactivemetaenabled = 'checked = "checked"';
1169
  $expiredactivemetadisabled = '';
1170
  }
1171
- if (!isset($defaults['taxonomy'])) $defaults['taxonomy'] = false;
1172
- if (!isset($defaults['emailnotification'])) $defaults['emailnotification'] = '';
 
 
 
 
1173
  ?>
1174
  <table class="form-table">
1175
  <tr valign="top">
1176
- <th scope="row"><label for="expirationdate_activemeta-<?php echo $type ?>"><?php _e('Active:','post-expirator');?></label></th>
1177
  <td>
1178
- <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>
1179
  <br/>
1180
- <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>
1181
  <br/>
1182
- <?php _e('Select whether the post expirator meta box is active for this post type.','post-expirator');?>
1183
  </td>
1184
  </tr>
1185
  <tr valign="top">
1186
- <th scope="row"><label for="expirationdate_expiretype-<?php echo $type ?>"><?php _e('How to expire:','post-expirator'); ?></label></th>
1187
  <td>
1188
- <?php echo _postExpiratorExpireType(array('name'=>'expirationdate_expiretype-'.$type,'selected' => $defaults['expireType'])); ?>
1189
  </select>
1190
  <br/>
1191
- <?php _e('Select the default expire action for the post type.','post-expirator');?>
1192
  </td>
1193
  </tr>
1194
  <tr valign="top">
1195
- <th scope="row"><label for="expirationdate_autoenable-<?php echo $type ?>"><?php _e('Auto-Enable?','post-expirator');?></label></th>
1196
  <td>
1197
- <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>
1198
  <br/>
1199
- <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>
1200
  <br/>
1201
- <?php _e('Select whether the post expirator is enabled for all new posts.','post-expirator');?>
1202
  </td>
1203
  </tr>
1204
  <tr valign="top">
1205
- <th scope="row"><label for="expirationdate_taxonomy-<?php echo $type ?>"><?php _e('Taxonomy (hierarchical):','post-expirator'); ?></label></th>
1206
  <td>
1207
- <?php echo _postExpiratorTaxonomy(array('type' => $type, 'name'=>'expirationdate_taxonomy-'.$type,'selected' => $defaults['taxonomy'])); ?>
1208
  </td>
1209
  </tr>
1210
  <tr valign="top">
1211
- <th scope="row"><label for="expirationdate_emailnotification-<?php echo $type ?>"><?php _e('Who to notify:','post-expirator'); ?></label></th>
1212
  <td>
1213
- <input class="large-text" type="text" name="expirationdate_emailnotification-<?php echo $type ?>" id="expirationdate_emailnotification-<?php echo $type ?>" value="<?php echo $defaults['emailnotification']; ?>" />
1214
  <br/>
1215
- <?php _e('Enter a comma seperate list of emails that you would like to be notified when the post expires.','post-expirator');?>
1216
  </td>
1217
  </tr>
1218
 
@@ -1221,212 +1362,246 @@ function postExpiratorMenuDefaults() {
1221
  <?php
1222
  }
1223
  ?>
1224
- <p class="submit">
1225
- <input type="submit" name="expirationdateSaveDefaults" class="button-primary" value="<?php _e('Save Changes','post-expirator');?>" />
1226
- </p>
1227
- </form>
1228
  <?php
1229
  }
1230
 
1231
- function postExpiratorMenuDiagnostics() {
1232
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1233
- if ( !isset($_POST['_postExpiratorMenuDiagnostics_nonce']) || !wp_verify_nonce($_POST['_postExpiratorMenuDiagnostics_nonce'],'postExpiratorMenuDiagnostics') ) {
 
 
 
1234
  print 'Form Validation Failure: Sorry, your nonce did not verify.';
1235
  exit;
1236
  }
1237
- if (isset($_POST['debugging-disable'])) {
1238
- update_option('expirationdateDebug',0);
1239
- echo "<div id='message' class='updated fade'><p>"; _e('Debugging Disabled','post-expirator'); echo "</p></div>";
1240
- } elseif (isset($_POST['debugging-enable'])) {
1241
- update_option('expirationdateDebug',1);
1242
- echo "<div id='message' class='updated fade'><p>"; _e('Debugging Enabled','post-expirator'); echo "</p></div>";
1243
- } elseif (isset($_POST['purge-debug'])) {
1244
- require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
1245
- $debug = new postExpiratorDebug();
 
 
 
 
1246
  $debug->purge();
1247
- echo "<div id='message' class='updated fade'><p>"; _e('Debugging Table Emptied','post-expirator'); echo "</p></div>";
 
 
1248
  }
1249
  }
1250
 
1251
- $debug = postExpiratorDebug();
1252
  ?>
1253
- <form method="post" id="postExpiratorMenuUpgrade">
1254
- <?php wp_nonce_field('postExpiratorMenuDiagnostics','_postExpiratorMenuDiagnostics_nonce'); ?>
1255
- <h3><?php _e('Advanced Diagnostics','post-expirator');?></h3>
1256
- <table class="form-table">
1257
- <tr valign="top">
1258
- <th scope="row"><label for="postexpirator-log"><?php _e('Post Expirator Debug Logging:','post-expirator');?></label></th>
1259
- <td>
1260
  <?php
1261
- if (POSTEXPIRATOR_DEBUG) {
1262
- echo __('Status: Enabled','post-expirator').'<br/>';
1263
- echo '<input type="submit" class="button" name="debugging-disable" id="debugging-disable" value="'.__('Disable Debugging','post-expirator').'" />';
1264
  } else {
1265
- echo __('Status: Disabled','post-expirator').'<br/>';
1266
- echo '<input type="submit" class="button" name="debugging-enable" id="debugging-enable" value="'.__('Enable Debugging','post-expirator').'" />';
1267
  }
1268
  ?>
1269
- <br/>
1270
- <a href="<?php echo admin_url('options-general.php?page=post-expirator.php&tab=viewdebug') ?>">View Debug Logs</a>
1271
- </td>
1272
- </tr>
1273
- <tr valign="top">
1274
- <th scope="row"><?php _e('Purge Debug Log:','post-expirator');?></th>
1275
- <td>
1276
- <input type="submit" class="button" name="purge-debug" id="purge-debug" value="<?php _e('Purge Debug Log','post-expirator');?>" />
1277
  </td>
1278
  </tr/>
1279
- <tr valign="top">
1280
- <th scope="row"><?php _e('WP-Cron Status:','post-expirator');?></th>
1281
- <td>
1282
- <?php
1283
- if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true) {
1284
- _e('DISABLED','post-expirator');
1285
  } else {
1286
- _e('ENABLED - OK','post-expirator');
1287
  }
1288
  ?>
1289
  </td>
1290
  </tr/>
1291
- <tr valign="top">
1292
- <th scope="row"><label for="cron-schedule"><?php _e('Current Cron Schedule:','post-expirator');?></label></th>
1293
- <td>
1294
- <?php _e('The below table will show all currently scheduled cron events with the next run time.','post-expirator');?><br/>
1295
  <table>
1296
  <tr>
1297
- <th style="width: 200px;"><?php _e('Date','post-expirator');?></th>
1298
- <th style="width: 200px;"><?php _e('Event','post-expirator');?></th>
1299
- <th style="width: 500px;"><?php _e('Arguments / Schedule','post-expirator');?></th>
1300
  </tr>
1301
  <?php
1302
  $cron = _get_cron_array();
1303
- foreach ($cron as $key=>$value) {
1304
- foreach ($value as $eventkey=>$eventvalue) {
1305
- print '<tr>';
1306
- print '<td>'.date_i18n('r',$key).'</td>';
1307
- print '<td>'.$eventkey.'</td>';
1308
- $arrkey = array_keys($eventvalue);
1309
- print '<td>';
1310
- foreach ($arrkey as $eventguid) {
1311
- print '<table><tr>';
1312
- if (empty($eventvalue[$eventguid]['args'])) {
1313
- print '<td>No Arguments</td>';
1314
- } else {
1315
- print '<td>';
1316
- $args = array();
1317
- foreach ($eventvalue[$eventguid]['args'] as $key=>$value) {
1318
- $args[] = "$key => $value";
 
 
 
1319
  }
1320
- print implode("<br/>\n",$args);
1321
- print '</td>';
1322
- }
1323
- if (empty($eventvalue[$eventguid]['schedule'])) {
1324
- print '<td>'.__('Single Event','post-expirator').'</td>';
1325
- } else {
1326
- print '<td>'.$eventvalue[$eventguid]['schedule'].' ('.$eventvalue[$eventguid]['interval'].')</td>';
1327
  }
1328
- print '</tr></table>';
1329
- }
1330
- print '</td>';
1331
- print '</tr>';
1332
  }
1333
  }
1334
  ?>
1335
  </table>
1336
- </td>
1337
- </tr>
1338
- </table>
1339
- </form>
1340
  <?php
1341
  }
1342
 
1343
- function postExpiratorMenuViewdebug() {
1344
- require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
1345
- print "<p>".__('Below is a dump of the debugging table, this should be useful for troubleshooting.','post-expirator')."</p>";
1346
- $debug = new postExpiratorDebug();
 
 
 
1347
  $debug->getTable();
1348
  }
1349
 
1350
- // [postexpirator format="l F jS, Y g:ia" tz="foo"]
1351
- function postexpirator_shortcode($atts) {
 
 
1352
  global $post;
1353
 
1354
- $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
1355
- if (empty($expirationdatets))
1356
  return false;
 
1357
 
1358
- extract(shortcode_atts(array(
1359
- 'dateformat' => get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT),
1360
- 'timeformat' => get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT),
1361
- 'type' => 'full',
1362
- 'tz' => date('T')
1363
- ), $atts));
 
 
 
 
 
 
1364
 
1365
- if (empty($dateformat)) {
1366
  global $expirationdateDefaultDateFormat;
1367
  $dateformat = $expirationdateDefaultDateFormat;
1368
  }
1369
 
1370
- if (empty($timeformat)) {
1371
  global $expirationdateDefaultTimeFormat;
1372
  $timeformat = $expirationdateDefaultTimeFormat;
1373
  }
1374
 
1375
- if ($type == 'full')
1376
- $format = $dateformat.' '.$timeformat;
1377
- else if ($type == 'date')
1378
  $format = $dateformat;
1379
- else if ($type == 'time')
1380
  $format = $timeformat;
 
1381
 
1382
- return get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$format);
1383
  }
1384
- add_shortcode('postexpirator', 'postexpirator_shortcode');
1385
 
1386
- function postexpirator_add_footer($text) {
 
 
 
1387
  global $post;
1388
 
1389
  // Check to see if its enabled
1390
- $displayFooter = get_option('expirationdateDisplayFooter');
1391
- if ($displayFooter === false || $displayFooter == 0)
 
 
1392
  return $text;
 
1393
 
1394
- $expirationdatets = get_post_meta($post->ID,'_expiration-date',true);
1395
- if (!is_numeric($expirationdatets))
1396
  return $text;
 
1397
 
1398
- $dateformat = get_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
1399
- $timeformat = get_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
1400
- $expirationdateFooterContents = get_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
1401
- $expirationdateFooterStyle = get_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
1402
 
1403
  $search = array(
1404
  'EXPIRATIONFULL',
1405
  'EXPIRATIONDATE',
1406
- 'EXPIRATIONTIME'
1407
  );
1408
  $replace = array(
1409
- get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),"$dateformat $timeformat"),
1410
- get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$dateformat),
1411
- get_date_from_gmt(gmdate('Y-m-d H:i:s',$expirationdatets),$timeformat)
1412
  );
1413
 
1414
- $add_to_footer = '<p style="'.$expirationdateFooterStyle.'">'.str_replace($search,$replace,$expirationdateFooterContents).'</p>';
1415
- return $text.$add_to_footer;
1416
  }
1417
- add_action('the_content','postexpirator_add_footer',0);
1418
 
1419
  /**
1420
  * Check for Debug
1421
  */
1422
- function postExpiratorDebug() {
1423
- $debug = get_option('expirationdateDebug');
1424
- if ($debug == 1) {
1425
- if (!defined('POSTEXPIRATOR_DEBUG')) define('POSTEXPIRATOR_DEBUG',1);
1426
- require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php'); // Load Class
1427
- return new postExpiratorDebug();
 
 
 
1428
  } else {
1429
- if (!defined('POSTEXPIRATOR_DEBUG')) define('POSTEXPIRATOR_DEBUG',0);
 
 
1430
  return false;
1431
  }
1432
  }
@@ -1436,15 +1611,15 @@ function postExpiratorDebug() {
1436
  * Add Stylesheet
1437
  */
1438
  function postexpirator_css() {
1439
- $myStyleUrl = plugins_url('style.css', __FILE__); // Respects SSL, Style.css is relative to the current file
1440
- $myStyleFile = WP_PLUGIN_DIR . '/post-expirator/style.css';
1441
- if ( file_exists($myStyleFile) ) {
1442
- wp_register_style('postexpirator-css', $myStyleUrl);
1443
- wp_enqueue_style('postexpirator-css');
1444
- }
1445
 
1446
  }
1447
- add_action('admin_init','postexpirator_css');
1448
 
1449
  /**
1450
  * Post Expirator Activation/Upgrade
@@ -1452,278 +1627,396 @@ add_action('admin_init','postexpirator_css');
1452
  function postexpirator_upgrade() {
1453
 
1454
  // Check for current version, if not exists, run activation
1455
- $version = get_option('postexpiratorVersion');
1456
- if ($version === false) { //not installed, run default activation
1457
  postexpirator_activate();
1458
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1459
  } else {
1460
- if (version_compare($version,'1.6.1') == -1) {
1461
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1462
- update_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
1463
  }
1464
 
1465
- if (version_compare($version,'1.6.2') == -1) {
1466
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1467
  }
1468
 
1469
- if (version_compare($version,'2.0.0-rc1') == -1) {
1470
  global $wpdb;
1471
 
1472
  // Schedule Events/Migrate Config
1473
- $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()));
1474
- foreach ($results as $result) {
1475
- wp_schedule_single_event($result->meta_value,'postExpiratorExpire',array($result->post_id));
1476
  $opts = array();
1477
  $opts['id'] = $result->post_id;
1478
- $posttype = get_post_type($result->post_id);
1479
- if ($posttype == 'page') {
1480
- $opts['expireType'] = strtolower(get_option('expirationdateExpiredPageStatus','Draft'));
1481
- } else {
1482
- $opts['expireType'] = strtolower(get_option('expirationdateExpiredPostStatus','Draft'));
1483
  }
1484
 
1485
- $cat = get_post_meta($result->post_id,'_expiration-date-category',true);
1486
- if ((isset($cat) && !empty($cat))) {
1487
  $opts['category'] = $cat;
1488
  $opts['expireType'] = 'category';
1489
  }
1490
- update_post_meta($result->post_id,'_expiration-date-options',$opts);
1491
  }
1492
 
1493
  // update meta key to new format
1494
- $wpdb->query($wpdb->prepare("UPDATE $wpdb->postmeta SET meta_key = %s WHERE meta_key = %s",'_expiration-date','expiration-date'));
1495
 
1496
  // migrate defaults
1497
- $pagedefault = get_option('expirationdateExpiredPageStatus');
1498
- $postdefault = get_option('expirationdateExpiredPostStatus');
1499
- if ($pagedefault) update_option('expirationdateDefaultsPage',array('expireType' => $pagedefault));
1500
- if ($postdefault) update_option('expirationdateDefaultsPost',array('expireType' => $postdefault));
1501
-
1502
- delete_option('expirationdateCronSchedule');
1503
- delete_option('expirationdateAutoEnabled');
1504
- delete_option('expirationdateExpiredPageStatus');
1505
- delete_option('expirationdateExpiredPostStatus');
1506
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
 
 
 
 
1507
  }
1508
 
1509
- if (version_compare($version,'2.0.1') == -1) {
1510
  // Forgot to do this in 2.0.0
1511
- if (is_multisite()) {
1512
  global $current_blog;
1513
- wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
1514
- } else
1515
- wp_clear_scheduled_hook('expirationdate_delete');
1516
-
1517
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1518
- }
1519
 
1520
- if (version_compare($version,'2.1.0') == -1) {
1521
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1522
  }
1523
 
1524
- if (version_compare($version,'2.1.1') == -1) {
1525
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1526
- }
1527
 
1528
- if (version_compare($version,'2.2.0') == -1) {
1529
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1530
- }
1531
- if (version_compare($version,'2.2.1') == -1) {
1532
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1533
- }
1534
- if (version_compare($version,'2.3.0') == -1) {
1535
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1536
- }
1537
- if (version_compare($version,'2.3.1') == -1) {
1538
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1539
- }
1540
- if (version_compare($version,'2.3.1.1') == -1) {
1541
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1542
- }
1543
- if (version_compare($version,'2.4') == -1) {
1544
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1545
- }
1546
- if (version_compare($version,'2.4.1') == -1) {
1547
- update_option('postexpiratorVersion',POSTEXPIRATOR_VERSION);
1548
- }
1549
  }
1550
  }
1551
- add_action('admin_init','postexpirator_upgrade');
1552
 
1553
  /**
1554
  * Called at plugin activation
1555
  */
1556
- function postexpirator_activate () {
1557
- if (get_option('expirationdateDefaultDateFormat') === false) update_option('expirationdateDefaultDateFormat',POSTEXPIRATOR_DATEFORMAT);
1558
- if (get_option('expirationdateDefaultTimeFormat') === false) update_option('expirationdateDefaultTimeFormat',POSTEXPIRATOR_TIMEFORMAT);
1559
- if (get_option('expirationdateFooterContents') === false) update_option('expirationdateFooterContents',POSTEXPIRATOR_FOOTERCONTENTS);
1560
- if (get_option('expirationdateFooterStyle') === false) update_option('expirationdateFooterStyle',POSTEXPIRATOR_FOOTERSTYLE);
1561
- if (get_option('expirationdateDisplayFooter') === false) update_option('expirationdateDisplayFooter',POSTEXPIRATOR_FOOTERDISPLAY);
1562
- if (get_option('expirationdateDebug') === false) update_option('expirationdateDebug',POSTEXPIRATOR_DEBUGDEFAULT);
1563
- if (get_option('expirationdateDefaultDate') === false) update_option('expirationdateDefaultDate',POSTEXPIRATOR_EXPIREDEFAULT);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1564
  }
1565
 
1566
  /**
1567
  * Called at plugin deactivation
1568
  */
1569
- function expirationdate_deactivate () {
1570
  global $current_blog;
1571
- delete_option('expirationdateExpiredPostStatus');
1572
- delete_option('expirationdateExpiredPageStatus');
1573
- delete_option('expirationdateDefaultDateFormat');
1574
- delete_option('expirationdateDefaultTimeFormat');
1575
- delete_option('expirationdateDisplayFooter');
1576
- delete_option('expirationdateFooterContents');
1577
- delete_option('expirationdateFooterStyle');
1578
- delete_option('expirationdateCategory');
1579
- delete_option('expirationdateCategoryDefaults');
1580
- delete_option('expirationdateDebug');
1581
- delete_option('postexpiratorVersion');
1582
- delete_option('expirationdateCronSchedule');
1583
- delete_option('expirationdateDefaultDate');
1584
- delete_option('expirationdateDefaultDateCustom');
1585
- delete_option('expirationdateAutoEnabled');
1586
- delete_option('expirationdateDefaultsPage');
1587
- delete_option('expirationdateDefaultsPost');
1588
- ## what about custom post types? - how to cleanup?
1589
- if (is_multisite())
1590
- wp_clear_scheduled_hook('expirationdate_delete_'.$current_blog->blog_id);
1591
- else
1592
- wp_clear_scheduled_hook('expirationdate_delete');
1593
- require_once(plugin_dir_path(__FILE__).'post-expirator-debug.php');
1594
- $debug = new postExpiratorDebug();
 
1595
  $debug->removeDbTable();
1596
  }
1597
- register_deactivation_hook (__FILE__, 'expirationdate_deactivate');
1598
 
 
 
 
1599
  class Walker_PostExpirator_Category_Checklist extends Walker {
 
 
 
 
 
 
1600
  var $tree_type = 'category';
1601
- var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
1602
 
 
 
 
 
 
 
 
 
 
 
 
 
1603
  var $disabled = '';
1604
 
 
 
 
1605
  function setDisabled() {
1606
  $this->disabled = 'disabled="disabled"';
1607
  }
1608
 
1609
- function start_lvl(&$output, $depth = 0, $args = array()) {
1610
- $indent = str_repeat("\t", $depth);
 
 
 
 
 
 
 
 
 
 
1611
  $output .= "$indent<ul class='children'>\n";
1612
  }
1613
 
1614
- function end_lvl(&$output, $depth = 0, $args = array()) {
1615
- $indent = str_repeat("\t", $depth);
 
 
 
 
 
 
 
 
 
 
1616
  $output .= "$indent</ul>\n";
1617
  }
1618
 
1619
- function start_el(&$output, $category, $depth = 0, $args = array(), $current_object_id = 0) {
1620
- extract($args);
1621
- if ( empty($taxonomy) )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1622
  $taxonomy = 'category';
 
1623
 
1624
  $name = 'expirationdate_category';
1625
 
1626
- $class = in_array( $category->term_id, $popular_cats ) ? ' class="expirator-category"' : '';
1627
- $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, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' '.$this->disabled.'/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
1628
  }
1629
 
1630
- function end_el(&$output, $category, $depth = 0, $args = array()) {
 
 
 
 
 
 
 
 
 
 
1631
  $output .= "</li>\n";
1632
  }
1633
  }
1634
 
1635
- function _postExpiratorExpireType($opts) {
1636
- if (empty($opts)) return false;
 
 
 
 
 
1637
 
1638
- extract($opts);
1639
- if (!isset($name)) return false;
1640
- if (!isset($id)) $id = $name;
1641
- if (!isset($disabled)) $disabled = false;
1642
- if (!isset($onchange)) $onchange = '';
1643
- if (!isset($type)) $type = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
1644
 
1645
  $rv = array();
1646
- $rv[] = '<select name="'.$name.'" id="'.$id.'"'.($disabled == true ? ' disabled="disabled"' : '').' onchange="'.$onchange.'">';
1647
- $rv[] = '<option value="draft" '. ($selected == 'draft' ? 'selected="selected"' : '') . '>'.__('Draft','post-expirator').'</option>';
1648
- $rv[] = '<option value="delete" '. ($selected == 'delete' ? 'selected="selected"' : '') . '>'.__('Delete','post-expirator').'</option>';
1649
- $rv[] = '<option value="trash" '. ($selected == 'trash' ? 'selected="selected"' : '') . '>'.__('Trash','post-expirator').'</option>';
1650
- $rv[] = '<option value="private" '. ($selected == 'private' ? 'selected="selected"' : '') . '>'.__('Private','post-expirator').'</option>';
1651
- $rv[] = '<option value="stick" '. ($selected == 'stick' ? 'selected="selected"' : '') . '>'.__('Stick','post-expirator').'</option>';
1652
- $rv[] = '<option value="unstick" '. ($selected == 'unstick' ? 'selected="selected"' : '') . '>'.__('Unstick','post-expirator').'</option>';
1653
- if ($type != 'page') {
1654
- $rv[] = '<option value="category" '. ($selected == 'category' ? 'selected="selected"' : '') . '>'.__('Category: Replace','post-expirator').'</option>';
1655
- $rv[] = '<option value="category-add" '. ($selected == 'category-add' ? 'selected="selected"' : '') . '>'.__('Category: Add','post-expirator').'</option>';
1656
- $rv[] = '<option value="category-remove" '. ($selected == 'category-remove' ? 'selected="selected"' : '') . '>'.__('Category: Remove','post-expirator').'</option>';
 
1657
  }
1658
  $rv[] = '</select>';
1659
- return implode("<br/>\n",$rv);
1660
  }
1661
 
1662
- function _postExpiratorTaxonomy($opts) {
1663
- if (empty($opts)) return false;
 
 
 
 
 
1664
 
1665
- extract($opts);
1666
- if (!isset($name)) return false;
1667
- if (!isset($id)) $id = $name;
1668
- if (!isset($disabled)) $disabled = false;
1669
- if (!isset($onchange)) $onchange = '';
1670
- if (!isset($type)) $type = '';
 
 
 
 
 
 
 
 
 
 
 
 
1671
 
1672
- $taxonomies = get_object_taxonomies($type,'object');
1673
- $taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true));
1674
 
1675
- if (empty($taxonomies)) $disabled = true;
 
 
1676
 
1677
  $rv = array();
1678
- if ($taxonomies) {
1679
- $rv[] = '<select name="'.$name.'" id="'.$id.'"'.($disabled == true ? ' disabled="disabled"' : '').' onchange="'.$onchange.'">';
1680
- foreach ($taxonomies as $taxonomy) {
1681
- $rv[] = '<option value="'.$taxonomy->name.'" '. ($selected == $taxonomy->name ? 'selected="selected"' : '') . '>'.$taxonomy->name.'</option>';
 
1682
  }
1683
 
1684
  $rv[] = '</select>';
1685
- $rv[] = __('Select the hierarchical taxonomy to be used for "category" based expiration.','post-expirator');
1686
  } else {
1687
  $rv[] = 'No taxonomies found for post type.';
1688
  }
1689
- return implode("<br/>\n",$rv);
1690
  }
1691
 
1692
- add_action( 'admin_print_scripts-edit.php', 'expirationdate_quickedit_javascript' );
1693
- function expirationdate_quickedit_javascript() {
 
 
1694
  // if using code as plugin
1695
  wp_enqueue_script( 'manage-wp-posts-using-bulk-quick-edit', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'admin-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
1696
-
 
 
 
 
 
 
 
1697
  }
 
1698
 
1699
  /**
1700
- * Receieve AJAX call from bulk edit to process save
1701
- */
1702
- add_action( 'wp_ajax_manage_wp_posts_using_bulk_quick_save_bulk_edit', 'expiration_date_save_bulk_edit' );
1703
- function expiration_date_save_bulk_edit() {
 
1704
  // we need the post IDs
1705
- $post_ids = ( isset( $_POST[ 'post_ids' ] ) && !empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : NULL;
1706
 
1707
  // if we have post IDs
1708
  if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
1709
 
1710
  // if no change, do nothing
1711
- if ($_POST['expirationdate_month'] == "false") return;
 
 
1712
 
1713
- $month = intval($_POST['expirationdate_month']);
1714
- $day = intval($_POST['expirationdate_day']);
1715
- $year = intval($_POST['expirationdate_year']);
1716
- $hour = intval($_POST['expirationdate_hour']);
1717
- $minute = intval($_POST['expirationdate_minute']);
1718
- $ts = get_gmt_from_date("$year-$month-$day $hour:$minute:0",'U');
 
 
 
 
1719
 
1720
- foreach( $post_ids as $post_id ) {
1721
  // Only update posts that already have expiration date set. Ignore Others
1722
- $ed = get_post_meta($post_id,'_expiration-date',true);
1723
- if ($ed) {
1724
- $opts = get_post_meta($post_id, '_expiration-date-options', true);
1725
- #_scheduleExpiratorEvent($post_id,$ts,$opts);
1726
  }
1727
  }
1728
  }
1729
  }
 
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">
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>
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>
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>
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>
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">
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
 
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
 
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
  }
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
  }
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
 
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
  }
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
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' );
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === Post Expirator: Automatically Unpublish WordPress Posts ===
2
- Contributors: publishpress, kevinB, stevejburge, andergmartins, axelseaa
3
  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.1
8
- Stable tag: 2.4.1
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
 
@@ -27,16 +27,16 @@ There are a number of different ways that the posts can expire:
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 webhost. 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
 
@@ -50,11 +50,17 @@ This section describes how to install the plugin and get it working.
50
  == Screenshots ==
51
 
52
  1. Adding expiration date to a post
53
- 2. Viewing the exipiration dates on the post overview screen
54
  3. Settings screen
55
 
56
  == Changelog ==
57
 
 
 
 
 
 
 
58
  **Version 2.4.1**
59
 
60
  * Fix: Updated deprecated .live jQuery reference.
@@ -102,7 +108,7 @@ This section describes how to install the plugin and get it working.
102
 
103
  **Version 2.1.2**
104
 
105
- * Security: Added form nonce for protect agaisnt possible CSRF
106
  * Security: Fixed XSS issue on settings pages
107
  * New: Added check to show if WP_CRON is enabled on diagnostics page
108
  * Fix: Minor Code Cleanup
@@ -114,9 +120,9 @@ This section describes how to install the plugin and get it working.
114
 
115
  **Version 2.1.0**
116
 
117
- * New: Added support for heirarchical custom taxonomy
118
  * New: Enhanced custom post type support
119
- * Fix: Updated debug function to be friendly for scripted calls
120
  * Fix: Change to only show public custom post types on defaults screen
121
  * Fix: Removed category expiration options for 'pages', which is currently unsupported
122
  * Fix: Some date calls were getting "double" converted for the timezone pending how other plugins handled date - this issue should now be resolved
1
  === Post Expirator: Automatically Unpublish WordPress Posts ===
2
+ Contributors: publishpress, kevinB, stevejburge, andergmartins, axelseaa, rozroz
3
  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
 
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
 
50
  == Screenshots ==
51
 
52
  1. Adding expiration date to a post
53
+ 2. Viewing the expiration dates on the post overview screen
54
  3. Settings screen
55
 
56
  == Changelog ==
57
 
58
+ **Version 2.4.2**
59
+
60
+ * Fixed: Bulk edit does not change scheduled event bug, #29;
61
+ * Fixed: Date not being translated in shortcode, #16;
62
+ * Fixed: Bulk Edit doesn't work, #4;
63
+
64
  **Version 2.4.1**
65
 
66
  * Fix: Updated deprecated .live jQuery reference.
108
 
109
  **Version 2.1.2**
110
 
111
+ * Security: Added form nonce for protect against possible CSRF
112
  * Security: Fixed XSS issue on settings pages
113
  * New: Added check to show if WP_CRON is enabled on diagnostics page
114
  * Fix: Minor Code Cleanup
120
 
121
  **Version 2.1.0**
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