Version Description
Download this release
Release Info
Developer | publishpress |
Plugin | Post Expirator |
Version | 2.6.0 |
Comparing to | |
See all releases |
Code changes from version 2.5.1 to 2.6.0
- assets/css/edit.css +6 -6
- assets/css/settings.css +17 -11
- assets/css/style.css +22 -19
- assets/js/admin-edit.js +108 -108
- assets/js/settings.js +5 -5
- assets/jsx/block.jsx +120 -106
- classes/Display.class.php +40 -10
- classes/Facade.class.php +132 -51
- composer.json +2 -2
- functions.php +0 -1
- legacy-functions.php +1 -0
- post-expirator-debug.php +2 -1
- post-expirator.php +295 -196
- readme.txt +5 -1
- vendor/composer/InstalledVersions.php +2 -2
- vendor/composer/installed.php +2 -2
- views/bulk-edit.php +53 -35
- views/classic-metabox.php +111 -100
- views/expire-column.php +36 -31
- views/how-to-expire.php +15 -15
- views/menu-defaults.php +160 -123
- views/menu-diagnostics.php +53 -50
- views/menu-general.php +233 -157
- views/quick-edit.php +43 -30
- views/tabs.php +13 -9
assets/css/edit.css
CHANGED
@@ -1,24 +1,24 @@
|
|
1 |
div.pe-qe-fields {
|
2 |
-
|
3 |
}
|
4 |
|
5 |
div.pe-qe-fields label {
|
6 |
-
|
7 |
}
|
8 |
|
9 |
div.pe-qe-fields .post-expirator-date-fields,
|
10 |
div.pe-qe-fields > .pe-category-list {
|
11 |
-
|
12 |
}
|
13 |
|
14 |
div.pe-qe-fields > div {
|
15 |
-
|
16 |
}
|
17 |
|
18 |
#bulk-edit div.pe-qe-fields > .pe-category-list {
|
19 |
-
|
20 |
}
|
21 |
|
22 |
.post-expirator-quickedit input {
|
23 |
-
|
24 |
}
|
1 |
div.pe-qe-fields {
|
2 |
+
padding: .2em .5em;
|
3 |
}
|
4 |
|
5 |
div.pe-qe-fields label {
|
6 |
+
vertical-align: middle !important;
|
7 |
}
|
8 |
|
9 |
div.pe-qe-fields .post-expirator-date-fields,
|
10 |
div.pe-qe-fields > .pe-category-list {
|
11 |
+
display: none;
|
12 |
}
|
13 |
|
14 |
div.pe-qe-fields > div {
|
15 |
+
margin: 5px 0px;
|
16 |
}
|
17 |
|
18 |
#bulk-edit div.pe-qe-fields > .pe-category-list {
|
19 |
+
max-width: 25%;
|
20 |
}
|
21 |
|
22 |
.post-expirator-quickedit input {
|
23 |
+
font-size: 12px;
|
24 |
}
|
assets/css/settings.css
CHANGED
@@ -1,27 +1,33 @@
|
|
1 |
ul.pe-list {
|
2 |
-
|
3 |
}
|
4 |
|
5 |
ul.pe-list > li {
|
6 |
-
|
7 |
}
|
8 |
|
9 |
.pe-scroll {
|
10 |
-
|
11 |
-
|
12 |
}
|
13 |
|
14 |
.pe-scroll > table td {
|
15 |
-
|
16 |
}
|
17 |
|
18 |
tr.pe-event {
|
19 |
-
|
20 |
}
|
21 |
|
22 |
#pe-settings-tabs fieldset {
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
1 |
ul.pe-list {
|
2 |
+
list-style: disc !important;
|
3 |
}
|
4 |
|
5 |
ul.pe-list > li {
|
6 |
+
margin-left: 3%;
|
7 |
}
|
8 |
|
9 |
.pe-scroll {
|
10 |
+
height: 300px;
|
11 |
+
overflow-y: scroll;
|
12 |
}
|
13 |
|
14 |
.pe-scroll > table td {
|
15 |
+
padding: 5px;
|
16 |
}
|
17 |
|
18 |
tr.pe-event {
|
19 |
+
background-color: #ddd !important;
|
20 |
}
|
21 |
|
22 |
#pe-settings-tabs fieldset {
|
23 |
+
border: 1px solid black;
|
24 |
+
border-radius: 6px;
|
25 |
+
padding: 0px 12px;
|
26 |
+
margin-bottom: 20px;
|
27 |
+
}
|
28 |
+
|
29 |
+
.pe-checklist label {
|
30 |
+
display: block;
|
31 |
+
width: 300px;
|
32 |
+
margin-bottom: 2px;
|
33 |
+
}
|
assets/css/style.css
CHANGED
@@ -1,41 +1,44 @@
|
|
1 |
/* settings */
|
2 |
.post-expirator-adminnotice {
|
3 |
-
|
4 |
}
|
5 |
|
6 |
.post-expirator-addcolumn {
|
7 |
-
|
8 |
-
|
9 |
}
|
10 |
|
11 |
.post-expirator-debug th {
|
12 |
-
|
13 |
-
|
14 |
}
|
15 |
|
16 |
.post-expirator-timestamp {
|
17 |
-
|
18 |
}
|
19 |
|
20 |
/* metabox */
|
21 |
#post-expirator-cat-list {
|
22 |
-
|
23 |
}
|
|
|
24 |
#post-expirator-cat-list ul {
|
25 |
-
|
26 |
}
|
|
|
27 |
#post-expirator-cat-list ul ul {
|
28 |
-
|
29 |
}
|
|
|
30 |
.post-expirator-taxonomy-name {
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
}
|
35 |
|
36 |
div.pe-classic-fields {
|
37 |
-
|
38 |
-
|
39 |
flex-wrap: wrap;
|
40 |
align-content: center;
|
41 |
justify-content: space-between;
|
@@ -43,11 +46,11 @@ div.pe-classic-fields {
|
|
43 |
}
|
44 |
|
45 |
div.pe-classic-fields > div {
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
}
|
50 |
|
51 |
div.pe-classic-fields > div > label {
|
52 |
-
|
53 |
-
}
|
1 |
/* settings */
|
2 |
.post-expirator-adminnotice {
|
3 |
+
background-color: red;
|
4 |
}
|
5 |
|
6 |
.post-expirator-addcolumn {
|
7 |
+
font-size: 0.8em;
|
8 |
+
font-weight: normal;
|
9 |
}
|
10 |
|
11 |
.post-expirator-debug th {
|
12 |
+
font-weight: bold;
|
13 |
+
border-bottom: 1px solid black;
|
14 |
}
|
15 |
|
16 |
.post-expirator-timestamp {
|
17 |
+
width: 150px;
|
18 |
}
|
19 |
|
20 |
/* metabox */
|
21 |
#post-expirator-cat-list {
|
22 |
+
max-width: 250px;
|
23 |
}
|
24 |
+
|
25 |
#post-expirator-cat-list ul {
|
26 |
+
margin: 0;
|
27 |
}
|
28 |
+
|
29 |
#post-expirator-cat-list ul ul {
|
30 |
+
margin-left: 18px;
|
31 |
}
|
32 |
+
|
33 |
.post-expirator-taxonomy-name {
|
34 |
+
margin: 0px;
|
35 |
+
font-style: italic;
|
36 |
+
font-size: x-small;
|
37 |
}
|
38 |
|
39 |
div.pe-classic-fields {
|
40 |
+
display: flex;
|
41 |
+
flex-direction: row;
|
42 |
flex-wrap: wrap;
|
43 |
align-content: center;
|
44 |
justify-content: space-between;
|
46 |
}
|
47 |
|
48 |
div.pe-classic-fields > div {
|
49 |
+
display: flex;
|
50 |
+
flex-direction: column;
|
51 |
+
padding: 5px;
|
52 |
}
|
53 |
|
54 |
div.pe-classic-fields > div > label {
|
55 |
+
font-weight: bold;
|
56 |
+
}
|
assets/js/admin-edit.js
CHANGED
@@ -1,44 +1,44 @@
|
|
1 |
-
(function($, config) {
|
2 |
|
3 |
// show/hide the date fields when the user chooses the intent in bulk edit
|
4 |
-
$('body').on('change', 'select[name="expirationdate_status"]', function(e){
|
5 |
var $show = $(this).find('option:selected').attr('data-show-fields');
|
6 |
-
if($show === 'true'){
|
7 |
$(this).parents('.pe-qe-fields').find('.post-expirator-date-fields').show();
|
8 |
-
}else{
|
9 |
$(this).parents('.pe-qe-fields').find('.post-expirator-date-fields').hide();
|
10 |
}
|
11 |
});
|
12 |
|
13 |
// show/hide the date fields when the user chooses the intent in quick edit
|
14 |
-
$('body').on('click', 'input[name="enable-expirationdate"]', function(e){
|
15 |
-
if($(this).is(':checked')){
|
16 |
$(this).parents('.post-expirator-quickedit').find('.pe-qe-fields').show();
|
17 |
-
}else{
|
18 |
$(this).parents('.post-expirator-quickedit').find('.pe-qe-fields').hide();
|
19 |
}
|
20 |
});
|
21 |
|
22 |
// hide/show the categories selection checkbox list in bulk/quick edit
|
23 |
-
$('body').on('change', 'select[name="expirationdate_expiretype"]', function(e){
|
24 |
var $show = $(this).val().indexOf('category') !== -1;
|
25 |
-
if($show){
|
26 |
$(this).parents('.pe-qe-fields').find('.pe-category-list').show();
|
27 |
-
}else{
|
28 |
$(this).parents('.pe-qe-fields').find('.pe-category-list').hide();
|
29 |
}
|
30 |
});
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
|
43 |
// hide the fields for bulk edit till action is taken by the user
|
44 |
$bulk_row.find('.pe-qe-fields select[name="expirationdate_status"]').prop('selectedIndex', 0);
|
@@ -46,122 +46,122 @@
|
|
46 |
$bulk_row.find('.pe-qe-fields .pe-category-list').hide();
|
47 |
};
|
48 |
|
49 |
-
|
50 |
-
|
51 |
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
59 |
-
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
|
91 |
// expire type
|
92 |
-
|
93 |
-
|
94 |
|
95 |
// enabled or not
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
|
102 |
// categories
|
103 |
-
|
104 |
-
|
105 |
-
$.each($categories.split(','), function(index, value){
|
106 |
-
$edit_row.find(
|
107 |
});
|
108 |
-
|
109 |
|
110 |
// show or hide categories
|
111 |
-
if($type.indexOf('category') !== -1){
|
112 |
$edit_row.find('.pe-category-list').show();
|
113 |
-
}else{
|
114 |
$edit_row.find('.pe-category-list').hide();
|
115 |
}
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
$bulk_row.find(
|
141 |
expirationdate_category.push($(this).val());
|
142 |
});
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
nonce: config.ajax.nonce
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
|
167 |
})(jQuery, config);
|
1 |
+
(function ($, config) {
|
2 |
|
3 |
// show/hide the date fields when the user chooses the intent in bulk edit
|
4 |
+
$('body').on('change', 'select[name="expirationdate_status"]', function (e) {
|
5 |
var $show = $(this).find('option:selected').attr('data-show-fields');
|
6 |
+
if ($show === 'true') {
|
7 |
$(this).parents('.pe-qe-fields').find('.post-expirator-date-fields').show();
|
8 |
+
} else {
|
9 |
$(this).parents('.pe-qe-fields').find('.post-expirator-date-fields').hide();
|
10 |
}
|
11 |
});
|
12 |
|
13 |
// show/hide the date fields when the user chooses the intent in quick edit
|
14 |
+
$('body').on('click', 'input[name="enable-expirationdate"]', function (e) {
|
15 |
+
if ($(this).is(':checked')) {
|
16 |
$(this).parents('.post-expirator-quickedit').find('.pe-qe-fields').show();
|
17 |
+
} else {
|
18 |
$(this).parents('.post-expirator-quickedit').find('.pe-qe-fields').hide();
|
19 |
}
|
20 |
});
|
21 |
|
22 |
// hide/show the categories selection checkbox list in bulk/quick edit
|
23 |
+
$('body').on('change', 'select[name="expirationdate_expiretype"]', function (e) {
|
24 |
var $show = $(this).val().indexOf('category') !== -1;
|
25 |
+
if ($show) {
|
26 |
$(this).parents('.pe-qe-fields').find('.pe-category-list').show();
|
27 |
+
} else {
|
28 |
$(this).parents('.pe-qe-fields').find('.pe-category-list').hide();
|
29 |
}
|
30 |
});
|
31 |
|
32 |
+
// we create a copy of the WP bulk edit post function
|
33 |
+
var $wp_bulk_edit = inlineEditPost.setBulk;
|
34 |
|
35 |
+
// and then we overwrite the function with our own code
|
36 |
+
inlineEditPost.setBulk = function (id) {
|
37 |
+
// "call" the original WP edit function
|
38 |
+
// we don't want to leave WordPress hanging
|
39 |
+
$wp_bulk_edit.apply(this, arguments);
|
40 |
|
41 |
+
var $bulk_row = $('#bulk-edit');
|
42 |
|
43 |
// hide the fields for bulk edit till action is taken by the user
|
44 |
$bulk_row.find('.pe-qe-fields select[name="expirationdate_status"]').prop('selectedIndex', 0);
|
46 |
$bulk_row.find('.pe-qe-fields .pe-category-list').hide();
|
47 |
};
|
48 |
|
49 |
+
// we create a copy of the WP inline edit post function
|
50 |
+
var $wp_inline_edit = inlineEditPost.edit;
|
51 |
|
52 |
+
// and then we overwrite the function with our own code
|
53 |
+
inlineEditPost.edit = function (id) {
|
54 |
|
55 |
+
// "call" the original WP edit function
|
56 |
+
// we don't want to leave WordPress hanging
|
57 |
+
$wp_inline_edit.apply(this, arguments);
|
58 |
|
59 |
+
// now we take care of our business
|
60 |
|
61 |
+
// get the post ID
|
62 |
+
var $post_id = 0;
|
63 |
+
if (typeof (id) == 'object') {
|
64 |
+
$post_id = parseInt(this.getId(id));
|
65 |
+
}
|
66 |
|
67 |
+
if ($post_id > 0) {
|
68 |
+
// define the edit row
|
69 |
+
var $edit_row = $('#edit-' + $post_id);
|
70 |
|
71 |
+
// get / set year
|
72 |
+
var $year = $('#expirationdate_year-' + $post_id).text();
|
73 |
+
$edit_row.find('input[name="expirationdate_year"]').val($year);
|
74 |
|
75 |
+
// get / set month
|
76 |
+
var $month = $('#expirationdate_month-' + $post_id).text();
|
77 |
+
$edit_row.find('select[name="expirationdate_month"]').val($month);
|
78 |
|
79 |
+
// get / set day
|
80 |
+
var $day = $('#expirationdate_day-' + $post_id).text();
|
81 |
+
$edit_row.find('input[name="expirationdate_day"]').val($day);
|
82 |
|
83 |
+
// get / set hour
|
84 |
+
var $hour = $('#expirationdate_hour-' + $post_id).text();
|
85 |
+
$edit_row.find('input[name="expirationdate_hour"]').val($hour);
|
86 |
|
87 |
+
// get / set minute
|
88 |
+
var $minute = $('#expirationdate_minute-' + $post_id).text();
|
89 |
+
$edit_row.find('input[name="expirationdate_minute"]').val($minute);
|
90 |
|
91 |
// expire type
|
92 |
+
var $type = $('#expirationdate_expireType-' + $post_id).text();
|
93 |
+
$edit_row.find('select[name="expirationdate_expiretype"]').val($type);
|
94 |
|
95 |
// enabled or not
|
96 |
+
var $enabled = $('#expirationdate_enabled-' + $post_id).text();
|
97 |
+
if ($enabled == "true") {
|
98 |
+
$edit_row.find('input[name="enable-expirationdate"]').prop('checked', true);
|
99 |
+
$edit_row.find('.pe-qe-fields').show();
|
100 |
+
}
|
101 |
|
102 |
// categories
|
103 |
+
var $categories = $('#expirationdate_categories-' + $post_id).text();
|
104 |
+
if ($categories !== '') {
|
105 |
+
$.each($categories.split(','), function (index, value) {
|
106 |
+
$edit_row.find('input[name="expirationdate_category[]"][value="' + value + '"]').prop('checked', true);
|
107 |
});
|
108 |
+
}
|
109 |
|
110 |
// show or hide categories
|
111 |
+
if ($type.indexOf('category') !== -1) {
|
112 |
$edit_row.find('.pe-category-list').show();
|
113 |
+
} else {
|
114 |
$edit_row.find('.pe-category-list').hide();
|
115 |
}
|
116 |
|
117 |
+
}
|
118 |
+
};
|
119 |
+
|
120 |
+
$('#bulk_edit').on('click', function () {
|
121 |
+
|
122 |
+
// define the bulk edit row
|
123 |
+
var $bulk_row = $('#bulk-edit');
|
124 |
+
|
125 |
+
// get the selected post ids that are being edited
|
126 |
+
var $post_ids = [];
|
127 |
+
$bulk_row.find('#bulk-titles').children().each(function () {
|
128 |
+
$post_ids.push($(this).attr('id').replace(/^(ttle)/i, ''));
|
129 |
+
});
|
130 |
+
|
131 |
+
// get the custom fields
|
132 |
+
var $expirationdate_month = $bulk_row.find('select[name="expirationdate_month"]').val();
|
133 |
+
var $expirationdate_day = $bulk_row.find('input[name="expirationdate_day"]').val();
|
134 |
+
var $expirationdate_year = $bulk_row.find('input[name="expirationdate_year"]').val();
|
135 |
+
var $expirationdate_hour = $bulk_row.find('input[name="expirationdate_hour"]').val();
|
136 |
+
var $expirationdate_minute = $bulk_row.find('input[name="expirationdate_minute"]').val();
|
137 |
+
var $expirationdate_status = $bulk_row.find('select[name="expirationdate_status"]').val();
|
138 |
+
var $expirationdate_expireType = $bulk_row.find('select[name="expirationdate_expiretype"]').val();
|
139 |
+
var expirationdate_category = [];
|
140 |
+
$bulk_row.find('input[name="expirationdate_category[]"]:checked').each(function () {
|
141 |
expirationdate_category.push($(this).val());
|
142 |
});
|
143 |
|
144 |
+
// save the data
|
145 |
+
$.ajax({
|
146 |
+
url: ajaxurl, // this is a variable that WordPress has already defined for us
|
147 |
+
type: 'POST',
|
148 |
+
async: false,
|
149 |
+
cache: false,
|
150 |
+
data: {
|
151 |
+
action: config.ajax.bulk_edit,
|
152 |
+
post_ids: $post_ids, // and these are the 2 parameters we're passing to our function
|
153 |
+
expirationdate_month: $expirationdate_month,
|
154 |
+
expirationdate_day: $expirationdate_day,
|
155 |
+
expirationdate_year: $expirationdate_year,
|
156 |
+
expirationdate_hour: $expirationdate_hour,
|
157 |
+
expirationdate_minute: $expirationdate_minute,
|
158 |
+
expirationdate_status: $expirationdate_status,
|
159 |
+
expirationdate_expiretype: $expirationdate_expireType,
|
160 |
+
expirationdate_category: expirationdate_category,
|
161 |
nonce: config.ajax.nonce
|
162 |
+
}
|
163 |
+
});
|
164 |
+
|
165 |
+
});
|
166 |
|
167 |
})(jQuery, config);
|
assets/js/settings.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
-
(function($) {
|
2 |
-
$(document).ready(function(){
|
3 |
init();
|
4 |
});
|
5 |
|
6 |
function init() {
|
7 |
-
$('.pe-custom-date-toggle').on('change', function(e){
|
8 |
-
if($(this).val() === 'custom') {
|
9 |
$(this).siblings('.pe-custom-date-container').show();
|
10 |
-
}else{
|
11 |
$(this).siblings('.pe-custom-date-container').hide();
|
12 |
}
|
13 |
});
|
1 |
+
(function ($) {
|
2 |
+
$(document).ready(function () {
|
3 |
init();
|
4 |
});
|
5 |
|
6 |
function init() {
|
7 |
+
$('.pe-custom-date-toggle').on('change', function (e) {
|
8 |
+
if ($(this).val() === 'custom') {
|
9 |
$(this).siblings('.pe-custom-date-container').show();
|
10 |
+
} else {
|
11 |
$(this).siblings('.pe-custom-date-container').hide();
|
12 |
}
|
13 |
});
|
assets/jsx/block.jsx
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
-
(function (
|
2 |
|
3 |
-
const {
|
4 |
-
const {
|
5 |
-
const {
|
6 |
-
const {
|
7 |
-
const {
|
8 |
-
const {
|
9 |
-
const {
|
10 |
|
11 |
class PostExpiratorSidebar extends Component {
|
12 |
constructor() {
|
13 |
-
super(
|
14 |
|
15 |
this.state = {
|
16 |
categoriesList: [],
|
@@ -19,9 +19,9 @@
|
|
19 |
}
|
20 |
|
21 |
componentWillMount() {
|
22 |
-
const {
|
23 |
|
24 |
-
const postMeta = wp.data.select(
|
25 |
const postType = wp.data.select('core/editor').getCurrentPostType();
|
26 |
|
27 |
let enabled = config.defaults.autoEnable == 1;
|
@@ -30,59 +30,63 @@
|
|
30 |
let expireAction = this.getExpireType(postMeta);
|
31 |
|
32 |
let categories = [];
|
33 |
-
if(expireAction.includes('category')){
|
34 |
categories = this.getCategories(postMeta);
|
35 |
}
|
36 |
|
37 |
-
if(postMeta['_expiration-date-status'] && postMeta['_expiration-date-status'] === 'saved'){
|
38 |
enabled = true;
|
39 |
}
|
40 |
|
41 |
-
if(postMeta['_expiration-date']){
|
42 |
date.setTime((postMeta['_expiration-date'] + date.getTimezoneOffset() * 60) * 1000);
|
43 |
-
}else{
|
44 |
categories = config.default_categories;
|
45 |
-
if(config.default_date){
|
46 |
date.setTime((parseInt(config.default_date) + date.getTimezoneOffset() * 60) * 1000);
|
47 |
}
|
48 |
}
|
49 |
|
50 |
let taxonomy = config.defaults.taxonomy || 'category';
|
51 |
|
52 |
-
this.setState(
|
53 |
enabled: enabled,
|
54 |
date: date,
|
55 |
expireAction: expireAction,
|
56 |
categories: categories,
|
57 |
taxonomy: taxonomy,
|
58 |
-
}
|
59 |
|
60 |
let categoriesList = [];
|
61 |
let catIdVsName = [];
|
62 |
|
63 |
-
if
|
64 |
-
wp.apiFetch(
|
65 |
-
path: wp.url.addQueryArgs(
|
66 |
-
}
|
67 |
list.forEach(cat => {
|
68 |
-
categoriesList[
|
69 |
-
catIdVsName[
|
70 |
});
|
71 |
-
this.setState(
|
72 |
-
}
|
73 |
-
}else if(postType !== 'page') {
|
74 |
-
wp.apiFetch(
|
75 |
-
path: wp.url.addQueryArgs(
|
76 |
-
}
|
77 |
// fetch all terms
|
78 |
-
wp.apiFetch(
|
79 |
-
path: wp.url.addQueryArgs(
|
80 |
-
}
|
81 |
terms.forEach(term => {
|
82 |
-
categoriesList[
|
83 |
-
catIdVsName[
|
|
|
|
|
|
|
|
|
|
|
84 |
});
|
85 |
-
this.setState( { categoriesList: categoriesList, catIdVsName: catIdVsName, taxonomy: decodeEntities(taxAttributes.name) } );
|
86 |
});
|
87 |
});
|
88 |
}
|
@@ -90,110 +94,120 @@
|
|
90 |
}
|
91 |
|
92 |
componentDidUpdate() {
|
93 |
-
const {
|
94 |
-
const setPostMeta = (newMeta) => wp.data.dispatch(
|
95 |
-
const postMeta = wp.data.select(
|
96 |
|
97 |
-
switch(attribute){
|
98 |
case 'enabled':
|
99 |
-
setPostMeta(
|
100 |
// if date is not set when the checkbox is enabled, set it to the default date
|
101 |
// this is to prevent the user from having to click the date to set it
|
102 |
-
if(!postMeta['_expiration-date']){
|
103 |
-
setPostMeta(
|
104 |
}
|
105 |
break;
|
106 |
case 'date':
|
107 |
-
if(typeof date === 'string'){
|
108 |
-
setPostMeta(
|
109 |
}
|
110 |
break;
|
111 |
case 'action':
|
112 |
-
setPostMeta(
|
113 |
-
if(!expireAction.includes('category')){
|
114 |
-
setPostMeta(
|
115 |
}
|
116 |
break;
|
117 |
case 'category':
|
118 |
-
setPostMeta(
|
119 |
break;
|
120 |
}
|
121 |
|
122 |
}
|
123 |
|
124 |
render() {
|
125 |
-
const {
|
126 |
-
const {
|
127 |
|
128 |
const postType = wp.data.select('core/editor').getCurrentPostType();
|
129 |
|
130 |
let actionsList = [
|
131 |
-
{
|
132 |
-
{
|
133 |
-
{
|
134 |
-
{
|
135 |
-
{
|
136 |
-
{
|
137 |
];
|
138 |
|
139 |
-
if(postType !== 'page'){
|
140 |
actionsList = _.union(actionsList, [
|
141 |
-
{
|
142 |
-
{
|
143 |
-
{
|
144 |
]);
|
145 |
}
|
146 |
|
147 |
-
let selectedCats = categories && compact(categories.map((id) => catIdVsName[id] || false
|
148 |
-
if(typeof selectedCats === 'string'){
|
149 |
selectedCats = [];
|
150 |
}
|
151 |
-
|
152 |
return (
|
153 |
-
<PluginDocumentSettingPanel title={
|
|
|
154 |
<PanelRow>
|
155 |
<CheckboxControl
|
156 |
-
label={
|
157 |
-
checked={
|
158 |
-
onChange={
|
|
|
|
|
159 |
/>
|
160 |
</PanelRow>
|
161 |
-
{
|
162 |
<Fragment>
|
163 |
<PanelRow>
|
164 |
<DateTimePicker
|
165 |
-
currentDate={
|
166 |
-
onChange={
|
167 |
-
is12Hour={
|
168 |
/>
|
169 |
</PanelRow>
|
170 |
<SelectControl
|
171 |
-
label={
|
172 |
-
value={
|
173 |
-
options={
|
174 |
-
onChange={
|
|
|
|
|
175 |
/>
|
176 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
(
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
/>
|
193 |
-
)
|
194 |
-
) }
|
195 |
</Fragment>
|
196 |
-
)
|
197 |
</PluginDocumentSettingPanel>
|
198 |
);
|
199 |
}
|
@@ -203,11 +217,11 @@
|
|
203 |
let typeNew = postMeta['_expiration-date-type'];
|
204 |
let typeOld = postMeta['_expiration-date-options'] && postMeta['_expiration-date-options']['expireType'];
|
205 |
|
206 |
-
if(typeNew){
|
207 |
return typeNew;
|
208 |
}
|
209 |
|
210 |
-
if(typeOld){
|
211 |
return typeOld;
|
212 |
}
|
213 |
|
@@ -219,12 +233,12 @@
|
|
219 |
let categoriesNew = postMeta['_expiration-date-categories'] && postMeta['_expiration-date-categories'];
|
220 |
let categoriesOld = postMeta['_expiration-date-options'] && postMeta['_expiration-date-options']['category'];
|
221 |
|
222 |
-
if(typeof categoriesNew === 'object' && categoriesNew.length > 0){
|
223 |
return categoriesNew;
|
224 |
}
|
225 |
|
226 |
-
if(categoriesOld && typeof categoriesOld !== 'undefined' && typeof categoriesOld !== 'object'){
|
227 |
-
categories = [
|
228 |
}
|
229 |
|
230 |
return categoriesOld;
|
@@ -233,7 +247,7 @@
|
|
233 |
|
234 |
// fired for the autocomplete
|
235 |
selectCategories(tokens) {
|
236 |
-
const {
|
237 |
|
238 |
var hasNoSuggestion = tokens.some(function (token) {
|
239 |
return typeof token === 'string' && !categoriesList[token];
|
@@ -247,10 +261,10 @@
|
|
247 |
return typeof token === 'string' ? categoriesList[token] : token;
|
248 |
})
|
249 |
|
250 |
-
return categories.map(
|
251 |
}
|
252 |
|
253 |
-
getDate(date){
|
254 |
let newDate = new Date();
|
255 |
newDate.setTime(Date.parse(date));
|
256 |
newDate.setTime(newDate.getTime() - new Date().getTimezoneOffset() * 60 * 1000);
|
@@ -259,9 +273,9 @@
|
|
259 |
|
260 |
}
|
261 |
|
262 |
-
registerPlugin(
|
263 |
render: PostExpiratorSidebar
|
264 |
-
}
|
265 |
|
266 |
|
267 |
-
})(
|
1 |
+
(function (wp, config) {
|
2 |
|
3 |
+
const {registerPlugin} = wp.plugins;
|
4 |
+
const {__} = wp.i18n;
|
5 |
+
const {PluginDocumentSettingPanel} = wp.editPost;
|
6 |
+
const {PanelRow, DateTimePicker, CheckboxControl, SelectControl, FormTokenField, Spinner} = wp.components;
|
7 |
+
const {Fragment, Component} = wp.element;
|
8 |
+
const {decodeEntities} = wp.htmlEntities;
|
9 |
+
const {isEmpty, keys, compact} = lodash;
|
10 |
|
11 |
class PostExpiratorSidebar extends Component {
|
12 |
constructor() {
|
13 |
+
super(...arguments);
|
14 |
|
15 |
this.state = {
|
16 |
categoriesList: [],
|
19 |
}
|
20 |
|
21 |
componentWillMount() {
|
22 |
+
const {attributes} = this.state;
|
23 |
|
24 |
+
const postMeta = wp.data.select('core/editor').getEditedPostAttribute('meta');
|
25 |
const postType = wp.data.select('core/editor').getCurrentPostType();
|
26 |
|
27 |
let enabled = config.defaults.autoEnable == 1;
|
30 |
let expireAction = this.getExpireType(postMeta);
|
31 |
|
32 |
let categories = [];
|
33 |
+
if (expireAction.includes('category')) {
|
34 |
categories = this.getCategories(postMeta);
|
35 |
}
|
36 |
|
37 |
+
if (postMeta['_expiration-date-status'] && postMeta['_expiration-date-status'] === 'saved') {
|
38 |
enabled = true;
|
39 |
}
|
40 |
|
41 |
+
if (postMeta['_expiration-date']) {
|
42 |
date.setTime((postMeta['_expiration-date'] + date.getTimezoneOffset() * 60) * 1000);
|
43 |
+
} else {
|
44 |
categories = config.default_categories;
|
45 |
+
if (config.default_date) {
|
46 |
date.setTime((parseInt(config.default_date) + date.getTimezoneOffset() * 60) * 1000);
|
47 |
}
|
48 |
}
|
49 |
|
50 |
let taxonomy = config.defaults.taxonomy || 'category';
|
51 |
|
52 |
+
this.setState({
|
53 |
enabled: enabled,
|
54 |
date: date,
|
55 |
expireAction: expireAction,
|
56 |
categories: categories,
|
57 |
taxonomy: taxonomy,
|
58 |
+
});
|
59 |
|
60 |
let categoriesList = [];
|
61 |
let catIdVsName = [];
|
62 |
|
63 |
+
if ((!taxonomy && postType === 'post') || taxonomy === 'category') {
|
64 |
+
wp.apiFetch({
|
65 |
+
path: wp.url.addQueryArgs('wp/v2/categories', {per_page: -1, hide_empty: false}),
|
66 |
+
}).then((list) => {
|
67 |
list.forEach(cat => {
|
68 |
+
categoriesList[cat.name] = cat;
|
69 |
+
catIdVsName[cat.id] = cat.name;
|
70 |
});
|
71 |
+
this.setState({categoriesList: categoriesList, catIdVsName: catIdVsName, taxonomy: __('Category')});
|
72 |
+
});
|
73 |
+
} else if (postType !== 'page') {
|
74 |
+
wp.apiFetch({
|
75 |
+
path: wp.url.addQueryArgs(`wp/v2/taxonomies/${taxonomy}`, {context: 'edit'}),
|
76 |
+
}).then((taxAttributes) => {
|
77 |
// fetch all terms
|
78 |
+
wp.apiFetch({
|
79 |
+
path: wp.url.addQueryArgs(`wp/v2/${taxAttributes.rest_base}`, {context: 'edit'}),
|
80 |
+
}).then((terms) => {
|
81 |
terms.forEach(term => {
|
82 |
+
categoriesList[decodeEntities(term.name)] = term;
|
83 |
+
catIdVsName[term.id] = decodeEntities(term.name);
|
84 |
+
});
|
85 |
+
this.setState({
|
86 |
+
categoriesList: categoriesList,
|
87 |
+
catIdVsName: catIdVsName,
|
88 |
+
taxonomy: decodeEntities(taxAttributes.name)
|
89 |
});
|
|
|
90 |
});
|
91 |
});
|
92 |
}
|
94 |
}
|
95 |
|
96 |
componentDidUpdate() {
|
97 |
+
const {enabled, date, expireAction, categories, attribute} = this.state;
|
98 |
+
const setPostMeta = (newMeta) => wp.data.dispatch('core/editor').editPost({meta: newMeta});
|
99 |
+
const postMeta = wp.data.select('core/editor').getEditedPostAttribute('meta');
|
100 |
|
101 |
+
switch (attribute) {
|
102 |
case 'enabled':
|
103 |
+
setPostMeta({'_expiration-date-status': (enabled ? 'saved' : '')});
|
104 |
// if date is not set when the checkbox is enabled, set it to the default date
|
105 |
// this is to prevent the user from having to click the date to set it
|
106 |
+
if (!postMeta['_expiration-date']) {
|
107 |
+
setPostMeta({'_expiration-date': this.getDate(date)});
|
108 |
}
|
109 |
break;
|
110 |
case 'date':
|
111 |
+
if (typeof date === 'string') {
|
112 |
+
setPostMeta({'_expiration-date': this.getDate(date)});
|
113 |
}
|
114 |
break;
|
115 |
case 'action':
|
116 |
+
setPostMeta({'_expiration-date-type': expireAction});
|
117 |
+
if (!expireAction.includes('category')) {
|
118 |
+
setPostMeta({'_expiration-date-categories': []});
|
119 |
}
|
120 |
break;
|
121 |
case 'category':
|
122 |
+
setPostMeta({'_expiration-date-categories': categories});
|
123 |
break;
|
124 |
}
|
125 |
|
126 |
}
|
127 |
|
128 |
render() {
|
129 |
+
const {categoriesList, catIdVsName} = this.state;
|
130 |
+
const {enabled, date, expireAction, categories, taxonomy} = this.state;
|
131 |
|
132 |
const postType = wp.data.select('core/editor').getCurrentPostType();
|
133 |
|
134 |
let actionsList = [
|
135 |
+
{label: __('Draft', 'post-expirator'), value: 'draft'},
|
136 |
+
{label: __('Delete', 'post-expirator'), value: 'delete'},
|
137 |
+
{label: __('Trash', 'post-expirator'), value: 'trash'},
|
138 |
+
{label: __('Private', 'post-expirator'), value: 'private'},
|
139 |
+
{label: __('Stick', 'post-expirator'), value: 'stick'},
|
140 |
+
{label: __('Unstick', 'post-expirator'), value: 'unstick'},
|
141 |
];
|
142 |
|
143 |
+
if (postType !== 'page') {
|
144 |
actionsList = _.union(actionsList, [
|
145 |
+
{label: __('Category: Replace', 'post-expirator'), value: 'category'},
|
146 |
+
{label: __('Category: Add', 'post-expirator'), value: 'category-add'},
|
147 |
+
{label: __('Category: Remove', 'post-expirator'), value: 'category-remove'},
|
148 |
]);
|
149 |
}
|
150 |
|
151 |
+
let selectedCats = categories && compact(categories.map((id) => catIdVsName[id] || false));
|
152 |
+
if (typeof selectedCats === 'string') {
|
153 |
selectedCats = [];
|
154 |
}
|
155 |
+
|
156 |
return (
|
157 |
+
<PluginDocumentSettingPanel title={__('Post Expirator', 'post-expirator')} icon="calendar"
|
158 |
+
initialOpen={enabled}>
|
159 |
<PanelRow>
|
160 |
<CheckboxControl
|
161 |
+
label={__('Enable Post Expiration', 'post-expirator')}
|
162 |
+
checked={enabled}
|
163 |
+
onChange={(value) => {
|
164 |
+
this.setState({enabled: !enabled, attribute: 'enabled'})
|
165 |
+
}}
|
166 |
/>
|
167 |
</PanelRow>
|
168 |
+
{enabled && (
|
169 |
<Fragment>
|
170 |
<PanelRow>
|
171 |
<DateTimePicker
|
172 |
+
currentDate={date}
|
173 |
+
onChange={(value) => this.setState({date: value, attribute: 'date'})}
|
174 |
+
is12Hour={true}
|
175 |
/>
|
176 |
</PanelRow>
|
177 |
<SelectControl
|
178 |
+
label={__('How to expire', 'post-expirator')}
|
179 |
+
value={expireAction}
|
180 |
+
options={actionsList}
|
181 |
+
onChange={(value) => {
|
182 |
+
this.setState({expireAction: value, attribute: 'action'})
|
183 |
+
}}
|
184 |
/>
|
185 |
+
{expireAction.includes('category') &&
|
186 |
+
(
|
187 |
+
(isEmpty(keys(categoriesList)) && (
|
188 |
+
<Fragment>
|
189 |
+
{__('Loading', 'post-expirator') + ` (${taxonomy})`}
|
190 |
+
<Spinner/>
|
191 |
+
</Fragment>
|
192 |
+
))
|
193 |
+
||
|
194 |
(
|
195 |
+
<FormTokenField
|
196 |
+
label={__('Expiration Categories', 'post-expirator') + ` (${taxonomy})`}
|
197 |
+
value={selectedCats}
|
198 |
+
suggestions={Object.keys(categoriesList)}
|
199 |
+
onChange={(value) => {
|
200 |
+
this.setState({
|
201 |
+
categories: this.selectCategories(value),
|
202 |
+
attribute: 'category'
|
203 |
+
})
|
204 |
+
}}
|
205 |
+
maxSuggestions={10}
|
206 |
+
/>
|
207 |
+
)
|
208 |
+
)}
|
|
|
|
|
|
|
209 |
</Fragment>
|
210 |
+
)}
|
211 |
</PluginDocumentSettingPanel>
|
212 |
);
|
213 |
}
|
217 |
let typeNew = postMeta['_expiration-date-type'];
|
218 |
let typeOld = postMeta['_expiration-date-options'] && postMeta['_expiration-date-options']['expireType'];
|
219 |
|
220 |
+
if (typeNew) {
|
221 |
return typeNew;
|
222 |
}
|
223 |
|
224 |
+
if (typeOld) {
|
225 |
return typeOld;
|
226 |
}
|
227 |
|
233 |
let categoriesNew = postMeta['_expiration-date-categories'] && postMeta['_expiration-date-categories'];
|
234 |
let categoriesOld = postMeta['_expiration-date-options'] && postMeta['_expiration-date-options']['category'];
|
235 |
|
236 |
+
if (typeof categoriesNew === 'object' && categoriesNew.length > 0) {
|
237 |
return categoriesNew;
|
238 |
}
|
239 |
|
240 |
+
if (categoriesOld && typeof categoriesOld !== 'undefined' && typeof categoriesOld !== 'object') {
|
241 |
+
categories = [categoriesOld];
|
242 |
}
|
243 |
|
244 |
return categoriesOld;
|
247 |
|
248 |
// fired for the autocomplete
|
249 |
selectCategories(tokens) {
|
250 |
+
const {categoriesList, catIdVsName} = this.state;
|
251 |
|
252 |
var hasNoSuggestion = tokens.some(function (token) {
|
253 |
return typeof token === 'string' && !categoriesList[token];
|
261 |
return typeof token === 'string' ? categoriesList[token] : token;
|
262 |
})
|
263 |
|
264 |
+
return categories.map((cat) => cat.id);
|
265 |
}
|
266 |
|
267 |
+
getDate(date) {
|
268 |
let newDate = new Date();
|
269 |
newDate.setTime(Date.parse(date));
|
270 |
newDate.setTime(newDate.getTime() - new Date().getTimezoneOffset() * 60 * 1000);
|
273 |
|
274 |
}
|
275 |
|
276 |
+
registerPlugin('postexpirator-sidebar', {
|
277 |
render: PostExpiratorSidebar
|
278 |
+
});
|
279 |
|
280 |
|
281 |
+
})(window.wp, config);
|
classes/Display.class.php
CHANGED
@@ -24,6 +24,7 @@ class PostExpirator_Display {
|
|
24 |
if ( is_null( self::$_instance ) ) {
|
25 |
self::$_instance = new self();
|
26 |
}
|
|
|
27 |
return self::$_instance;
|
28 |
}
|
29 |
|
@@ -38,7 +39,10 @@ class PostExpirator_Display {
|
|
38 |
* Add plugin page menu.
|
39 |
*/
|
40 |
function add_menu() {
|
41 |
-
add_submenu_page( 'options-general.php', __( 'Post Expirator Options', 'post-expirator' ), __( 'Post Expirator', 'post-expirator' ), 'manage_options', POSTEXPIRATOR_BASENAME, array(
|
|
|
|
|
|
|
42 |
}
|
43 |
|
44 |
/**
|
@@ -104,7 +108,12 @@ class PostExpirator_Display {
|
|
104 |
$tabs[] = 'viewdebug';
|
105 |
}
|
106 |
|
107 |
-
$this->render_template( 'tabs', array(
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
}
|
110 |
|
@@ -119,19 +128,19 @@ class PostExpirator_Display {
|
|
119 |
}
|
120 |
if ( isset( $_POST['debugging-disable'] ) ) {
|
121 |
update_option( 'expirationdateDebug', 0 );
|
122 |
-
|
123 |
_e( 'Debugging Disabled', 'post-expirator' );
|
124 |
echo '</p></div>';
|
125 |
} elseif ( isset( $_POST['debugging-enable'] ) ) {
|
126 |
update_option( 'expirationdateDebug', 1 );
|
127 |
-
|
128 |
_e( 'Debugging Enabled', 'post-expirator' );
|
129 |
echo '</p></div>';
|
130 |
} elseif ( isset( $_POST['purge-debug'] ) ) {
|
131 |
require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' );
|
132 |
$debug = new PostExpiratorDebug();
|
133 |
$debug->purge();
|
134 |
-
|
135 |
_e( 'Debugging Table Emptied', 'post-expirator' );
|
136 |
echo '</p></div>';
|
137 |
}
|
@@ -156,8 +165,8 @@ class PostExpirator_Display {
|
|
156 |
* The default menu.
|
157 |
*/
|
158 |
private function menu_defaults() {
|
159 |
-
$debug
|
160 |
-
$types
|
161 |
$defaults = array();
|
162 |
|
163 |
if ( isset( $_POST['expirationdateSaveDefaults'] ) ) {
|
@@ -228,9 +237,30 @@ class PostExpirator_Display {
|
|
228 |
if ( $_POST['expired-custom-expiration-date'] ) {
|
229 |
update_option( 'expirationdateDefaultDateCustom', $_POST['expired-custom-expiration-date'] );
|
230 |
}
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
235 |
}
|
236 |
|
24 |
if ( is_null( self::$_instance ) ) {
|
25 |
self::$_instance = new self();
|
26 |
}
|
27 |
+
|
28 |
return self::$_instance;
|
29 |
}
|
30 |
|
39 |
* Add plugin page menu.
|
40 |
*/
|
41 |
function add_menu() {
|
42 |
+
add_submenu_page( 'options-general.php', __( 'Post Expirator Options', 'post-expirator' ), __( 'Post Expirator', 'post-expirator' ), 'manage_options', POSTEXPIRATOR_BASENAME, array(
|
43 |
+
self::$_instance,
|
44 |
+
'settings_tabs'
|
45 |
+
) );
|
46 |
}
|
47 |
|
48 |
/**
|
108 |
$tabs[] = 'viewdebug';
|
109 |
}
|
110 |
|
111 |
+
$this->render_template( 'tabs', array(
|
112 |
+
'tabs' => $tabs,
|
113 |
+
'tab_index' => $tab_index,
|
114 |
+
'html' => $html,
|
115 |
+
'tab' => $tab
|
116 |
+
) );
|
117 |
|
118 |
}
|
119 |
|
128 |
}
|
129 |
if ( isset( $_POST['debugging-disable'] ) ) {
|
130 |
update_option( 'expirationdateDebug', 0 );
|
131 |
+
echo "<div id='message' class='updated fade'><p>";
|
132 |
_e( 'Debugging Disabled', 'post-expirator' );
|
133 |
echo '</p></div>';
|
134 |
} elseif ( isset( $_POST['debugging-enable'] ) ) {
|
135 |
update_option( 'expirationdateDebug', 1 );
|
136 |
+
echo "<div id='message' class='updated fade'><p>";
|
137 |
_e( 'Debugging Enabled', 'post-expirator' );
|
138 |
echo '</p></div>';
|
139 |
} elseif ( isset( $_POST['purge-debug'] ) ) {
|
140 |
require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' );
|
141 |
$debug = new PostExpiratorDebug();
|
142 |
$debug->purge();
|
143 |
+
echo "<div id='message' class='updated fade'><p>";
|
144 |
_e( 'Debugging Table Emptied', 'post-expirator' );
|
145 |
echo '</p></div>';
|
146 |
}
|
165 |
* The default menu.
|
166 |
*/
|
167 |
private function menu_defaults() {
|
168 |
+
$debug = postexpirator_debug();
|
169 |
+
$types = postexpirator_get_post_types();
|
170 |
$defaults = array();
|
171 |
|
172 |
if ( isset( $_POST['expirationdateSaveDefaults'] ) ) {
|
237 |
if ( $_POST['expired-custom-expiration-date'] ) {
|
238 |
update_option( 'expirationdateDefaultDateCustom', $_POST['expired-custom-expiration-date'] );
|
239 |
}
|
240 |
+
|
241 |
+
if ( ! isset( $_POST['allow-user-roles'] ) || ! is_array( $_POST['allow-user-roles'] ) ) {
|
242 |
+
$_POST['allow-user-roles'] = array();
|
243 |
+
}
|
244 |
+
|
245 |
+
$user_roles = wp_roles()->get_names();
|
246 |
+
|
247 |
+
foreach ( $user_roles as $role_name => $role_label ) {
|
248 |
+
$role = get_role( $role_name );
|
249 |
+
|
250 |
+
if ( ! is_a( $role, WP_Role::class ) ) {
|
251 |
+
continue;
|
252 |
+
}
|
253 |
+
|
254 |
+
if ( $role_name === 'administrator' || in_array( $role_name, $_POST['allow-user-roles'], true ) ) {
|
255 |
+
$role->add_cap( PostExpirator_Facade::DEFAULT_CAPABILITY_EXPIRE_POST );
|
256 |
+
} else {
|
257 |
+
$role->remove_cap( PostExpirator_Facade::DEFAULT_CAPABILITY_EXPIRE_POST );
|
258 |
+
}
|
259 |
+
}
|
260 |
+
|
261 |
+
echo "<div id='message' class='updated fade'><p>";
|
262 |
+
_e( 'Saved Options!', 'post-expirator' );
|
263 |
+
echo '</p></div>';
|
264 |
}
|
265 |
}
|
266 |
|
classes/Facade.class.php
CHANGED
@@ -12,12 +12,27 @@ class PostExpirator_Facade {
|
|
12 |
*/
|
13 |
private static $_instance = null;
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
/**
|
16 |
* Constructor.
|
17 |
*/
|
18 |
private function __construct() {
|
19 |
PostExpirator_Display::getInstance();
|
20 |
$this->hooks();
|
|
|
|
|
|
|
|
|
21 |
}
|
22 |
|
23 |
/**
|
@@ -27,6 +42,7 @@ class PostExpirator_Facade {
|
|
27 |
if ( is_null( self::$_instance ) ) {
|
28 |
self::$_instance = new self();
|
29 |
}
|
|
|
30 |
return self::$_instance;
|
31 |
}
|
32 |
|
@@ -35,8 +51,9 @@ class PostExpirator_Facade {
|
|
35 |
*/
|
36 |
private function hooks() {
|
37 |
add_action( 'init', array( $this, 'register_post_meta' ), 11 );
|
38 |
-
add_action( 'enqueue_block_editor_assets', array( $this, 'block_editor_assets') );
|
39 |
add_action( 'updated_postmeta', array( $this, 'updatedmeta' ), 10, 4 );
|
|
|
40 |
}
|
41 |
|
42 |
/**
|
@@ -45,7 +62,12 @@ class PostExpirator_Facade {
|
|
45 |
public static function load_assets( $for ) {
|
46 |
switch ( $for ) {
|
47 |
case 'settings':
|
48 |
-
wp_enqueue_script(
|
|
|
|
|
|
|
|
|
|
|
49 |
wp_localize_script( 'pe-settings', 'config', array() );
|
50 |
wp_enqueue_style( 'pe-settings', POSTEXPIRATOR_BASEURL . '/assets/css/settings.css', array(), POSTEXPIRATOR_VERSION, false );
|
51 |
wp_enqueue_style( 'pe-jquery-ui', POSTEXPIRATOR_BASEURL . '/assets/css/lib/jquery-ui/jquery-ui.min.css', array( 'pe-settings' ), POSTEXPIRATOR_VERSION );
|
@@ -97,7 +119,7 @@ class PostExpirator_Facade {
|
|
97 |
|
98 |
if ( $schedule ) {
|
99 |
$opts = self::get_expire_principles( $post_id );
|
100 |
-
$ts
|
101 |
$this->schedule_event( $post_id, $ts, $opts );
|
102 |
}
|
103 |
}
|
@@ -106,12 +128,12 @@ class PostExpirator_Facade {
|
|
106 |
* Calculates the default expiry date as set in the options.
|
107 |
*/
|
108 |
public static function get_default_expiry( $post_type ) {
|
109 |
-
$defaultmonth
|
110 |
-
$defaultday
|
111 |
-
$defaulthour
|
112 |
-
$defaultyear
|
113 |
-
$defaultminute
|
114 |
-
$ts
|
115 |
|
116 |
$default_date_expiry = $custom_date = '';
|
117 |
$general_date_expiry = $general_custom_date = '';
|
@@ -135,13 +157,13 @@ class PostExpirator_Facade {
|
|
135 |
$custom_date = $defaults['default-custom-date'];
|
136 |
break;
|
137 |
case 'inherit':
|
138 |
-
$custom_date
|
139 |
$default_date_expiry = $general_date_expiry;
|
140 |
break;
|
141 |
}
|
142 |
} else {
|
143 |
$default_date_expiry = $general_date_expiry;
|
144 |
-
$custom_date
|
145 |
}
|
146 |
|
147 |
if ( 'custom' === $default_date_expiry ) {
|
@@ -164,20 +186,20 @@ class PostExpirator_Facade {
|
|
164 |
date_default_timezone_set( 'UTC' );
|
165 |
}
|
166 |
}
|
167 |
-
$defaultmonth
|
168 |
-
$defaultday
|
169 |
-
$defaultyear
|
170 |
-
$defaulthour
|
171 |
-
$defaultminute
|
172 |
}
|
173 |
|
174 |
return array(
|
175 |
-
'month'
|
176 |
-
'day'
|
177 |
-
'year'
|
178 |
-
'hour'
|
179 |
'minute' => $defaultminute,
|
180 |
-
'ts'
|
181 |
);
|
182 |
}
|
183 |
|
@@ -215,7 +237,7 @@ class PostExpirator_Facade {
|
|
215 |
}
|
216 |
|
217 |
// _expiration-date-options is deprecated when using block editor
|
218 |
-
$opts
|
219 |
if ( empty( $expireType ) && isset( $opts['expireType'] ) ) {
|
220 |
$expireType = $opts['expireType'];
|
221 |
}
|
@@ -228,8 +250,8 @@ class PostExpirator_Facade {
|
|
228 |
}
|
229 |
|
230 |
return array(
|
231 |
-
'expireType'
|
232 |
-
'category'
|
233 |
'categoryTaxonomy' => $taxonomyName,
|
234 |
);
|
235 |
}
|
@@ -239,7 +261,7 @@ class PostExpirator_Facade {
|
|
239 |
* Register the post meta to use in the block.
|
240 |
*/
|
241 |
function register_post_meta() {
|
242 |
-
$post_types = get_post_types( array('public' => true) );
|
243 |
foreach ( $post_types as $post_type ) {
|
244 |
|
245 |
// this is important for CPTs to show the postMeta.
|
@@ -247,44 +269,44 @@ class PostExpirator_Facade {
|
|
247 |
|
248 |
register_post_meta(
|
249 |
$post_type, '_expiration-date-status', array(
|
250 |
-
'single'
|
251 |
-
'type'
|
252 |
-
'auth_callback' => function() {
|
253 |
return current_user_can( 'edit_posts' );
|
254 |
},
|
255 |
-
'show_in_rest'
|
256 |
)
|
257 |
);
|
258 |
register_post_meta(
|
259 |
$post_type, '_expiration-date', array(
|
260 |
-
'single'
|
261 |
-
'type'
|
262 |
-
'auth_callback' => function() {
|
263 |
return current_user_can( 'edit_posts' );
|
264 |
},
|
265 |
-
'show_in_rest'
|
266 |
)
|
267 |
);
|
268 |
register_post_meta(
|
269 |
$post_type, '_expiration-date-type', array(
|
270 |
-
'single'
|
271 |
-
'type'
|
272 |
-
'auth_callback' => function() {
|
273 |
return current_user_can( 'edit_posts' );
|
274 |
},
|
275 |
-
'show_in_rest'
|
276 |
)
|
277 |
);
|
278 |
register_post_meta(
|
279 |
$post_type, '_expiration-date-categories', array(
|
280 |
-
'single'
|
281 |
-
'type'
|
282 |
-
'auth_callback' => function() {
|
283 |
return current_user_can( 'edit_posts' );
|
284 |
},
|
285 |
-
'show_in_rest'
|
286 |
'schema' => array(
|
287 |
-
'type'
|
288 |
'items' => array(
|
289 |
'type' => 'number',
|
290 |
),
|
@@ -297,14 +319,14 @@ class PostExpirator_Facade {
|
|
297 |
// as it cannot be used easily in the block editor
|
298 |
register_post_meta(
|
299 |
$post_type, '_expiration-date-options', array(
|
300 |
-
'single'
|
301 |
-
'type'
|
302 |
-
'auth_callback' => function() {
|
303 |
return current_user_can( 'edit_posts' );
|
304 |
},
|
305 |
-
'show_in_rest'
|
306 |
'schema' => array(
|
307 |
-
'type'
|
308 |
'additionalProperties' => true,
|
309 |
),
|
310 |
),
|
@@ -326,7 +348,12 @@ class PostExpirator_Facade {
|
|
326 |
|
327 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post->post_type ) );
|
328 |
// if settings are not configured, show the metabox by default only for posts and pages
|
329 |
-
if ( ( ! isset( $defaults['activeMetaBox'] ) && in_array(
|
|
|
|
|
|
|
|
|
|
|
330 |
wp_enqueue_script(
|
331 |
'postexpirator-block',
|
332 |
POSTEXPIRATOR_BASEURL . 'assets/js/block.js',
|
@@ -338,8 +365,8 @@ class PostExpirator_Facade {
|
|
338 |
$default_expiry = PostExpirator_Facade::get_default_expiry( $post->post_type );
|
339 |
wp_localize_script(
|
340 |
'postexpirator-block', 'config', array(
|
341 |
-
'defaults'
|
342 |
-
'default_date'
|
343 |
'default_categories' => get_option( 'expirationdateCategoryDefaults' ),
|
344 |
)
|
345 |
);
|
@@ -352,7 +379,10 @@ class PostExpirator_Facade {
|
|
352 |
*/
|
353 |
public static function show_gutenberg_metabox() {
|
354 |
$gutenberg = get_option( 'expirationdateGutenbergSupport', 1 );
|
355 |
-
|
|
|
|
|
|
|
356 |
}
|
357 |
|
358 |
/**
|
@@ -369,4 +399,55 @@ class PostExpirator_Facade {
|
|
369 |
postexpirator_schedule_event( $post_id, $ts, $opts );
|
370 |
}
|
371 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
372 |
}
|
12 |
*/
|
13 |
private static $_instance = null;
|
14 |
|
15 |
+
const DEFAULT_CAPABILITY_EXPIRE_POST = 'publishpress_future_expire_post';
|
16 |
+
|
17 |
+
/**
|
18 |
+
* List of capabilities used by the plugin.
|
19 |
+
*
|
20 |
+
* @var string[]
|
21 |
+
*/
|
22 |
+
private $capabilities = array(
|
23 |
+
'expire_post' => self::DEFAULT_CAPABILITY_EXPIRE_POST,
|
24 |
+
);
|
25 |
+
|
26 |
/**
|
27 |
* Constructor.
|
28 |
*/
|
29 |
private function __construct() {
|
30 |
PostExpirator_Display::getInstance();
|
31 |
$this->hooks();
|
32 |
+
|
33 |
+
if ( ! $this->user_role_can_expire_posts( 'administrator' ) ) {
|
34 |
+
$this->set_default_capabilities();
|
35 |
+
}
|
36 |
}
|
37 |
|
38 |
/**
|
42 |
if ( is_null( self::$_instance ) ) {
|
43 |
self::$_instance = new self();
|
44 |
}
|
45 |
+
|
46 |
return self::$_instance;
|
47 |
}
|
48 |
|
51 |
*/
|
52 |
private function hooks() {
|
53 |
add_action( 'init', array( $this, 'register_post_meta' ), 11 );
|
54 |
+
add_action( 'enqueue_block_editor_assets', array( $this, 'block_editor_assets' ) );
|
55 |
add_action( 'updated_postmeta', array( $this, 'updatedmeta' ), 10, 4 );
|
56 |
+
add_filter( 'cme_plugin_capabilities', [ $this, 'filter_cme_capabilities' ], 20 );
|
57 |
}
|
58 |
|
59 |
/**
|
62 |
public static function load_assets( $for ) {
|
63 |
switch ( $for ) {
|
64 |
case 'settings':
|
65 |
+
wp_enqueue_script(
|
66 |
+
'pe-settings', POSTEXPIRATOR_BASEURL . '/assets/js/settings.js', array(
|
67 |
+
'jquery',
|
68 |
+
'jquery-ui-tabs',
|
69 |
+
), POSTEXPIRATOR_VERSION, false
|
70 |
+
);
|
71 |
wp_localize_script( 'pe-settings', 'config', array() );
|
72 |
wp_enqueue_style( 'pe-settings', POSTEXPIRATOR_BASEURL . '/assets/css/settings.css', array(), POSTEXPIRATOR_VERSION, false );
|
73 |
wp_enqueue_style( 'pe-jquery-ui', POSTEXPIRATOR_BASEURL . '/assets/css/lib/jquery-ui/jquery-ui.min.css', array( 'pe-settings' ), POSTEXPIRATOR_VERSION );
|
119 |
|
120 |
if ( $schedule ) {
|
121 |
$opts = self::get_expire_principles( $post_id );
|
122 |
+
$ts = $meta_value;
|
123 |
$this->schedule_event( $post_id, $ts, $opts );
|
124 |
}
|
125 |
}
|
128 |
* Calculates the default expiry date as set in the options.
|
129 |
*/
|
130 |
public static function get_default_expiry( $post_type ) {
|
131 |
+
$defaultmonth = date_i18n( 'm' );
|
132 |
+
$defaultday = date_i18n( 'd' );
|
133 |
+
$defaulthour = date_i18n( 'H' );
|
134 |
+
$defaultyear = date_i18n( 'Y' );
|
135 |
+
$defaultminute = date_i18n( 'i' );
|
136 |
+
$ts = time();
|
137 |
|
138 |
$default_date_expiry = $custom_date = '';
|
139 |
$general_date_expiry = $general_custom_date = '';
|
157 |
$custom_date = $defaults['default-custom-date'];
|
158 |
break;
|
159 |
case 'inherit':
|
160 |
+
$custom_date = $general_custom_date;
|
161 |
$default_date_expiry = $general_date_expiry;
|
162 |
break;
|
163 |
}
|
164 |
} else {
|
165 |
$default_date_expiry = $general_date_expiry;
|
166 |
+
$custom_date = $general_custom_date;
|
167 |
}
|
168 |
|
169 |
if ( 'custom' === $default_date_expiry ) {
|
186 |
date_default_timezone_set( 'UTC' );
|
187 |
}
|
188 |
}
|
189 |
+
$defaultmonth = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'm' );
|
190 |
+
$defaultday = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'd' );
|
191 |
+
$defaultyear = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'Y' );
|
192 |
+
$defaulthour = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'H' );
|
193 |
+
$defaultminute = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $ts ), 'i' );
|
194 |
}
|
195 |
|
196 |
return array(
|
197 |
+
'month' => $defaultmonth,
|
198 |
+
'day' => $defaultday,
|
199 |
+
'year' => $defaultyear,
|
200 |
+
'hour' => $defaulthour,
|
201 |
'minute' => $defaultminute,
|
202 |
+
'ts' => $ts,
|
203 |
);
|
204 |
}
|
205 |
|
237 |
}
|
238 |
|
239 |
// _expiration-date-options is deprecated when using block editor
|
240 |
+
$opts = get_post_meta( $id, '_expiration-date-options', true );
|
241 |
if ( empty( $expireType ) && isset( $opts['expireType'] ) ) {
|
242 |
$expireType = $opts['expireType'];
|
243 |
}
|
250 |
}
|
251 |
|
252 |
return array(
|
253 |
+
'expireType' => $expireType,
|
254 |
+
'category' => $categories,
|
255 |
'categoryTaxonomy' => $taxonomyName,
|
256 |
);
|
257 |
}
|
261 |
* Register the post meta to use in the block.
|
262 |
*/
|
263 |
function register_post_meta() {
|
264 |
+
$post_types = get_post_types( array( 'public' => true ) );
|
265 |
foreach ( $post_types as $post_type ) {
|
266 |
|
267 |
// this is important for CPTs to show the postMeta.
|
269 |
|
270 |
register_post_meta(
|
271 |
$post_type, '_expiration-date-status', array(
|
272 |
+
'single' => true,
|
273 |
+
'type' => 'string',
|
274 |
+
'auth_callback' => function () {
|
275 |
return current_user_can( 'edit_posts' );
|
276 |
},
|
277 |
+
'show_in_rest' => true,
|
278 |
)
|
279 |
);
|
280 |
register_post_meta(
|
281 |
$post_type, '_expiration-date', array(
|
282 |
+
'single' => true,
|
283 |
+
'type' => 'number',
|
284 |
+
'auth_callback' => function () {
|
285 |
return current_user_can( 'edit_posts' );
|
286 |
},
|
287 |
+
'show_in_rest' => true,
|
288 |
)
|
289 |
);
|
290 |
register_post_meta(
|
291 |
$post_type, '_expiration-date-type', array(
|
292 |
+
'single' => true,
|
293 |
+
'type' => 'string',
|
294 |
+
'auth_callback' => function () {
|
295 |
return current_user_can( 'edit_posts' );
|
296 |
},
|
297 |
+
'show_in_rest' => true,
|
298 |
)
|
299 |
);
|
300 |
register_post_meta(
|
301 |
$post_type, '_expiration-date-categories', array(
|
302 |
+
'single' => true,
|
303 |
+
'type' => 'array',
|
304 |
+
'auth_callback' => function () {
|
305 |
return current_user_can( 'edit_posts' );
|
306 |
},
|
307 |
+
'show_in_rest' => array(
|
308 |
'schema' => array(
|
309 |
+
'type' => 'array',
|
310 |
'items' => array(
|
311 |
'type' => 'number',
|
312 |
),
|
319 |
// as it cannot be used easily in the block editor
|
320 |
register_post_meta(
|
321 |
$post_type, '_expiration-date-options', array(
|
322 |
+
'single' => true,
|
323 |
+
'type' => 'object',
|
324 |
+
'auth_callback' => function () {
|
325 |
return current_user_can( 'edit_posts' );
|
326 |
},
|
327 |
+
'show_in_rest' => array(
|
328 |
'schema' => array(
|
329 |
+
'type' => 'object',
|
330 |
'additionalProperties' => true,
|
331 |
),
|
332 |
),
|
348 |
|
349 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post->post_type ) );
|
350 |
// if settings are not configured, show the metabox by default only for posts and pages
|
351 |
+
if ( ( ! isset( $defaults['activeMetaBox'] ) && in_array(
|
352 |
+
$post->post_type, array(
|
353 |
+
'post',
|
354 |
+
'page',
|
355 |
+
), true
|
356 |
+
) ) || $defaults['activeMetaBox'] === 'active' ) {
|
357 |
wp_enqueue_script(
|
358 |
'postexpirator-block',
|
359 |
POSTEXPIRATOR_BASEURL . 'assets/js/block.js',
|
365 |
$default_expiry = PostExpirator_Facade::get_default_expiry( $post->post_type );
|
366 |
wp_localize_script(
|
367 |
'postexpirator-block', 'config', array(
|
368 |
+
'defaults' => $defaults,
|
369 |
+
'default_date' => $default_expiry['ts'],
|
370 |
'default_categories' => get_option( 'expirationdateCategoryDefaults' ),
|
371 |
)
|
372 |
);
|
379 |
*/
|
380 |
public static function show_gutenberg_metabox() {
|
381 |
$gutenberg = get_option( 'expirationdateGutenbergSupport', 1 );
|
382 |
+
|
383 |
+
$facade = PostExpirator_Facade::getInstance();
|
384 |
+
|
385 |
+
return intval( $gutenberg ) === 1 && $facade->current_user_can_expire_posts();
|
386 |
}
|
387 |
|
388 |
/**
|
399 |
postexpirator_schedule_event( $post_id, $ts, $opts );
|
400 |
}
|
401 |
|
402 |
+
/**
|
403 |
+
* Return true if the specific user role can expire posts.
|
404 |
+
*
|
405 |
+
* @return bool
|
406 |
+
*/
|
407 |
+
public function user_role_can_expire_posts( $user_role ) {
|
408 |
+
$user_role_instance = get_role( $user_role );
|
409 |
+
|
410 |
+
if ( ! is_a( $user_role_instance, WP_Role::class ) ) {
|
411 |
+
return false;
|
412 |
+
}
|
413 |
+
|
414 |
+
return $user_role_instance->has_cap( $this->capabilities['expire_post'] )
|
415 |
+
&& $user_role_instance->capabilities[ $this->capabilities['expire_post'] ] === true;
|
416 |
+
}
|
417 |
+
|
418 |
+
/**
|
419 |
+
* Returns true if the current user can expire posts.
|
420 |
+
*
|
421 |
+
* @return bool
|
422 |
+
*/
|
423 |
+
public function current_user_can_expire_posts() {
|
424 |
+
$current_user = wp_get_current_user();
|
425 |
+
|
426 |
+
return is_a( $current_user, WP_User::class )
|
427 |
+
&& $current_user->has_cap( $this->capabilities['expire_post'] );
|
428 |
+
}
|
429 |
+
|
430 |
+
/**
|
431 |
+
* Set the default capabilities.
|
432 |
+
*/
|
433 |
+
public function set_default_capabilities() {
|
434 |
+
$admin_role = get_role( 'administrator' );
|
435 |
+
$admin_role->add_cap( self::DEFAULT_CAPABILITY_EXPIRE_POST );
|
436 |
+
}
|
437 |
+
|
438 |
+
/**
|
439 |
+
* Add the plugin capabilities to the PublishPress Capabilities plugin.
|
440 |
+
*
|
441 |
+
* @param array $capabilities Array of capabilities.
|
442 |
+
*
|
443 |
+
* @return array
|
444 |
+
*/
|
445 |
+
public function filter_cme_capabilities( $capabilities ) {
|
446 |
+
return array_merge(
|
447 |
+
$capabilities,
|
448 |
+
array(
|
449 |
+
'Post Expirator' => array( self::DEFAULT_CAPABILITY_EXPIRE_POST ),
|
450 |
+
)
|
451 |
+
);
|
452 |
+
}
|
453 |
}
|
composer.json
CHANGED
@@ -26,7 +26,7 @@
|
|
26 |
}
|
27 |
],
|
28 |
"dist": {
|
29 |
-
"url": "https://github.com/publishpress/PublishPress-Future/releases/download/v2.5.1/post-expirator-2.5.1.zip",
|
30 |
"type": "zip"
|
31 |
},
|
32 |
"require-dev": {
|
@@ -36,4 +36,4 @@
|
|
36 |
"wp-coding-standards/wpcs": "*",
|
37 |
"publishpress/publishpress-plugin-builder": "^1.3"
|
38 |
}
|
39 |
-
}
|
26 |
}
|
27 |
],
|
28 |
"dist": {
|
29 |
+
"url": "https://github.com/publishpress/PublishPress-Future/releases/download/v2.5.2-beta.1/post-expirator-2.5.2-beta.1.zip",
|
30 |
"type": "zip"
|
31 |
},
|
32 |
"require-dev": {
|
36 |
"wp-coding-standards/wpcs": "*",
|
37 |
"publishpress/publishpress-plugin-builder": "^1.3"
|
38 |
}
|
39 |
+
}
|
functions.php
CHANGED
@@ -4,4 +4,3 @@
|
|
4 |
*/
|
5 |
|
6 |
require_once POSTEXPIRATOR_BASEDIR . '/legacy-functions.php';
|
7 |
-
|
4 |
*/
|
5 |
|
6 |
require_once POSTEXPIRATOR_BASEDIR . '/legacy-functions.php';
|
|
legacy-functions.php
CHANGED
@@ -56,6 +56,7 @@ if ( ! function_exists( '_postExpiratorExpireType' ) ) {
|
|
56 |
function _postExpiratorExpireType( $opts ) {
|
57 |
ob_start();
|
58 |
_postexpirator_expire_type( $opts );
|
|
|
59 |
return ob_get_clean();
|
60 |
}
|
61 |
}
|
56 |
function _postExpiratorExpireType( $opts ) {
|
57 |
ob_start();
|
58 |
_postexpirator_expire_type( $opts );
|
59 |
+
|
60 |
return ob_get_clean();
|
61 |
}
|
62 |
}
|
post-expirator-debug.php
CHANGED
@@ -64,6 +64,7 @@ class PostExpiratorDebug {
|
|
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">';
|
@@ -85,4 +86,4 @@ class PostExpiratorDebug {
|
|
85 |
}
|
86 |
}
|
87 |
|
88 |
-
// phpcs:enable
|
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 |
+
|
68 |
return;
|
69 |
}
|
70 |
print '<table class="post-expirator-debug">';
|
86 |
}
|
87 |
}
|
88 |
|
89 |
+
// phpcs:enable
|
post-expirator.php
CHANGED
@@ -4,14 +4,14 @@ 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: PublishPress
|
7 |
-
Version: 2.
|
8 |
Author URI: http://publishpress.com
|
9 |
Text Domain: post-expirator
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
// Default Values
|
14 |
-
define( 'POSTEXPIRATOR_VERSION', '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' ) );
|
@@ -41,8 +41,10 @@ function postexpirator_plugin_action_links( $links, $file ) {
|
|
41 |
if ( $file === $this_plugin ) {
|
42 |
$links[] = '<a href="options-general.php?page=post-expirator">' . __( 'Settings', 'post-expirator' ) . '</a>';
|
43 |
}
|
|
|
44 |
return $links;
|
45 |
}
|
|
|
46 |
add_filter( 'plugin_action_links', 'postexpirator_plugin_action_links', 10, 2 );
|
47 |
|
48 |
/**
|
@@ -56,6 +58,7 @@ function postexpirator_init() {
|
|
56 |
$plugin_dir = basename( dirname( __FILE__ ) );
|
57 |
load_plugin_textdomain( 'post-expirator', null, $plugin_dir . '/languages/' );
|
58 |
}
|
|
|
59 |
add_action( 'plugins_loaded', 'postexpirator_init' );
|
60 |
|
61 |
/**
|
@@ -68,11 +71,16 @@ add_action( 'plugins_loaded', 'postexpirator_init' );
|
|
68 |
function postexpirator_add_column( $columns, $type ) {
|
69 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
|
70 |
// if settings are not configured, show the metabox by default only for posts and pages
|
71 |
-
if ( ( ! isset( $defaults['activeMetaBox'] ) && in_array( $type, array(
|
|
|
|
|
|
|
72 |
$columns['expirationdate'] = __( 'Expires', 'post-expirator' );
|
73 |
}
|
|
|
74 |
return $columns;
|
75 |
}
|
|
|
76 |
add_filter( 'manage_posts_columns', 'postexpirator_add_column', 10, 2 );
|
77 |
|
78 |
/**
|
@@ -88,6 +96,7 @@ function postexpirator_manage_sortable_columns() {
|
|
88 |
add_filter( 'manage_edit-' . $post_type . '_sortable_columns', 'postexpirator_sortable_column' );
|
89 |
}
|
90 |
}
|
|
|
91 |
add_action( 'init', 'postexpirator_manage_sortable_columns', 100 );
|
92 |
|
93 |
/**
|
@@ -99,6 +108,7 @@ add_action( 'init', 'postexpirator_manage_sortable_columns', 100 );
|
|
99 |
*/
|
100 |
function postexpirator_sortable_column( $columns ) {
|
101 |
$columns['expirationdate'] = 'expirationdate';
|
|
|
102 |
return $columns;
|
103 |
}
|
104 |
|
@@ -119,21 +129,22 @@ function postexpirator_orderby( $query ) {
|
|
119 |
if ( 'expirationdate' === $orderby ) {
|
120 |
$query->set(
|
121 |
'meta_query', array(
|
122 |
-
'relation'
|
123 |
array(
|
124 |
-
'key'
|
125 |
-
'compare'
|
126 |
),
|
127 |
array(
|
128 |
-
'key'
|
129 |
-
'compare'
|
130 |
-
'value'
|
131 |
),
|
132 |
)
|
133 |
);
|
134 |
-
|
135 |
}
|
136 |
}
|
|
|
137 |
add_action( 'pre_get_posts', 'postexpirator_orderby' );
|
138 |
|
139 |
/**
|
@@ -148,8 +159,10 @@ function postexpirator_add_column_page( $columns ) {
|
|
148 |
if ( ! isset( $defaults['activeMetaBox'] ) || $defaults['activeMetaBox'] === 'active' ) {
|
149 |
$columns['expirationdate'] = __( 'Expires', 'post-expirator' );
|
150 |
}
|
|
|
151 |
return $columns;
|
152 |
}
|
|
|
153 |
add_filter( 'manage_pages_columns', 'postexpirator_add_column_page' );
|
154 |
|
155 |
/**
|
@@ -169,8 +182,13 @@ function postexpirator_show_value( $column_name ) {
|
|
169 |
// get the attributes that quick edit functionality requires
|
170 |
// and save it as a JSON encoded HTML attribute
|
171 |
$attributes = PostExpirator_Facade::get_expire_principles( $post->ID );
|
172 |
-
PostExpirator_Display::getInstance()->render_template( 'expire-column', array(
|
|
|
|
|
|
|
|
|
173 |
}
|
|
|
174 |
add_action( 'manage_posts_custom_column', 'postexpirator_show_value' );
|
175 |
add_action( 'manage_pages_custom_column', 'postexpirator_show_value' );
|
176 |
|
@@ -187,9 +205,15 @@ function postexpirator_quickedit( $column_name, $post_type ) {
|
|
187 |
return;
|
188 |
}
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post_type ) );
|
191 |
$taxonomy = isset( $defaults['taxonomy'] ) ? $defaults['taxonomy'] : '';
|
192 |
-
$label
|
193 |
|
194 |
// if settings have not been configured and this is the default post type
|
195 |
if ( empty( $taxonomy ) && 'post' === $post_type ) {
|
@@ -198,11 +222,16 @@ function postexpirator_quickedit( $column_name, $post_type ) {
|
|
198 |
|
199 |
if ( ! empty( $taxonomy ) ) {
|
200 |
$tax_object = get_taxonomy( $taxonomy );
|
201 |
-
$label
|
202 |
}
|
203 |
|
204 |
-
PostExpirator_Display::getInstance()->render_template( 'quick-edit', array(
|
|
|
|
|
|
|
|
|
205 |
}
|
|
|
206 |
add_action( 'quick_edit_custom_box', 'postexpirator_quickedit', 10, 2 );
|
207 |
|
208 |
/**
|
@@ -217,9 +246,15 @@ function postexpirator_bulkedit( $column_name, $post_type ) {
|
|
217 |
return;
|
218 |
}
|
219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post_type ) );
|
221 |
$taxonomy = isset( $defaults['taxonomy'] ) ? $defaults['taxonomy'] : '';
|
222 |
-
$label
|
223 |
|
224 |
// if settings have not been configured and this is the default post type
|
225 |
if ( empty( $taxonomy ) && 'post' === $post_type ) {
|
@@ -228,11 +263,16 @@ function postexpirator_bulkedit( $column_name, $post_type ) {
|
|
228 |
|
229 |
if ( ! empty( $taxonomy ) ) {
|
230 |
$tax_object = get_taxonomy( $taxonomy );
|
231 |
-
$label
|
232 |
}
|
233 |
|
234 |
-
PostExpirator_Display::getInstance()->render_template( 'bulk-edit', array(
|
|
|
|
|
|
|
|
|
235 |
}
|
|
|
236 |
add_action( 'bulk_edit_custom_box', 'postexpirator_bulkedit', 10, 2 );
|
237 |
|
238 |
/**
|
@@ -244,7 +284,11 @@ add_action( 'bulk_edit_custom_box', 'postexpirator_bulkedit', 10, 2 );
|
|
244 |
*/
|
245 |
function postexpirator_get_post_types() {
|
246 |
$post_types = get_post_types( array( 'public' => true ) );
|
247 |
-
$post_types = array_merge( $post_types, get_post_types( array(
|
|
|
|
|
|
|
|
|
248 |
|
249 |
// in case some post types should not be supported.
|
250 |
$unset_post_types = apply_filters( 'postexpirator_unset_post_types', array( 'attachment' ) );
|
@@ -253,6 +297,7 @@ function postexpirator_get_post_types() {
|
|
253 |
unset( $post_types[ $type ] );
|
254 |
}
|
255 |
}
|
|
|
256 |
return $post_types;
|
257 |
}
|
258 |
|
@@ -264,15 +309,25 @@ function postexpirator_get_post_types() {
|
|
264 |
* @access private
|
265 |
*/
|
266 |
function postexpirator_meta_custom() {
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
$post_types = postexpirator_get_post_types();
|
268 |
foreach ( $post_types as $type ) {
|
269 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
|
270 |
// if settings are not configured, show the metabox by default only for posts and pages
|
271 |
-
if ( ( ! isset( $defaults['activeMetaBox'] ) && in_array( $type, array(
|
|
|
|
|
|
|
272 |
add_meta_box( 'expirationdatediv', __( 'Post Expirator', 'post-expirator' ), 'postexpirator_meta_box', $type, 'side', 'core', array( '__back_compat_meta_box' => PostExpirator_Facade::show_gutenberg_metabox() ) );
|
273 |
}
|
274 |
}
|
275 |
}
|
|
|
276 |
add_action( 'add_meta_boxes', 'postexpirator_meta_custom' );
|
277 |
|
278 |
/**
|
@@ -285,20 +340,20 @@ add_action( 'add_meta_boxes', 'postexpirator_meta_custom' );
|
|
285 |
function postexpirator_meta_box( $post ) {
|
286 |
// Get default month
|
287 |
$expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
|
288 |
-
$firstsave
|
289 |
|
290 |
-
$default
|
291 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post->post_type ) );
|
292 |
if ( empty( $expirationdatets ) ) {
|
293 |
$default_expiry = PostExpirator_Facade::get_default_expiry( $post->post_type );
|
294 |
|
295 |
-
$defaultmonth
|
296 |
-
$defaultday
|
297 |
-
$defaulthour
|
298 |
-
$defaultyear
|
299 |
-
$defaultminute
|
300 |
|
301 |
-
$enabled
|
302 |
$categories = get_option( 'expirationdateCategoryDefaults' );
|
303 |
|
304 |
if ( isset( $defaults['expireType'] ) ) {
|
@@ -310,12 +365,12 @@ function postexpirator_meta_box( $post ) {
|
|
310 |
$enabled = ' checked="checked"';
|
311 |
}
|
312 |
} else {
|
313 |
-
$defaultmonth
|
314 |
-
$defaultday
|
315 |
-
$defaultyear
|
316 |
-
$defaulthour
|
317 |
-
$defaultminute
|
318 |
-
$enabled
|
319 |
|
320 |
$attributes = PostExpirator_Facade::get_expire_principles( $post->ID );
|
321 |
$expireType = $attributes['expireType'];
|
@@ -324,16 +379,16 @@ function postexpirator_meta_box( $post ) {
|
|
324 |
|
325 |
PostExpirator_Display::getInstance()->render_template(
|
326 |
'classic-metabox', array(
|
327 |
-
'post'
|
328 |
-
'enabled'
|
329 |
-
'default'
|
330 |
-
'defaultmonth'
|
331 |
-
'defaultday'
|
332 |
-
'defaulthour'
|
333 |
-
'defaultyear'
|
334 |
'defaultminute' => $defaultminute,
|
335 |
-
'categories'
|
336 |
-
'expireType'
|
337 |
)
|
338 |
);
|
339 |
}
|
@@ -346,36 +401,42 @@ function postexpirator_meta_box( $post ) {
|
|
346 |
* @access private
|
347 |
*/
|
348 |
function postexpirator_js_admin_header() {
|
349 |
-
|
350 |
-
<script type="text/javascript">
|
351 |
-
//<![CDATA[
|
352 |
-
(function($){
|
353 |
-
$(document).ready(function(){
|
354 |
-
init();
|
355 |
-
});
|
356 |
-
|
357 |
-
function init(){
|
358 |
-
$('#enable-expirationdate').on('click', function(e){
|
359 |
-
if($(this).is(':checked')){
|
360 |
-
$('.pe-classic-fields').show();
|
361 |
-
}else{
|
362 |
-
$('.pe-classic-fields').hide();
|
363 |
-
}
|
364 |
-
});
|
365 |
|
366 |
-
|
367 |
-
|
368 |
-
$('#expired-category-selection').show();
|
369 |
-
}else{
|
370 |
-
$('#expired-category-selection').hide();
|
371 |
-
}
|
372 |
-
});
|
373 |
}
|
374 |
-
|
375 |
-
|
376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
<?php
|
378 |
}
|
|
|
379 |
add_action( 'admin_head', 'postexpirator_js_admin_header' );
|
380 |
|
381 |
/**
|
@@ -412,11 +473,17 @@ function postexpirator_update_post_meta( $id ) {
|
|
412 |
return;
|
413 |
}
|
414 |
|
|
|
|
|
|
|
|
|
|
|
|
|
415 |
// we want to make sure we don't fire the save_post action when we are inside the block editor
|
416 |
// but this should not stop quick/bulk edit
|
417 |
if ( PostExpirator_Util::is_gutenberg_active() && PostExpirator_Facade::show_gutenberg_metabox()
|
418 |
-
|
419 |
-
|
420 |
) {
|
421 |
return;
|
422 |
}
|
@@ -424,17 +491,17 @@ function postexpirator_update_post_meta( $id ) {
|
|
424 |
if ( isset( $_POST['enable-expirationdate'] ) ) {
|
425 |
$default = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
|
426 |
if ( $default === 'publish' ) {
|
427 |
-
$month
|
428 |
-
$day
|
429 |
-
$year
|
430 |
-
$hour
|
431 |
-
$minute
|
432 |
} else {
|
433 |
-
$month
|
434 |
-
$day
|
435 |
-
$year
|
436 |
-
$hour
|
437 |
-
$minute
|
438 |
|
439 |
if ( empty( $day ) ) {
|
440 |
$day = date( 'd' );
|
@@ -453,7 +520,11 @@ function postexpirator_update_post_meta( $id ) {
|
|
453 |
$opts = PostExpirator_Facade::get_expire_principles( $id );
|
454 |
if ( isset( $_POST['expirationdate_expiretype'] ) ) {
|
455 |
$opts['expireType'] = $_POST['expirationdate_expiretype'];
|
456 |
-
if ( in_array( $opts['expireType'], array(
|
|
|
|
|
|
|
|
|
457 |
$opts['category'] = $_POST['expirationdate_category'];
|
458 |
}
|
459 |
PostExpirator_Facade::set_expire_principles( $id, $opts );
|
@@ -464,12 +535,12 @@ function postexpirator_update_post_meta( $id ) {
|
|
464 |
|
465 |
// Schedule/Update Expiration
|
466 |
$opts['expireType'] = $_POST['expirationdate_expiretype'];
|
467 |
-
$opts['id']
|
468 |
|
469 |
if ( $opts['expireType'] === 'category' || $opts['expireType'] === 'category-add' || $opts['expireType'] === 'category-remove' ) {
|
470 |
if ( isset( $category ) && ! empty( $category ) ) {
|
471 |
if ( ! empty( $category ) ) {
|
472 |
-
$opts['category']
|
473 |
$opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical'];
|
474 |
}
|
475 |
}
|
@@ -480,6 +551,7 @@ function postexpirator_update_post_meta( $id ) {
|
|
480 |
postexpirator_unschedule_event( $id );
|
481 |
}
|
482 |
}
|
|
|
483 |
add_action( 'save_post', 'postexpirator_update_post_meta' );
|
484 |
|
485 |
/**
|
@@ -496,16 +568,16 @@ function postexpirator_schedule_event( $id, $ts, $opts ) {
|
|
496 |
|
497 |
do_action( 'postexpiratior_schedule', $id, $ts, $opts ); // allow custom actions
|
498 |
|
499 |
-
if ( wp_next_scheduled( 'postExpiratorExpire', array($id) ) !== false ) {
|
500 |
-
$error = wp_clear_scheduled_hook( 'postExpiratorExpire', array($id), true ); // Remove any existing hooks
|
501 |
if ( POSTEXPIRATOR_DEBUG ) {
|
502 |
-
$debug->save( array('message' => $id . ' -> EXISTING FOUND - UNSCHEDULED - ' . ( is_wp_error( $error ) ? $error->get_error_message() : 'no error' )) );
|
503 |
}
|
504 |
}
|
505 |
|
506 |
-
$error = wp_schedule_single_event( $ts, 'postExpiratorExpire', array($id), true );
|
507 |
if ( POSTEXPIRATOR_DEBUG ) {
|
508 |
-
$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' ) ) );
|
509 |
}
|
510 |
|
511 |
// Update Post Meta
|
@@ -535,10 +607,10 @@ function postexpirator_unschedule_event( $id ) {
|
|
535 |
delete_post_meta( $id, '_expiration-date-taxonomy' );
|
536 |
|
537 |
// Delete Scheduled Expiration
|
538 |
-
if ( wp_next_scheduled( 'postExpiratorExpire', array($id) ) !== false ) {
|
539 |
-
wp_clear_scheduled_hook( 'postExpiratorExpire', array($id) ); // Remove any existing hooks
|
540 |
if ( POSTEXPIRATOR_DEBUG ) {
|
541 |
-
$debug->save( array('message' => $id . ' -> UNSCHEDULED') );
|
542 |
}
|
543 |
}
|
544 |
delete_post_meta( $id, '_expiration-date-status' );
|
@@ -558,24 +630,26 @@ function postexpirator_expire_post( $id ) {
|
|
558 |
|
559 |
if ( empty( $id ) ) {
|
560 |
if ( POSTEXPIRATOR_DEBUG ) {
|
561 |
-
$debug->save( array('message' => 'No Post ID found - exiting') );
|
562 |
}
|
|
|
563 |
return false;
|
564 |
}
|
565 |
|
566 |
if ( is_null( get_post( $id ) ) ) {
|
567 |
if ( POSTEXPIRATOR_DEBUG ) {
|
568 |
-
$debug->save( array('message' => $id . ' -> Post does not exist - exiting') );
|
569 |
}
|
|
|
570 |
return false;
|
571 |
}
|
572 |
|
573 |
-
$posttype
|
574 |
$posttitle = get_the_title( $id );
|
575 |
-
$postlink
|
576 |
|
577 |
$postoptions = PostExpirator_Facade::get_expire_principles( $id );
|
578 |
-
$expireType
|
579 |
|
580 |
if ( isset( $postoptions['expireType'] ) ) {
|
581 |
$expireType = $postoptions['expireType'];
|
@@ -610,147 +684,147 @@ function postexpirator_expire_post( $id ) {
|
|
610 |
|
611 |
// Do Work
|
612 |
if ( $expireType === 'draft' ) {
|
613 |
-
if ( wp_update_post( array('ID' => $id, 'post_status' => 'draft') ) === 0 ) {
|
614 |
if ( POSTEXPIRATOR_DEBUG ) {
|
615 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
616 |
}
|
617 |
} else {
|
618 |
$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 ) );
|
619 |
if ( POSTEXPIRATOR_DEBUG ) {
|
620 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
621 |
}
|
622 |
}
|
623 |
} elseif ( $expireType === 'private' ) {
|
624 |
-
if ( wp_update_post( array('ID' => $id, 'post_status' => 'private') ) === 0 ) {
|
625 |
if ( POSTEXPIRATOR_DEBUG ) {
|
626 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
627 |
}
|
628 |
} else {
|
629 |
$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 ) );
|
630 |
if ( POSTEXPIRATOR_DEBUG ) {
|
631 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
632 |
}
|
633 |
}
|
634 |
} elseif ( $expireType === 'delete' ) {
|
635 |
if ( wp_delete_post( $id ) === false ) {
|
636 |
if ( POSTEXPIRATOR_DEBUG ) {
|
637 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
638 |
}
|
639 |
} else {
|
640 |
$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 ) );
|
641 |
if ( POSTEXPIRATOR_DEBUG ) {
|
642 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
643 |
}
|
644 |
}
|
645 |
} elseif ( $expireType === 'trash' ) {
|
646 |
if ( wp_trash_post( $id ) === false ) {
|
647 |
if ( POSTEXPIRATOR_DEBUG ) {
|
648 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
649 |
}
|
650 |
} else {
|
651 |
$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 ) );
|
652 |
if ( POSTEXPIRATOR_DEBUG ) {
|
653 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
654 |
}
|
655 |
}
|
656 |
} elseif ( $expireType === 'stick' ) {
|
657 |
if ( stick_post( $id ) === false ) {
|
658 |
if ( POSTEXPIRATOR_DEBUG ) {
|
659 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
660 |
}
|
661 |
} else {
|
662 |
$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' );
|
663 |
if ( POSTEXPIRATOR_DEBUG ) {
|
664 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
665 |
}
|
666 |
}
|
667 |
} elseif ( $expireType === 'unstick' ) {
|
668 |
if ( unstick_post( $id ) === false ) {
|
669 |
if ( POSTEXPIRATOR_DEBUG ) {
|
670 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
671 |
}
|
672 |
} else {
|
673 |
$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' );
|
674 |
if ( POSTEXPIRATOR_DEBUG ) {
|
675 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
676 |
}
|
677 |
}
|
678 |
} elseif ( $expireType === 'category' ) {
|
679 |
if ( ! empty( $category ) ) {
|
680 |
if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
|
681 |
-
if ( wp_update_post( array('ID' => $id, 'post_category' => $category) ) === 0 ) {
|
682 |
if ( POSTEXPIRATOR_DEBUG ) {
|
683 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
684 |
}
|
685 |
} else {
|
686 |
$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 ) ) );
|
687 |
if ( POSTEXPIRATOR_DEBUG ) {
|
688 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
689 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES REPLACED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
690 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
691 |
}
|
692 |
}
|
693 |
} else {
|
694 |
$terms = array_map( 'intval', $category );
|
695 |
if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, false ) ) ) {
|
696 |
if ( POSTEXPIRATOR_DEBUG ) {
|
697 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
698 |
}
|
699 |
} else {
|
700 |
$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 ) ) );
|
701 |
if ( POSTEXPIRATOR_DEBUG ) {
|
702 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
703 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES REPLACED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
704 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
705 |
}
|
706 |
}
|
707 |
}
|
708 |
} else {
|
709 |
if ( POSTEXPIRATOR_DEBUG ) {
|
710 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
711 |
}
|
712 |
}
|
713 |
} elseif ( $expireType === 'category-add' ) {
|
714 |
if ( ! empty( $category ) ) {
|
715 |
if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
|
716 |
-
$cats
|
717 |
$merged = array_merge( $cats, $category );
|
718 |
-
if ( wp_update_post( array('ID' => $id, 'post_category' => $merged) ) === 0 ) {
|
719 |
if ( POSTEXPIRATOR_DEBUG ) {
|
720 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
721 |
}
|
722 |
} else {
|
723 |
$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 ) ) );
|
724 |
if ( POSTEXPIRATOR_DEBUG ) {
|
725 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
726 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES ADDED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
727 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $merged ), true )) );
|
728 |
}
|
729 |
}
|
730 |
} else {
|
731 |
$terms = array_map( 'intval', $category );
|
732 |
if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, true ) ) ) {
|
733 |
if ( POSTEXPIRATOR_DEBUG ) {
|
734 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
735 |
}
|
736 |
} else {
|
737 |
$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 ) ) );
|
738 |
if ( POSTEXPIRATOR_DEBUG ) {
|
739 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
740 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES ADDED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
741 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
742 |
}
|
743 |
}
|
744 |
}
|
745 |
} else {
|
746 |
if ( POSTEXPIRATOR_DEBUG ) {
|
747 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
748 |
}
|
749 |
}
|
750 |
} elseif ( $expireType === 'category-remove' ) {
|
751 |
if ( ! empty( $category ) ) {
|
752 |
if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
|
753 |
-
$cats
|
754 |
$merged = array();
|
755 |
foreach ( $cats as $cat ) {
|
756 |
if ( ! in_array( $cat, $category, false ) ) {
|
@@ -758,20 +832,20 @@ function postexpirator_expire_post( $id ) {
|
|
758 |
}
|
759 |
}
|
760 |
|
761 |
-
if ( wp_update_post( array('ID' => $id, 'post_category' => $merged) ) === 0 ) {
|
762 |
if ( POSTEXPIRATOR_DEBUG ) {
|
763 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
764 |
}
|
765 |
} else {
|
766 |
$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 ) ) );
|
767 |
if ( POSTEXPIRATOR_DEBUG ) {
|
768 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
769 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES REMOVED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
770 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $merged ), true )) );
|
771 |
}
|
772 |
}
|
773 |
} else {
|
774 |
-
$terms
|
775 |
$merged = array();
|
776 |
foreach ( $terms as $term ) {
|
777 |
if ( ! in_array( $term, $category, false ) ) {
|
@@ -781,20 +855,20 @@ function postexpirator_expire_post( $id ) {
|
|
781 |
$terms = array_map( 'intval', $merged );
|
782 |
if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, false ) ) ) {
|
783 |
if ( POSTEXPIRATOR_DEBUG ) {
|
784 |
-
$debug->save( array('message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
785 |
}
|
786 |
} else {
|
787 |
$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 ) ) );
|
788 |
if ( POSTEXPIRATOR_DEBUG ) {
|
789 |
-
$debug->save( array('message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
790 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES REMOVED ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
791 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true )) );
|
792 |
}
|
793 |
}
|
794 |
}
|
795 |
} else {
|
796 |
if ( POSTEXPIRATOR_DEBUG ) {
|
797 |
-
$debug->save( array('message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true )) );
|
798 |
}
|
799 |
}
|
800 |
}
|
@@ -803,7 +877,7 @@ function postexpirator_expire_post( $id ) {
|
|
803 |
$emailenabled = get_option( 'expirationdateEmailNotification', POSTEXPIRATOR_EMAILNOTIFICATION );
|
804 |
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
805 |
if ( $emailenabled == 1 && isset( $emailBody ) ) {
|
806 |
-
$subj
|
807 |
$emailBody = str_replace( '##POSTTITLE##', $posttitle, $emailBody );
|
808 |
$emailBody = str_replace( '##POSTLINK##', $postlink, $emailBody );
|
809 |
$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 );
|
@@ -829,7 +903,7 @@ function postexpirator_expire_post( $id ) {
|
|
829 |
}
|
830 |
|
831 |
// Get Post Type Notification Emails
|
832 |
-
|
833 |
if ( isset( $defaults['emailnotification'] ) && ! empty( $defaults['emailnotification'] ) ) {
|
834 |
$vals = explode( ',', $defaults['emailnotification'] );
|
835 |
foreach ( $vals as $val ) {
|
@@ -841,17 +915,18 @@ function postexpirator_expire_post( $id ) {
|
|
841 |
foreach ( $emails as $email ) {
|
842 |
if ( wp_mail( $email, sprintf( __( '[%1$s] %2$s' ), get_option( 'blogname' ), $subj ), $emailBody ) ) {
|
843 |
if ( POSTEXPIRATOR_DEBUG ) {
|
844 |
-
$debug->save( array('message' => $id . ' -> EXPIRATION EMAIL SENT (' . $email . ')') );
|
845 |
}
|
846 |
} else {
|
847 |
if ( POSTEXPIRATOR_DEBUG ) {
|
848 |
-
$debug->save( array('message' => $id . ' -> EXPIRATION EMAIL FAILED (' . $email . ')') );
|
849 |
}
|
850 |
}
|
851 |
}
|
852 |
}
|
853 |
|
854 |
}
|
|
|
855 |
add_action( 'postExpiratorExpire', 'postexpirator_expire_post' );
|
856 |
|
857 |
/**
|
@@ -866,6 +941,7 @@ function _postexpirator_get_cat_names( $cats ) {
|
|
866 |
foreach ( $cats as $cat ) {
|
867 |
$out[ $cat ] = get_the_category_by_id( $cat );
|
868 |
}
|
|
|
869 |
return $out;
|
870 |
}
|
871 |
|
@@ -950,7 +1026,7 @@ function postexpirator_menu_debug() {
|
|
950 |
function postexpirator_shortcode( $atts ) {
|
951 |
global $post;
|
952 |
|
953 |
-
|
954 |
if ( empty( $expirationdatets ) ) {
|
955 |
return false;
|
956 |
}
|
@@ -962,8 +1038,8 @@ function postexpirator_shortcode( $atts ) {
|
|
962 |
array(
|
963 |
'dateformat' => get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT ),
|
964 |
'timeformat' => get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT ),
|
965 |
-
'type'
|
966 |
-
'tz'
|
967 |
), $atts
|
968 |
)
|
969 |
);
|
@@ -988,6 +1064,7 @@ function postexpirator_shortcode( $atts ) {
|
|
988 |
|
989 |
return date_i18n( $format, $expirationdatets + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
|
990 |
}
|
|
|
991 |
add_shortcode( 'postexpirator', 'postexpirator_shortcode' );
|
992 |
|
993 |
/**
|
@@ -1008,17 +1085,17 @@ function postexpirator_add_footer( $text ) {
|
|
1008 |
return $text;
|
1009 |
}
|
1010 |
|
1011 |
-
|
1012 |
if ( ! is_numeric( $expirationdatets ) ) {
|
1013 |
return $text;
|
1014 |
}
|
1015 |
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
|
1021 |
-
$search
|
1022 |
'EXPIRATIONFULL',
|
1023 |
'EXPIRATIONDATE',
|
1024 |
'EXPIRATIONTIME',
|
@@ -1030,8 +1107,10 @@ function postexpirator_add_footer( $text ) {
|
|
1030 |
);
|
1031 |
|
1032 |
$add_to_footer = '<p style="' . $expirationdateFooterStyle . '">' . str_replace( $search, $replace, $expirationdateFooterContents ) . '</p>';
|
|
|
1033 |
return $text . $add_to_footer;
|
1034 |
}
|
|
|
1035 |
add_action( 'the_content', 'postexpirator_add_footer', 0 );
|
1036 |
|
1037 |
/**
|
@@ -1048,12 +1127,14 @@ function postexpirator_debug() {
|
|
1048 |
if ( ! defined( 'POSTEXPIRATOR_DEBUG' ) ) {
|
1049 |
define( 'POSTEXPIRATOR_DEBUG', 1 );
|
1050 |
}
|
1051 |
-
|
1052 |
-
|
|
|
1053 |
} else {
|
1054 |
if ( ! defined( 'POSTEXPIRATOR_DEBUG' ) ) {
|
1055 |
define( 'POSTEXPIRATOR_DEBUG', 0 );
|
1056 |
}
|
|
|
1057 |
return false;
|
1058 |
}
|
1059 |
}
|
@@ -1078,6 +1159,7 @@ function postexpirator_css( $screen_id ) {
|
|
1078 |
break;
|
1079 |
}
|
1080 |
}
|
|
|
1081 |
add_action( 'admin_enqueue_scripts', 'postexpirator_css', 10, 1 );
|
1082 |
|
1083 |
/**
|
@@ -1095,34 +1177,34 @@ function postexpirator_upgrade() {
|
|
1095 |
postexpirator_activate();
|
1096 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1097 |
} else {
|
1098 |
-
if ( version_compare( $version, '1.6.1' ) === -1 ) {
|
1099 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1100 |
update_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
|
1101 |
}
|
1102 |
|
1103 |
-
if ( version_compare( $version, '1.6.2' ) === -1 ) {
|
1104 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1105 |
}
|
1106 |
|
1107 |
-
if ( version_compare( $version, '2.0.0-rc1' ) === -1 ) {
|
1108 |
global $wpdb;
|
1109 |
|
1110 |
// Schedule Events/Migrate Config
|
1111 |
$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() ) );
|
1112 |
foreach ( $results as $result ) {
|
1113 |
-
wp_schedule_single_event( $result->meta_value, 'postExpiratorExpire', array($result->post_id) );
|
1114 |
-
$opts
|
1115 |
$opts['id'] = $result->post_id;
|
1116 |
-
$posttype
|
1117 |
if ( $posttype === 'page' ) {
|
1118 |
-
|
1119 |
} else {
|
1120 |
-
|
1121 |
}
|
1122 |
|
1123 |
$cat = get_post_meta( $result->post_id, '_expiration-date-category', true );
|
1124 |
if ( ( isset( $cat ) && ! empty( $cat ) ) ) {
|
1125 |
-
$opts['category']
|
1126 |
$opts['expireType'] = 'category';
|
1127 |
}
|
1128 |
|
@@ -1137,10 +1219,10 @@ function postexpirator_upgrade() {
|
|
1137 |
$pagedefault = get_option( 'expirationdateExpiredPageStatus' );
|
1138 |
$postdefault = get_option( 'expirationdateExpiredPostStatus' );
|
1139 |
if ( $pagedefault ) {
|
1140 |
-
update_option( 'expirationdateDefaultsPage', array('expireType' => $pagedefault) );
|
1141 |
}
|
1142 |
if ( $postdefault ) {
|
1143 |
-
update_option( 'expirationdateDefaultsPost', array('expireType' => $postdefault) );
|
1144 |
}
|
1145 |
|
1146 |
delete_option( 'expirationdateCronSchedule' );
|
@@ -1150,11 +1232,11 @@ function postexpirator_upgrade() {
|
|
1150 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1151 |
}
|
1152 |
|
1153 |
-
if ( version_compare( $version, '2.0.1' ) === -1 ) {
|
1154 |
// Forgot to do this in 2.0.0
|
1155 |
if ( is_multisite() ) {
|
1156 |
global $current_blog;
|
1157 |
-
|
1158 |
} else {
|
1159 |
wp_clear_scheduled_hook( 'expirationdate_delete' );
|
1160 |
}
|
@@ -1163,9 +1245,9 @@ function postexpirator_upgrade() {
|
|
1163 |
}
|
1164 |
|
1165 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1166 |
-
|
1167 |
}
|
1168 |
}
|
|
|
1169 |
add_action( 'admin_init', 'postexpirator_upgrade' );
|
1170 |
|
1171 |
/**
|
@@ -1239,6 +1321,7 @@ function expirationdate_deactivate() {
|
|
1239 |
$debug = new PostExpiratorDebug();
|
1240 |
$debug->removeDbTable();
|
1241 |
}
|
|
|
1242 |
register_deactivation_hook( __FILE__, 'expirationdate_deactivate' );
|
1243 |
|
1244 |
/**
|
@@ -1262,7 +1345,7 @@ class Walker_PostExpirator_Category_Checklist extends Walker {
|
|
1262 |
*
|
1263 |
* @var array
|
1264 |
*/
|
1265 |
-
var $db_fields = array
|
1266 |
|
1267 |
/**
|
1268 |
* The disabled attribute.
|
@@ -1285,8 +1368,8 @@ class Walker_PostExpirator_Category_Checklist extends Walker {
|
|
1285 |
* class methods. This method is called at the start of the output list.
|
1286 |
*
|
1287 |
* @param string $output Used to append additional content (passed by reference).
|
1288 |
-
* @param int
|
1289 |
-
* @param array
|
1290 |
*/
|
1291 |
function start_lvl( &$output, $depth = 0, $args = array() ) {
|
1292 |
$indent = str_repeat( "\t", $depth );
|
@@ -1300,8 +1383,8 @@ class Walker_PostExpirator_Category_Checklist extends Walker {
|
|
1300 |
* class methods. This method finishes the list at the end of output of the elements.
|
1301 |
*
|
1302 |
* @param string $output Used to append additional content (passed by reference).
|
1303 |
-
* @param int
|
1304 |
-
* @param array
|
1305 |
*/
|
1306 |
function end_lvl( &$output, $depth = 0, $args = array() ) {
|
1307 |
$indent = str_repeat( "\t", $depth );
|
@@ -1314,11 +1397,11 @@ class Walker_PostExpirator_Category_Checklist extends Walker {
|
|
1314 |
* The $args parameter holds additional values that may be used with the child
|
1315 |
* class methods. Includes the element output also.
|
1316 |
*
|
1317 |
-
* @param string $output
|
1318 |
-
* @param object $category
|
1319 |
-
* @param int
|
1320 |
-
* @param array
|
1321 |
-
* @param int
|
1322 |
*/
|
1323 |
function start_el( &$output, $category, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
1324 |
// @TODO remove extract
|
@@ -1330,7 +1413,7 @@ class Walker_PostExpirator_Category_Checklist extends Walker {
|
|
1330 |
|
1331 |
$name = 'expirationdate_category';
|
1332 |
|
1333 |
-
$class
|
1334 |
$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>';
|
1335 |
}
|
1336 |
|
@@ -1341,8 +1424,8 @@ class Walker_PostExpirator_Category_Checklist extends Walker {
|
|
1341 |
*
|
1342 |
* @param string $output Used to append additional content (passed by reference).
|
1343 |
* @param object $category The data object.
|
1344 |
-
* @param int
|
1345 |
-
* @param array
|
1346 |
*/
|
1347 |
function end_el( &$output, $category, $depth = 0, $args = array() ) {
|
1348 |
$output .= "</li>\n";
|
@@ -1396,7 +1479,7 @@ function _postexpirator_taxonomy( $opts ) {
|
|
1396 |
}
|
1397 |
|
1398 |
$taxonomies = get_object_taxonomies( $type, 'object' );
|
1399 |
-
$taxonomies = wp_filter_object_list( $taxonomies, array('hierarchical' => true) );
|
1400 |
|
1401 |
if ( empty( $taxonomies ) ) {
|
1402 |
$disabled = true;
|
@@ -1415,6 +1498,7 @@ function _postexpirator_taxonomy( $opts ) {
|
|
1415 |
} else {
|
1416 |
$rv[] = __( 'No taxonomies found', 'post-expirator' );
|
1417 |
}
|
|
|
1418 |
return implode( "<br/>\n", $rv );
|
1419 |
}
|
1420 |
|
@@ -1427,16 +1511,20 @@ function _postexpirator_taxonomy( $opts ) {
|
|
1427 |
*/
|
1428 |
function postexpirator_quickedit_javascript() {
|
1429 |
// if using code as plugin
|
1430 |
-
wp_enqueue_script( 'postexpirator-edit', POSTEXPIRATOR_BASEURL . '/assets/js/admin-edit.js', array(
|
|
|
|
|
|
|
1431 |
wp_localize_script(
|
1432 |
'postexpirator-edit', 'config', array(
|
1433 |
'ajax' => array(
|
1434 |
-
'nonce'
|
1435 |
'bulk_edit' => 'manage_wp_posts_using_bulk_quick_save_bulk_edit',
|
1436 |
),
|
1437 |
)
|
1438 |
);
|
1439 |
}
|
|
|
1440 |
add_action( 'admin_print_scripts-edit.php', 'postexpirator_quickedit_javascript' );
|
1441 |
|
1442 |
/**
|
@@ -1449,6 +1537,12 @@ add_action( 'admin_print_scripts-edit.php', 'postexpirator_quickedit_javascript'
|
|
1449 |
function postexpirator_date_save_bulk_edit() {
|
1450 |
check_ajax_referer( POSTEXPIRATOR_SLUG, 'nonce' );
|
1451 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1452 |
// we need the post IDs
|
1453 |
$post_ids = ( isset( $_POST['post_ids'] ) && ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : null;
|
1454 |
|
@@ -1462,11 +1556,11 @@ function postexpirator_date_save_bulk_edit() {
|
|
1462 |
return;
|
1463 |
}
|
1464 |
|
1465 |
-
$month
|
1466 |
-
$day
|
1467 |
-
$year
|
1468 |
-
$hour
|
1469 |
-
$minute
|
1470 |
|
1471 |
// default to current date and/or year if not provided by user.
|
1472 |
if ( empty( $day ) ) {
|
@@ -1483,7 +1577,7 @@ function postexpirator_date_save_bulk_edit() {
|
|
1483 |
}
|
1484 |
|
1485 |
foreach ( $post_ids as $post_id ) {
|
1486 |
-
$ed
|
1487 |
$update_expiry = false;
|
1488 |
|
1489 |
switch ( $status ) {
|
@@ -1503,7 +1597,7 @@ function postexpirator_date_save_bulk_edit() {
|
|
1503 |
}
|
1504 |
|
1505 |
if ( $update_expiry ) {
|
1506 |
-
$opts
|
1507 |
$opts['expireType'] = $_POST['expirationdate_expiretype'];
|
1508 |
|
1509 |
if ( in_array( $opts['expireType'], array( 'category', 'category-add', 'category-remove' ), true ) ) {
|
@@ -1517,6 +1611,7 @@ function postexpirator_date_save_bulk_edit() {
|
|
1517 |
}
|
1518 |
}
|
1519 |
}
|
|
|
1520 |
add_action( 'wp_ajax_manage_wp_posts_using_bulk_quick_save_bulk_edit', 'postexpirator_date_save_bulk_edit' );
|
1521 |
|
1522 |
/**
|
@@ -1526,16 +1621,19 @@ function postexpirator_autoload( $class ) {
|
|
1526 |
$namespaces = array( 'PostExpirator' );
|
1527 |
foreach ( $namespaces as $namespace ) {
|
1528 |
if ( substr( $class, 0, strlen( $namespace ) ) === $namespace ) {
|
1529 |
-
$class
|
1530 |
$filename = plugin_dir_path( __FILE__ ) . 'classes/' . sprintf( '%s.class.php', $class );
|
1531 |
if ( is_readable( $filename ) ) {
|
1532 |
require_once $filename;
|
|
|
1533 |
return true;
|
1534 |
}
|
1535 |
}
|
1536 |
}
|
|
|
1537 |
return false;
|
1538 |
}
|
|
|
1539 |
spl_autoload_register( 'postexpirator_autoload' );
|
1540 |
|
1541 |
/**
|
@@ -1544,5 +1642,6 @@ spl_autoload_register( 'postexpirator_autoload' );
|
|
1544 |
function postexpirator_launch() {
|
1545 |
PostExpirator_Facade::getInstance();
|
1546 |
}
|
|
|
1547 |
postexpirator_launch();
|
1548 |
|
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: PublishPress
|
7 |
+
Version: 2.6.0
|
8 |
Author URI: http://publishpress.com
|
9 |
Text Domain: post-expirator
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
// Default Values
|
14 |
+
define( 'POSTEXPIRATOR_VERSION', '2.6.0' );
|
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' ) );
|
41 |
if ( $file === $this_plugin ) {
|
42 |
$links[] = '<a href="options-general.php?page=post-expirator">' . __( 'Settings', 'post-expirator' ) . '</a>';
|
43 |
}
|
44 |
+
|
45 |
return $links;
|
46 |
}
|
47 |
+
|
48 |
add_filter( 'plugin_action_links', 'postexpirator_plugin_action_links', 10, 2 );
|
49 |
|
50 |
/**
|
58 |
$plugin_dir = basename( dirname( __FILE__ ) );
|
59 |
load_plugin_textdomain( 'post-expirator', null, $plugin_dir . '/languages/' );
|
60 |
}
|
61 |
+
|
62 |
add_action( 'plugins_loaded', 'postexpirator_init' );
|
63 |
|
64 |
/**
|
71 |
function postexpirator_add_column( $columns, $type ) {
|
72 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
|
73 |
// if settings are not configured, show the metabox by default only for posts and pages
|
74 |
+
if ( ( ! isset( $defaults['activeMetaBox'] ) && in_array( $type, array(
|
75 |
+
'post',
|
76 |
+
'page'
|
77 |
+
), true ) ) || ( is_array( $defaults ) && $defaults['activeMetaBox'] === 'active' ) ) {
|
78 |
$columns['expirationdate'] = __( 'Expires', 'post-expirator' );
|
79 |
}
|
80 |
+
|
81 |
return $columns;
|
82 |
}
|
83 |
+
|
84 |
add_filter( 'manage_posts_columns', 'postexpirator_add_column', 10, 2 );
|
85 |
|
86 |
/**
|
96 |
add_filter( 'manage_edit-' . $post_type . '_sortable_columns', 'postexpirator_sortable_column' );
|
97 |
}
|
98 |
}
|
99 |
+
|
100 |
add_action( 'init', 'postexpirator_manage_sortable_columns', 100 );
|
101 |
|
102 |
/**
|
108 |
*/
|
109 |
function postexpirator_sortable_column( $columns ) {
|
110 |
$columns['expirationdate'] = 'expirationdate';
|
111 |
+
|
112 |
return $columns;
|
113 |
}
|
114 |
|
129 |
if ( 'expirationdate' === $orderby ) {
|
130 |
$query->set(
|
131 |
'meta_query', array(
|
132 |
+
'relation' => 'OR',
|
133 |
array(
|
134 |
+
'key' => '_expiration-date',
|
135 |
+
'compare' => 'EXISTS',
|
136 |
),
|
137 |
array(
|
138 |
+
'key' => '_expiration-date',
|
139 |
+
'compare' => 'NOT EXISTS',
|
140 |
+
'value' => '',
|
141 |
),
|
142 |
)
|
143 |
);
|
144 |
+
$query->set( 'orderby', 'meta_value_num' );
|
145 |
}
|
146 |
}
|
147 |
+
|
148 |
add_action( 'pre_get_posts', 'postexpirator_orderby' );
|
149 |
|
150 |
/**
|
159 |
if ( ! isset( $defaults['activeMetaBox'] ) || $defaults['activeMetaBox'] === 'active' ) {
|
160 |
$columns['expirationdate'] = __( 'Expires', 'post-expirator' );
|
161 |
}
|
162 |
+
|
163 |
return $columns;
|
164 |
}
|
165 |
+
|
166 |
add_filter( 'manage_pages_columns', 'postexpirator_add_column_page' );
|
167 |
|
168 |
/**
|
182 |
// get the attributes that quick edit functionality requires
|
183 |
// and save it as a JSON encoded HTML attribute
|
184 |
$attributes = PostExpirator_Facade::get_expire_principles( $post->ID );
|
185 |
+
PostExpirator_Display::getInstance()->render_template( 'expire-column', array(
|
186 |
+
'id' => $post->ID,
|
187 |
+
'post_type' => $post->post_type,
|
188 |
+
'attributes' => $attributes
|
189 |
+
) );
|
190 |
}
|
191 |
+
|
192 |
add_action( 'manage_posts_custom_column', 'postexpirator_show_value' );
|
193 |
add_action( 'manage_pages_custom_column', 'postexpirator_show_value' );
|
194 |
|
205 |
return;
|
206 |
}
|
207 |
|
208 |
+
$facade = PostExpirator_Facade::getInstance();
|
209 |
+
|
210 |
+
if ( ! $facade->current_user_can_expire_posts() ) {
|
211 |
+
return;
|
212 |
+
}
|
213 |
+
|
214 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post_type ) );
|
215 |
$taxonomy = isset( $defaults['taxonomy'] ) ? $defaults['taxonomy'] : '';
|
216 |
+
$label = '';
|
217 |
|
218 |
// if settings have not been configured and this is the default post type
|
219 |
if ( empty( $taxonomy ) && 'post' === $post_type ) {
|
222 |
|
223 |
if ( ! empty( $taxonomy ) ) {
|
224 |
$tax_object = get_taxonomy( $taxonomy );
|
225 |
+
$label = $tax_object ? $tax_object->label : '';
|
226 |
}
|
227 |
|
228 |
+
PostExpirator_Display::getInstance()->render_template( 'quick-edit', array(
|
229 |
+
'post_type' => $post_type,
|
230 |
+
'taxonomy' => $taxonomy,
|
231 |
+
'tax_label' => $label
|
232 |
+
) );
|
233 |
}
|
234 |
+
|
235 |
add_action( 'quick_edit_custom_box', 'postexpirator_quickedit', 10, 2 );
|
236 |
|
237 |
/**
|
246 |
return;
|
247 |
}
|
248 |
|
249 |
+
$facade = PostExpirator_Facade::getInstance();
|
250 |
+
|
251 |
+
if ( ! $facade->current_user_can_expire_posts() ) {
|
252 |
+
return;
|
253 |
+
}
|
254 |
+
|
255 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post_type ) );
|
256 |
$taxonomy = isset( $defaults['taxonomy'] ) ? $defaults['taxonomy'] : '';
|
257 |
+
$label = '';
|
258 |
|
259 |
// if settings have not been configured and this is the default post type
|
260 |
if ( empty( $taxonomy ) && 'post' === $post_type ) {
|
263 |
|
264 |
if ( ! empty( $taxonomy ) ) {
|
265 |
$tax_object = get_taxonomy( $taxonomy );
|
266 |
+
$label = $tax_object ? $tax_object->label : '';
|
267 |
}
|
268 |
|
269 |
+
PostExpirator_Display::getInstance()->render_template( 'bulk-edit', array(
|
270 |
+
'post_type' => $post_type,
|
271 |
+
'taxonomy' => $taxonomy,
|
272 |
+
'tax_label' => $label
|
273 |
+
) );
|
274 |
}
|
275 |
+
|
276 |
add_action( 'bulk_edit_custom_box', 'postexpirator_bulkedit', 10, 2 );
|
277 |
|
278 |
/**
|
284 |
*/
|
285 |
function postexpirator_get_post_types() {
|
286 |
$post_types = get_post_types( array( 'public' => true ) );
|
287 |
+
$post_types = array_merge( $post_types, get_post_types( array(
|
288 |
+
'public' => false,
|
289 |
+
'show_ui' => true,
|
290 |
+
'_builtin' => false
|
291 |
+
) ) );
|
292 |
|
293 |
// in case some post types should not be supported.
|
294 |
$unset_post_types = apply_filters( 'postexpirator_unset_post_types', array( 'attachment' ) );
|
297 |
unset( $post_types[ $type ] );
|
298 |
}
|
299 |
}
|
300 |
+
|
301 |
return $post_types;
|
302 |
}
|
303 |
|
309 |
* @access private
|
310 |
*/
|
311 |
function postexpirator_meta_custom() {
|
312 |
+
$facade = PostExpirator_Facade::getInstance();
|
313 |
+
|
314 |
+
if ( ! $facade->current_user_can_expire_posts() ) {
|
315 |
+
return;
|
316 |
+
}
|
317 |
+
|
318 |
$post_types = postexpirator_get_post_types();
|
319 |
foreach ( $post_types as $type ) {
|
320 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
|
321 |
// if settings are not configured, show the metabox by default only for posts and pages
|
322 |
+
if ( ( ! isset( $defaults['activeMetaBox'] ) && in_array( $type, array(
|
323 |
+
'post',
|
324 |
+
'page'
|
325 |
+
), true ) ) || ( is_array( $defaults ) && $defaults['activeMetaBox'] === 'active' ) ) {
|
326 |
add_meta_box( 'expirationdatediv', __( 'Post Expirator', 'post-expirator' ), 'postexpirator_meta_box', $type, 'side', 'core', array( '__back_compat_meta_box' => PostExpirator_Facade::show_gutenberg_metabox() ) );
|
327 |
}
|
328 |
}
|
329 |
}
|
330 |
+
|
331 |
add_action( 'add_meta_boxes', 'postexpirator_meta_custom' );
|
332 |
|
333 |
/**
|
340 |
function postexpirator_meta_box( $post ) {
|
341 |
// Get default month
|
342 |
$expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
|
343 |
+
$firstsave = get_post_meta( $post->ID, '_expiration-date-status', true );
|
344 |
|
345 |
+
$default = $expireType = $enabled = $defaultmonth = $defaultday = $defaulthour = $defaultyear = $defaultminute = $categories = '';
|
346 |
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post->post_type ) );
|
347 |
if ( empty( $expirationdatets ) ) {
|
348 |
$default_expiry = PostExpirator_Facade::get_default_expiry( $post->post_type );
|
349 |
|
350 |
+
$defaultmonth = $default_expiry['month'];
|
351 |
+
$defaultday = $default_expiry['day'];
|
352 |
+
$defaulthour = $default_expiry['hour'];
|
353 |
+
$defaultyear = $default_expiry['year'];
|
354 |
+
$defaultminute = $default_expiry['minute'];
|
355 |
|
356 |
+
$enabled = '';
|
357 |
$categories = get_option( 'expirationdateCategoryDefaults' );
|
358 |
|
359 |
if ( isset( $defaults['expireType'] ) ) {
|
365 |
$enabled = ' checked="checked"';
|
366 |
}
|
367 |
} else {
|
368 |
+
$defaultmonth = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'm' );
|
369 |
+
$defaultday = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'd' );
|
370 |
+
$defaultyear = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'Y' );
|
371 |
+
$defaulthour = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'H' );
|
372 |
+
$defaultminute = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $expirationdatets ), 'i' );
|
373 |
+
$enabled = ' checked="checked"';
|
374 |
|
375 |
$attributes = PostExpirator_Facade::get_expire_principles( $post->ID );
|
376 |
$expireType = $attributes['expireType'];
|
379 |
|
380 |
PostExpirator_Display::getInstance()->render_template(
|
381 |
'classic-metabox', array(
|
382 |
+
'post' => $post,
|
383 |
+
'enabled' => $enabled,
|
384 |
+
'default' => $default,
|
385 |
+
'defaultmonth' => $defaultmonth,
|
386 |
+
'defaultday' => $defaultday,
|
387 |
+
'defaulthour' => $defaulthour,
|
388 |
+
'defaultyear' => $defaultyear,
|
389 |
'defaultminute' => $defaultminute,
|
390 |
+
'categories' => $categories,
|
391 |
+
'expireType' => $expireType,
|
392 |
)
|
393 |
);
|
394 |
}
|
401 |
* @access private
|
402 |
*/
|
403 |
function postexpirator_js_admin_header() {
|
404 |
+
$facade = PostExpirator_Facade::getInstance();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
+
if ( ! $facade->current_user_can_expire_posts() ) {
|
407 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
408 |
}
|
409 |
+
?>
|
410 |
+
<script type="text/javascript">
|
411 |
+
//<![CDATA[
|
412 |
+
(function ($) {
|
413 |
+
$(document).ready(function () {
|
414 |
+
init();
|
415 |
+
});
|
416 |
+
|
417 |
+
function init() {
|
418 |
+
$('#enable-expirationdate').on('click', function (e) {
|
419 |
+
if ($(this).is(':checked')) {
|
420 |
+
$('.pe-classic-fields').show();
|
421 |
+
} else {
|
422 |
+
$('.pe-classic-fields').hide();
|
423 |
+
}
|
424 |
+
});
|
425 |
+
|
426 |
+
$('.pe-howtoexpire').on('change', function (e) {
|
427 |
+
if ($(this).val().indexOf('category') !== -1) {
|
428 |
+
$('#expired-category-selection').show();
|
429 |
+
} else {
|
430 |
+
$('#expired-category-selection').hide();
|
431 |
+
}
|
432 |
+
});
|
433 |
+
}
|
434 |
+
})(jQuery);
|
435 |
+
//]]>
|
436 |
+
</script>
|
437 |
<?php
|
438 |
}
|
439 |
+
|
440 |
add_action( 'admin_head', 'postexpirator_js_admin_header' );
|
441 |
|
442 |
/**
|
473 |
return;
|
474 |
}
|
475 |
|
476 |
+
$facade = PostExpirator_Facade::getInstance();
|
477 |
+
|
478 |
+
if ( ! $facade->current_user_can_expire_posts() ) {
|
479 |
+
return;
|
480 |
+
}
|
481 |
+
|
482 |
// we want to make sure we don't fire the save_post action when we are inside the block editor
|
483 |
// but this should not stop quick/bulk edit
|
484 |
if ( PostExpirator_Util::is_gutenberg_active() && PostExpirator_Facade::show_gutenberg_metabox()
|
485 |
+
&&
|
486 |
+
! isset( $_POST['expirationdate_quickedit'] ) && ! isset( $_POST['expirationdate_formcheck'] )
|
487 |
) {
|
488 |
return;
|
489 |
}
|
491 |
if ( isset( $_POST['enable-expirationdate'] ) ) {
|
492 |
$default = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
|
493 |
if ( $default === 'publish' ) {
|
494 |
+
$month = intval( $_POST['mm'] );
|
495 |
+
$day = intval( $_POST['jj'] );
|
496 |
+
$year = intval( $_POST['aa'] );
|
497 |
+
$hour = intval( $_POST['hh'] );
|
498 |
+
$minute = intval( $_POST['mn'] );
|
499 |
} else {
|
500 |
+
$month = intval( $_POST['expirationdate_month'] );
|
501 |
+
$day = intval( $_POST['expirationdate_day'] );
|
502 |
+
$year = intval( $_POST['expirationdate_year'] );
|
503 |
+
$hour = intval( $_POST['expirationdate_hour'] );
|
504 |
+
$minute = intval( $_POST['expirationdate_minute'] );
|
505 |
|
506 |
if ( empty( $day ) ) {
|
507 |
$day = date( 'd' );
|
520 |
$opts = PostExpirator_Facade::get_expire_principles( $id );
|
521 |
if ( isset( $_POST['expirationdate_expiretype'] ) ) {
|
522 |
$opts['expireType'] = $_POST['expirationdate_expiretype'];
|
523 |
+
if ( in_array( $opts['expireType'], array(
|
524 |
+
'category',
|
525 |
+
'category-add',
|
526 |
+
'category-remove'
|
527 |
+
), true ) ) {
|
528 |
$opts['category'] = $_POST['expirationdate_category'];
|
529 |
}
|
530 |
PostExpirator_Facade::set_expire_principles( $id, $opts );
|
535 |
|
536 |
// Schedule/Update Expiration
|
537 |
$opts['expireType'] = $_POST['expirationdate_expiretype'];
|
538 |
+
$opts['id'] = $id;
|
539 |
|
540 |
if ( $opts['expireType'] === 'category' || $opts['expireType'] === 'category-add' || $opts['expireType'] === 'category-remove' ) {
|
541 |
if ( isset( $category ) && ! empty( $category ) ) {
|
542 |
if ( ! empty( $category ) ) {
|
543 |
+
$opts['category'] = $category;
|
544 |
$opts['categoryTaxonomy'] = $_POST['taxonomy-heirarchical'];
|
545 |
}
|
546 |
}
|
551 |
postexpirator_unschedule_event( $id );
|
552 |
}
|
553 |
}
|
554 |
+
|
555 |
add_action( 'save_post', 'postexpirator_update_post_meta' );
|
556 |
|
557 |
/**
|
568 |
|
569 |
do_action( 'postexpiratior_schedule', $id, $ts, $opts ); // allow custom actions
|
570 |
|
571 |
+
if ( wp_next_scheduled( 'postExpiratorExpire', array( $id ) ) !== false ) {
|
572 |
+
$error = wp_clear_scheduled_hook( 'postExpiratorExpire', array( $id ), true ); // Remove any existing hooks
|
573 |
if ( POSTEXPIRATOR_DEBUG ) {
|
574 |
+
$debug->save( array( 'message' => $id . ' -> EXISTING FOUND - UNSCHEDULED - ' . ( is_wp_error( $error ) ? $error->get_error_message() : 'no error' ) ) );
|
575 |
}
|
576 |
}
|
577 |
|
578 |
+
$error = wp_schedule_single_event( $ts, 'postExpiratorExpire', array( $id ), true );
|
579 |
if ( POSTEXPIRATOR_DEBUG ) {
|
580 |
+
$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' ) ) );
|
581 |
}
|
582 |
|
583 |
// Update Post Meta
|
607 |
delete_post_meta( $id, '_expiration-date-taxonomy' );
|
608 |
|
609 |
// Delete Scheduled Expiration
|
610 |
+
if ( wp_next_scheduled( 'postExpiratorExpire', array( $id ) ) !== false ) {
|
611 |
+
wp_clear_scheduled_hook( 'postExpiratorExpire', array( $id ) ); // Remove any existing hooks
|
612 |
if ( POSTEXPIRATOR_DEBUG ) {
|
613 |
+
$debug->save( array( 'message' => $id . ' -> UNSCHEDULED' ) );
|
614 |
}
|
615 |
}
|
616 |
delete_post_meta( $id, '_expiration-date-status' );
|
630 |
|
631 |
if ( empty( $id ) ) {
|
632 |
if ( POSTEXPIRATOR_DEBUG ) {
|
633 |
+
$debug->save( array( 'message' => 'No Post ID found - exiting' ) );
|
634 |
}
|
635 |
+
|
636 |
return false;
|
637 |
}
|
638 |
|
639 |
if ( is_null( get_post( $id ) ) ) {
|
640 |
if ( POSTEXPIRATOR_DEBUG ) {
|
641 |
+
$debug->save( array( 'message' => $id . ' -> Post does not exist - exiting' ) );
|
642 |
}
|
643 |
+
|
644 |
return false;
|
645 |
}
|
646 |
|
647 |
+
$posttype = get_post_type( $id );
|
648 |
$posttitle = get_the_title( $id );
|
649 |
+
$postlink = get_post_permalink( $id );
|
650 |
|
651 |
$postoptions = PostExpirator_Facade::get_expire_principles( $id );
|
652 |
+
$expireType = $category = $categoryTaxonomy = null;
|
653 |
|
654 |
if ( isset( $postoptions['expireType'] ) ) {
|
655 |
$expireType = $postoptions['expireType'];
|
684 |
|
685 |
// Do Work
|
686 |
if ( $expireType === 'draft' ) {
|
687 |
+
if ( wp_update_post( array( 'ID' => $id, 'post_status' => 'draft' ) ) === 0 ) {
|
688 |
if ( POSTEXPIRATOR_DEBUG ) {
|
689 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
690 |
}
|
691 |
} else {
|
692 |
$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 ) );
|
693 |
if ( POSTEXPIRATOR_DEBUG ) {
|
694 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
695 |
}
|
696 |
}
|
697 |
} elseif ( $expireType === 'private' ) {
|
698 |
+
if ( wp_update_post( array( 'ID' => $id, 'post_status' => 'private' ) ) === 0 ) {
|
699 |
if ( POSTEXPIRATOR_DEBUG ) {
|
700 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
701 |
}
|
702 |
} else {
|
703 |
$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 ) );
|
704 |
if ( POSTEXPIRATOR_DEBUG ) {
|
705 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
706 |
}
|
707 |
}
|
708 |
} elseif ( $expireType === 'delete' ) {
|
709 |
if ( wp_delete_post( $id ) === false ) {
|
710 |
if ( POSTEXPIRATOR_DEBUG ) {
|
711 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
712 |
}
|
713 |
} else {
|
714 |
$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 ) );
|
715 |
if ( POSTEXPIRATOR_DEBUG ) {
|
716 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
717 |
}
|
718 |
}
|
719 |
} elseif ( $expireType === 'trash' ) {
|
720 |
if ( wp_trash_post( $id ) === false ) {
|
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 === 'stick' ) {
|
731 |
if ( stick_post( $id ) === false ) {
|
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 "%4$s" status has been successfully set.', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'STICKY' );
|
737 |
if ( POSTEXPIRATOR_DEBUG ) {
|
738 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
739 |
}
|
740 |
}
|
741 |
} elseif ( $expireType === 'unstick' ) {
|
742 |
if ( unstick_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 "%4$s" status has been successfully removed.', 'post-expirator' ), '##POSTTITLE##', '##POSTLINK##', '##EXPIRATIONDATE##', 'STICKY' );
|
748 |
if ( POSTEXPIRATOR_DEBUG ) {
|
749 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
750 |
}
|
751 |
}
|
752 |
} elseif ( $expireType === 'category' ) {
|
753 |
if ( ! empty( $category ) ) {
|
754 |
if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
|
755 |
+
if ( wp_update_post( array( 'ID' => $id, 'post_category' => $category ) ) === 0 ) {
|
756 |
if ( POSTEXPIRATOR_DEBUG ) {
|
757 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
758 |
}
|
759 |
} else {
|
760 |
$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 ) ) );
|
761 |
if ( POSTEXPIRATOR_DEBUG ) {
|
762 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
763 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES REPLACED ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
764 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
765 |
}
|
766 |
}
|
767 |
} else {
|
768 |
$terms = array_map( 'intval', $category );
|
769 |
if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, false ) ) ) {
|
770 |
if ( POSTEXPIRATOR_DEBUG ) {
|
771 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
772 |
}
|
773 |
} else {
|
774 |
$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 ) ) );
|
775 |
if ( POSTEXPIRATOR_DEBUG ) {
|
776 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
777 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES REPLACED ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
778 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
779 |
}
|
780 |
}
|
781 |
}
|
782 |
} else {
|
783 |
if ( POSTEXPIRATOR_DEBUG ) {
|
784 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
785 |
}
|
786 |
}
|
787 |
} elseif ( $expireType === 'category-add' ) {
|
788 |
if ( ! empty( $category ) ) {
|
789 |
if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
|
790 |
+
$cats = wp_get_post_categories( $id );
|
791 |
$merged = array_merge( $cats, $category );
|
792 |
+
if ( wp_update_post( array( 'ID' => $id, 'post_category' => $merged ) ) === 0 ) {
|
793 |
if ( POSTEXPIRATOR_DEBUG ) {
|
794 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
795 |
}
|
796 |
} else {
|
797 |
$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 ) ) );
|
798 |
if ( POSTEXPIRATOR_DEBUG ) {
|
799 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
800 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES ADDED ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
801 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $merged ), true ) ) );
|
802 |
}
|
803 |
}
|
804 |
} else {
|
805 |
$terms = array_map( 'intval', $category );
|
806 |
if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, true ) ) ) {
|
807 |
if ( POSTEXPIRATOR_DEBUG ) {
|
808 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
809 |
}
|
810 |
} else {
|
811 |
$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 ) ) );
|
812 |
if ( POSTEXPIRATOR_DEBUG ) {
|
813 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
814 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES ADDED ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
815 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
816 |
}
|
817 |
}
|
818 |
}
|
819 |
} else {
|
820 |
if ( POSTEXPIRATOR_DEBUG ) {
|
821 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
822 |
}
|
823 |
}
|
824 |
} elseif ( $expireType === 'category-remove' ) {
|
825 |
if ( ! empty( $category ) ) {
|
826 |
if ( ! isset( $categoryTaxonomy ) || $categoryTaxonomy === 'category' ) {
|
827 |
+
$cats = wp_get_post_categories( $id );
|
828 |
$merged = array();
|
829 |
foreach ( $cats as $cat ) {
|
830 |
if ( ! in_array( $cat, $category, false ) ) {
|
832 |
}
|
833 |
}
|
834 |
|
835 |
+
if ( wp_update_post( array( 'ID' => $id, 'post_category' => $merged ) ) === 0 ) {
|
836 |
if ( POSTEXPIRATOR_DEBUG ) {
|
837 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
838 |
}
|
839 |
} else {
|
840 |
$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 ) ) );
|
841 |
if ( POSTEXPIRATOR_DEBUG ) {
|
842 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
843 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES REMOVED ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
844 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $merged ), true ) ) );
|
845 |
}
|
846 |
}
|
847 |
} else {
|
848 |
+
$terms = wp_get_object_terms( $id, $categoryTaxonomy, array( 'fields' => 'ids' ) );
|
849 |
$merged = array();
|
850 |
foreach ( $terms as $term ) {
|
851 |
if ( ! in_array( $term, $category, false ) ) {
|
855 |
$terms = array_map( 'intval', $merged );
|
856 |
if ( is_wp_error( wp_set_object_terms( $id, $terms, $categoryTaxonomy, false ) ) ) {
|
857 |
if ( POSTEXPIRATOR_DEBUG ) {
|
858 |
+
$debug->save( array( 'message' => $id . ' -> FAILED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
859 |
}
|
860 |
} else {
|
861 |
$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 ) ) );
|
862 |
if ( POSTEXPIRATOR_DEBUG ) {
|
863 |
+
$debug->save( array( 'message' => $id . ' -> PROCESSED ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
864 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES REMOVED ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
865 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES COMPLETE ' . print_r( _postexpirator_get_cat_names( $category ), true ) ) );
|
866 |
}
|
867 |
}
|
868 |
}
|
869 |
} else {
|
870 |
if ( POSTEXPIRATOR_DEBUG ) {
|
871 |
+
$debug->save( array( 'message' => $id . ' -> CATEGORIES MISSING ' . $expireType . ' ' . print_r( $postoptions, true ) ) );
|
872 |
}
|
873 |
}
|
874 |
}
|
877 |
$emailenabled = get_option( 'expirationdateEmailNotification', POSTEXPIRATOR_EMAILNOTIFICATION );
|
878 |
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
879 |
if ( $emailenabled == 1 && isset( $emailBody ) ) {
|
880 |
+
$subj = sprintf( __( 'Post Expiration Complete "%s"', 'post-expirator' ), $posttitle );
|
881 |
$emailBody = str_replace( '##POSTTITLE##', $posttitle, $emailBody );
|
882 |
$emailBody = str_replace( '##POSTLINK##', $postlink, $emailBody );
|
883 |
$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 );
|
903 |
}
|
904 |
|
905 |
// Get Post Type Notification Emails
|
906 |
+
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $posttype ) );
|
907 |
if ( isset( $defaults['emailnotification'] ) && ! empty( $defaults['emailnotification'] ) ) {
|
908 |
$vals = explode( ',', $defaults['emailnotification'] );
|
909 |
foreach ( $vals as $val ) {
|
915 |
foreach ( $emails as $email ) {
|
916 |
if ( wp_mail( $email, sprintf( __( '[%1$s] %2$s' ), get_option( 'blogname' ), $subj ), $emailBody ) ) {
|
917 |
if ( POSTEXPIRATOR_DEBUG ) {
|
918 |
+
$debug->save( array( 'message' => $id . ' -> EXPIRATION EMAIL SENT (' . $email . ')' ) );
|
919 |
}
|
920 |
} else {
|
921 |
if ( POSTEXPIRATOR_DEBUG ) {
|
922 |
+
$debug->save( array( 'message' => $id . ' -> EXPIRATION EMAIL FAILED (' . $email . ')' ) );
|
923 |
}
|
924 |
}
|
925 |
}
|
926 |
}
|
927 |
|
928 |
}
|
929 |
+
|
930 |
add_action( 'postExpiratorExpire', 'postexpirator_expire_post' );
|
931 |
|
932 |
/**
|
941 |
foreach ( $cats as $cat ) {
|
942 |
$out[ $cat ] = get_the_category_by_id( $cat );
|
943 |
}
|
944 |
+
|
945 |
return $out;
|
946 |
}
|
947 |
|
1026 |
function postexpirator_shortcode( $atts ) {
|
1027 |
global $post;
|
1028 |
|
1029 |
+
$expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
|
1030 |
if ( empty( $expirationdatets ) ) {
|
1031 |
return false;
|
1032 |
}
|
1038 |
array(
|
1039 |
'dateformat' => get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT ),
|
1040 |
'timeformat' => get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT ),
|
1041 |
+
'type' => 'full',
|
1042 |
+
'tz' => date( 'T' ),
|
1043 |
), $atts
|
1044 |
)
|
1045 |
);
|
1064 |
|
1065 |
return date_i18n( $format, $expirationdatets + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
|
1066 |
}
|
1067 |
+
|
1068 |
add_shortcode( 'postexpirator', 'postexpirator_shortcode' );
|
1069 |
|
1070 |
/**
|
1085 |
return $text;
|
1086 |
}
|
1087 |
|
1088 |
+
$expirationdatets = get_post_meta( $post->ID, '_expiration-date', true );
|
1089 |
if ( ! is_numeric( $expirationdatets ) ) {
|
1090 |
return $text;
|
1091 |
}
|
1092 |
|
1093 |
+
$dateformat = get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT );
|
1094 |
+
$timeformat = get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT );
|
1095 |
+
$expirationdateFooterContents = get_option( 'expirationdateFooterContents', POSTEXPIRATOR_FOOTERCONTENTS );
|
1096 |
+
$expirationdateFooterStyle = get_option( 'expirationdateFooterStyle', POSTEXPIRATOR_FOOTERSTYLE );
|
1097 |
|
1098 |
+
$search = array(
|
1099 |
'EXPIRATIONFULL',
|
1100 |
'EXPIRATIONDATE',
|
1101 |
'EXPIRATIONTIME',
|
1107 |
);
|
1108 |
|
1109 |
$add_to_footer = '<p style="' . $expirationdateFooterStyle . '">' . str_replace( $search, $replace, $expirationdateFooterContents ) . '</p>';
|
1110 |
+
|
1111 |
return $text . $add_to_footer;
|
1112 |
}
|
1113 |
+
|
1114 |
add_action( 'the_content', 'postexpirator_add_footer', 0 );
|
1115 |
|
1116 |
/**
|
1127 |
if ( ! defined( 'POSTEXPIRATOR_DEBUG' ) ) {
|
1128 |
define( 'POSTEXPIRATOR_DEBUG', 1 );
|
1129 |
}
|
1130 |
+
require_once( plugin_dir_path( __FILE__ ) . 'post-expirator-debug.php' ); // Load Class
|
1131 |
+
|
1132 |
+
return new PostExpiratorDebug();
|
1133 |
} else {
|
1134 |
if ( ! defined( 'POSTEXPIRATOR_DEBUG' ) ) {
|
1135 |
define( 'POSTEXPIRATOR_DEBUG', 0 );
|
1136 |
}
|
1137 |
+
|
1138 |
return false;
|
1139 |
}
|
1140 |
}
|
1159 |
break;
|
1160 |
}
|
1161 |
}
|
1162 |
+
|
1163 |
add_action( 'admin_enqueue_scripts', 'postexpirator_css', 10, 1 );
|
1164 |
|
1165 |
/**
|
1177 |
postexpirator_activate();
|
1178 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1179 |
} else {
|
1180 |
+
if ( version_compare( $version, '1.6.1' ) === - 1 ) {
|
1181 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1182 |
update_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
|
1183 |
}
|
1184 |
|
1185 |
+
if ( version_compare( $version, '1.6.2' ) === - 1 ) {
|
1186 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1187 |
}
|
1188 |
|
1189 |
+
if ( version_compare( $version, '2.0.0-rc1' ) === - 1 ) {
|
1190 |
global $wpdb;
|
1191 |
|
1192 |
// Schedule Events/Migrate Config
|
1193 |
$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() ) );
|
1194 |
foreach ( $results as $result ) {
|
1195 |
+
wp_schedule_single_event( $result->meta_value, 'postExpiratorExpire', array( $result->post_id ) );
|
1196 |
+
$opts = array();
|
1197 |
$opts['id'] = $result->post_id;
|
1198 |
+
$posttype = get_post_type( $result->post_id );
|
1199 |
if ( $posttype === 'page' ) {
|
1200 |
+
$opts['expireType'] = strtolower( get_option( 'expirationdateExpiredPageStatus', 'Draft' ) );
|
1201 |
} else {
|
1202 |
+
$opts['expireType'] = strtolower( get_option( 'expirationdateExpiredPostStatus', 'Draft' ) );
|
1203 |
}
|
1204 |
|
1205 |
$cat = get_post_meta( $result->post_id, '_expiration-date-category', true );
|
1206 |
if ( ( isset( $cat ) && ! empty( $cat ) ) ) {
|
1207 |
+
$opts['category'] = $cat;
|
1208 |
$opts['expireType'] = 'category';
|
1209 |
}
|
1210 |
|
1219 |
$pagedefault = get_option( 'expirationdateExpiredPageStatus' );
|
1220 |
$postdefault = get_option( 'expirationdateExpiredPostStatus' );
|
1221 |
if ( $pagedefault ) {
|
1222 |
+
update_option( 'expirationdateDefaultsPage', array( 'expireType' => $pagedefault ) );
|
1223 |
}
|
1224 |
if ( $postdefault ) {
|
1225 |
+
update_option( 'expirationdateDefaultsPost', array( 'expireType' => $postdefault ) );
|
1226 |
}
|
1227 |
|
1228 |
delete_option( 'expirationdateCronSchedule' );
|
1232 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
1233 |
}
|
1234 |
|
1235 |
+
if ( version_compare( $version, '2.0.1' ) === - 1 ) {
|
1236 |
// Forgot to do this in 2.0.0
|
1237 |
if ( is_multisite() ) {
|
1238 |
global $current_blog;
|
1239 |
+
wp_clear_scheduled_hook( 'expirationdate_delete_' . $current_blog->blog_id );
|
1240 |
} else {
|
1241 |
wp_clear_scheduled_hook( 'expirationdate_delete' );
|
1242 |
}
|
1245 |
}
|
1246 |
|
1247 |
update_option( 'postexpiratorVersion', POSTEXPIRATOR_VERSION );
|
|
|
1248 |
}
|
1249 |
}
|
1250 |
+
|
1251 |
add_action( 'admin_init', 'postexpirator_upgrade' );
|
1252 |
|
1253 |
/**
|
1321 |
$debug = new PostExpiratorDebug();
|
1322 |
$debug->removeDbTable();
|
1323 |
}
|
1324 |
+
|
1325 |
register_deactivation_hook( __FILE__, 'expirationdate_deactivate' );
|
1326 |
|
1327 |
/**
|
1345 |
*
|
1346 |
* @var array
|
1347 |
*/
|
1348 |
+
var $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); // TODO: decouple this
|
1349 |
|
1350 |
/**
|
1351 |
* The disabled attribute.
|
1368 |
* class methods. This method is called at the start of the output list.
|
1369 |
*
|
1370 |
* @param string $output Used to append additional content (passed by reference).
|
1371 |
+
* @param int $depth Depth of the item.
|
1372 |
+
* @param array $args An array of additional arguments.
|
1373 |
*/
|
1374 |
function start_lvl( &$output, $depth = 0, $args = array() ) {
|
1375 |
$indent = str_repeat( "\t", $depth );
|
1383 |
* class methods. This method finishes the list at the end of output of the elements.
|
1384 |
*
|
1385 |
* @param string $output Used to append additional content (passed by reference).
|
1386 |
+
* @param int $depth Depth of the item.
|
1387 |
+
* @param array $args An array of additional arguments.
|
1388 |
*/
|
1389 |
function end_lvl( &$output, $depth = 0, $args = array() ) {
|
1390 |
$indent = str_repeat( "\t", $depth );
|
1397 |
* The $args parameter holds additional values that may be used with the child
|
1398 |
* class methods. Includes the element output also.
|
1399 |
*
|
1400 |
+
* @param string $output Used to append additional content (passed by reference).
|
1401 |
+
* @param object $category The data object.
|
1402 |
+
* @param int $depth Depth of the item.
|
1403 |
+
* @param array $args An array of additional arguments.
|
1404 |
+
* @param int $current_object_id ID of the current item.
|
1405 |
*/
|
1406 |
function start_el( &$output, $category, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
1407 |
// @TODO remove extract
|
1413 |
|
1414 |
$name = 'expirationdate_category';
|
1415 |
|
1416 |
+
$class = in_array( $category->term_id, $popular_cats, true ) ? ' class="expirator-category"' : '';
|
1417 |
$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>';
|
1418 |
}
|
1419 |
|
1424 |
*
|
1425 |
* @param string $output Used to append additional content (passed by reference).
|
1426 |
* @param object $category The data object.
|
1427 |
+
* @param int $depth Depth of the item.
|
1428 |
+
* @param array $args An array of additional arguments.
|
1429 |
*/
|
1430 |
function end_el( &$output, $category, $depth = 0, $args = array() ) {
|
1431 |
$output .= "</li>\n";
|
1479 |
}
|
1480 |
|
1481 |
$taxonomies = get_object_taxonomies( $type, 'object' );
|
1482 |
+
$taxonomies = wp_filter_object_list( $taxonomies, array( 'hierarchical' => true ) );
|
1483 |
|
1484 |
if ( empty( $taxonomies ) ) {
|
1485 |
$disabled = true;
|
1498 |
} else {
|
1499 |
$rv[] = __( 'No taxonomies found', 'post-expirator' );
|
1500 |
}
|
1501 |
+
|
1502 |
return implode( "<br/>\n", $rv );
|
1503 |
}
|
1504 |
|
1511 |
*/
|
1512 |
function postexpirator_quickedit_javascript() {
|
1513 |
// if using code as plugin
|
1514 |
+
wp_enqueue_script( 'postexpirator-edit', POSTEXPIRATOR_BASEURL . '/assets/js/admin-edit.js', array(
|
1515 |
+
'jquery',
|
1516 |
+
'inline-edit-post'
|
1517 |
+
), POSTEXPIRATOR_VERSION, true );
|
1518 |
wp_localize_script(
|
1519 |
'postexpirator-edit', 'config', array(
|
1520 |
'ajax' => array(
|
1521 |
+
'nonce' => wp_create_nonce( POSTEXPIRATOR_SLUG ),
|
1522 |
'bulk_edit' => 'manage_wp_posts_using_bulk_quick_save_bulk_edit',
|
1523 |
),
|
1524 |
)
|
1525 |
);
|
1526 |
}
|
1527 |
+
|
1528 |
add_action( 'admin_print_scripts-edit.php', 'postexpirator_quickedit_javascript' );
|
1529 |
|
1530 |
/**
|
1537 |
function postexpirator_date_save_bulk_edit() {
|
1538 |
check_ajax_referer( POSTEXPIRATOR_SLUG, 'nonce' );
|
1539 |
|
1540 |
+
$facade = PostExpirator_Facade::getInstance();
|
1541 |
+
|
1542 |
+
if ( ! $facade->current_user_can_expire_posts() ) {
|
1543 |
+
wp_die( __( 'You\'re not allowed to set posts to expire', 'post-expirator' ), __( 'Forbidden', 'post-expirator' ), 403 );
|
1544 |
+
}
|
1545 |
+
|
1546 |
// we need the post IDs
|
1547 |
$post_ids = ( isset( $_POST['post_ids'] ) && ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : null;
|
1548 |
|
1556 |
return;
|
1557 |
}
|
1558 |
|
1559 |
+
$month = intval( $_POST['expirationdate_month'] );
|
1560 |
+
$day = intval( $_POST['expirationdate_day'] );
|
1561 |
+
$year = intval( $_POST['expirationdate_year'] );
|
1562 |
+
$hour = intval( $_POST['expirationdate_hour'] );
|
1563 |
+
$minute = intval( $_POST['expirationdate_minute'] );
|
1564 |
|
1565 |
// default to current date and/or year if not provided by user.
|
1566 |
if ( empty( $day ) ) {
|
1577 |
}
|
1578 |
|
1579 |
foreach ( $post_ids as $post_id ) {
|
1580 |
+
$ed = get_post_meta( $post_id, '_expiration-date', true );
|
1581 |
$update_expiry = false;
|
1582 |
|
1583 |
switch ( $status ) {
|
1597 |
}
|
1598 |
|
1599 |
if ( $update_expiry ) {
|
1600 |
+
$opts = PostExpirator_Facade::get_expire_principles( $post_id );
|
1601 |
$opts['expireType'] = $_POST['expirationdate_expiretype'];
|
1602 |
|
1603 |
if ( in_array( $opts['expireType'], array( 'category', 'category-add', 'category-remove' ), true ) ) {
|
1611 |
}
|
1612 |
}
|
1613 |
}
|
1614 |
+
|
1615 |
add_action( 'wp_ajax_manage_wp_posts_using_bulk_quick_save_bulk_edit', 'postexpirator_date_save_bulk_edit' );
|
1616 |
|
1617 |
/**
|
1621 |
$namespaces = array( 'PostExpirator' );
|
1622 |
foreach ( $namespaces as $namespace ) {
|
1623 |
if ( substr( $class, 0, strlen( $namespace ) ) === $namespace ) {
|
1624 |
+
$class = str_replace( '_', '', strstr( $class, '_' ) );
|
1625 |
$filename = plugin_dir_path( __FILE__ ) . 'classes/' . sprintf( '%s.class.php', $class );
|
1626 |
if ( is_readable( $filename ) ) {
|
1627 |
require_once $filename;
|
1628 |
+
|
1629 |
return true;
|
1630 |
}
|
1631 |
}
|
1632 |
}
|
1633 |
+
|
1634 |
return false;
|
1635 |
}
|
1636 |
+
|
1637 |
spl_autoload_register( 'postexpirator_autoload' );
|
1638 |
|
1639 |
/**
|
1642 |
function postexpirator_launch() {
|
1643 |
PostExpirator_Facade::getInstance();
|
1644 |
}
|
1645 |
+
|
1646 |
postexpirator_launch();
|
1647 |
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Author URI: https://publishpress.com
|
|
5 |
Tags: expire, posts, pages, schedule
|
6 |
Requires at least: 5.0
|
7 |
Tested up to: 5.8
|
8 |
-
Stable tag: 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 |
|
@@ -81,6 +81,10 @@ This section describes how to install the plugin and get it working.
|
|
81 |
|
82 |
== Changelog ==
|
83 |
|
|
|
|
|
|
|
|
|
84 |
= [2.5.1] - 27 Sep 2021 =
|
85 |
|
86 |
* Fixed: Default Expiration Categories cannot be unset, #94;
|
5 |
Tags: expire, posts, pages, schedule
|
6 |
Requires at least: 5.0
|
7 |
Tested up to: 5.8
|
8 |
+
Stable tag: 2.6.0
|
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 |
|
81 |
|
82 |
== Changelog ==
|
83 |
|
84 |
+
= [2.6.0] - 04 Oct 2021 =
|
85 |
+
|
86 |
+
* Added: Add specific capabilities for expiring posts, #141;
|
87 |
+
|
88 |
= [2.5.1] - 27 Sep 2021 =
|
89 |
|
90 |
* Fixed: Default Expiration Categories cannot be unset, #94;
|
vendor/composer/InstalledVersions.php
CHANGED
@@ -29,7 +29,7 @@ private static $installed = array (
|
|
29 |
'aliases' =>
|
30 |
array (
|
31 |
),
|
32 |
-
'reference' => '
|
33 |
'name' => 'publishpress/post-expirator',
|
34 |
),
|
35 |
'versions' =>
|
@@ -41,7 +41,7 @@ private static $installed = array (
|
|
41 |
'aliases' =>
|
42 |
array (
|
43 |
),
|
44 |
-
'reference' => '
|
45 |
),
|
46 |
),
|
47 |
);
|
29 |
'aliases' =>
|
30 |
array (
|
31 |
),
|
32 |
+
'reference' => '51bb3d37d22a270fd69314262d1ff3f997ee8f4c',
|
33 |
'name' => 'publishpress/post-expirator',
|
34 |
),
|
35 |
'versions' =>
|
41 |
'aliases' =>
|
42 |
array (
|
43 |
),
|
44 |
+
'reference' => '51bb3d37d22a270fd69314262d1ff3f997ee8f4c',
|
45 |
),
|
46 |
),
|
47 |
);
|
vendor/composer/installed.php
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
'aliases' =>
|
7 |
array (
|
8 |
),
|
9 |
-
'reference' => '
|
10 |
'name' => 'publishpress/post-expirator',
|
11 |
),
|
12 |
'versions' =>
|
@@ -18,7 +18,7 @@
|
|
18 |
'aliases' =>
|
19 |
array (
|
20 |
),
|
21 |
-
'reference' => '
|
22 |
),
|
23 |
),
|
24 |
);
|
6 |
'aliases' =>
|
7 |
array (
|
8 |
),
|
9 |
+
'reference' => '51bb3d37d22a270fd69314262d1ff3f997ee8f4c',
|
10 |
'name' => 'publishpress/post-expirator',
|
11 |
),
|
12 |
'versions' =>
|
18 |
'aliases' =>
|
19 |
array (
|
20 |
),
|
21 |
+
'reference' => '51bb3d37d22a270fd69314262d1ff3f997ee8f4c',
|
22 |
),
|
23 |
),
|
24 |
);
|
views/bulk-edit.php
CHANGED
@@ -1,17 +1,17 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
?>
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
<div class="inline-edit-group">
|
14 |
-
|
15 |
<fieldset class="inline-edit-date">
|
16 |
<div class="pe-qe-fields">
|
17 |
<div>
|
@@ -19,11 +19,17 @@
|
|
19 |
<label>
|
20 |
<span class="screen-reader-text"><?php _e( 'Enable Post Expiration', 'post-expirator' ); ?></span>
|
21 |
<select name="expirationdate_status">
|
22 |
-
<option value="no-change" data-show-fields="false" selected
|
23 |
-
|
24 |
-
|
25 |
-
<option value="change-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
</select>
|
28 |
</label>
|
29 |
<span class="post-expirator-date-fields">
|
@@ -31,33 +37,38 @@
|
|
31 |
<span class="screen-reader-text"><?php _e( 'Month', 'post-expirator' ); ?></span>
|
32 |
<select name="expirationdate_month">
|
33 |
<?php
|
34 |
-
for ( $x = 1; $x <= 12; $x++ ) {
|
35 |
-
$now
|
36 |
$monthNumeric = date_i18n( 'm', $now );
|
37 |
-
$monthStr
|
38 |
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
39 |
$selected = $monthNumeric == $defaults['month'] ? 'selected' : '';
|
40 |
?>
|
41 |
-
|
|
|
42 |
<?php } ?>
|
43 |
|
44 |
</select>
|
45 |
</label>
|
46 |
<label>
|
47 |
<span class="screen-reader-text"><?php _e( 'Day', 'post-expirator' ); ?></span>
|
48 |
-
<input name="expirationdate_day" placeholder="<?php echo $day; ?>" value="" size="2"
|
49 |
-
|
|
|
50 |
<label>
|
51 |
<span class="screen-reader-text"><?php _e( 'Year', 'post-expirator' ); ?></span>
|
52 |
-
<input name="expirationdate_year" placeholder="<?php echo $year; ?>" value="" size="4"
|
53 |
-
|
|
|
54 |
<label>
|
55 |
<span class="screen-reader-text"><?php _e( 'Hour', 'post-expirator' ); ?></span>
|
56 |
-
<input name="expirationdate_hour" placeholder="<?php echo $hour; ?>" value="" size="2"
|
|
|
57 |
</label> :
|
58 |
<label>
|
59 |
<span class="screen-reader-text"><?php _e( 'Minute', 'post-expirator' ); ?></span>
|
60 |
-
<input name="expirationdate_minute" placeholder="<?php echo $minute; ?>" value=""
|
|
|
61 |
</label>
|
62 |
</span>
|
63 |
</div>
|
@@ -68,8 +79,11 @@
|
|
68 |
</legend>
|
69 |
<label>
|
70 |
<?php
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
73 |
?>
|
74 |
</label>
|
75 |
</div>
|
@@ -78,13 +92,17 @@
|
|
78 |
<span class="title"><?php echo $tax_label; ?></span>
|
79 |
<span class="screen-reader-text"><?php _e( 'Expiration Categories', 'post-expirator' ); ?></span>
|
80 |
</legend>
|
81 |
-
<ul id="categorychecklist"
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
88 |
</ul>
|
89 |
</div>
|
90 |
</span>
|
@@ -92,5 +110,5 @@
|
|
92 |
<input name="expirationdate_quickedit" value="true" type="hidden"/>
|
93 |
</fieldset>
|
94 |
</div>
|
95 |
-
</div>
|
96 |
</div>
|
|
1 |
<?php
|
2 |
+
$defaults = PostExpirator_Facade::get_default_expiry( $post_type );
|
3 |
|
4 |
+
$year = $defaults['year'];
|
5 |
+
$month = $defaults['month'];
|
6 |
+
$day = $defaults['day'];
|
7 |
+
$hour = $defaults['hour'];
|
8 |
+
$minute = $defaults['minute'];
|
9 |
?>
|
10 |
+
<div style="clear:both"></div>
|
11 |
+
<div class="inline-edit-col post-expirator-quickedit">
|
12 |
+
<div class="inline-edit-col">
|
13 |
<div class="inline-edit-group">
|
14 |
+
<legend class="inline-edit-legend"><?php _e( 'Post Expirator', 'post-expirator' ); ?></legend>
|
15 |
<fieldset class="inline-edit-date">
|
16 |
<div class="pe-qe-fields">
|
17 |
<div>
|
19 |
<label>
|
20 |
<span class="screen-reader-text"><?php _e( 'Enable Post Expiration', 'post-expirator' ); ?></span>
|
21 |
<select name="expirationdate_status">
|
22 |
+
<option value="no-change" data-show-fields="false" selected>
|
23 |
+
--<?php _e( 'No Change', 'post-expirator' ); ?>--
|
24 |
+
</option>
|
25 |
+
<option value="change-only" data-show-fields="true"
|
26 |
+
title="<?php _e( 'Change expiry date if enabled on posts', 'post-expirator' ); ?>"><?php _e( 'Change on posts', 'post-expirator' ); ?></option>
|
27 |
+
<option value="add-only" data-show-fields="true"
|
28 |
+
title="<?php _e( 'Add expiry date if not enabled on posts', 'post-expirator' ); ?>"><?php _e( 'Add to posts', 'post-expirator' ); ?></option>
|
29 |
+
<option value="change-add"
|
30 |
+
data-show-fields="true"><?php _e( 'Change & Add', 'post-expirator' ); ?></option>
|
31 |
+
<option value="remove-only"
|
32 |
+
data-show-fields="false"><?php _e( 'Remove from posts', 'post-expirator' ); ?></option>
|
33 |
</select>
|
34 |
</label>
|
35 |
<span class="post-expirator-date-fields">
|
37 |
<span class="screen-reader-text"><?php _e( 'Month', 'post-expirator' ); ?></span>
|
38 |
<select name="expirationdate_month">
|
39 |
<?php
|
40 |
+
for ( $x = 1; $x <= 12; $x ++ ) {
|
41 |
+
$now = mktime( 0, 0, 0, $x, 1, date_i18n( 'Y' ) );
|
42 |
$monthNumeric = date_i18n( 'm', $now );
|
43 |
+
$monthStr = date_i18n( 'M', $now );
|
44 |
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
45 |
$selected = $monthNumeric == $defaults['month'] ? 'selected' : '';
|
46 |
?>
|
47 |
+
<option value="<?php echo $monthNumeric; ?>"
|
48 |
+
data-text="<?php echo $monthStr; ?>" <?php echo $selected; ?>><?php echo $monthNumeric; ?>-<?php echo $monthStr; ?></option>
|
49 |
<?php } ?>
|
50 |
|
51 |
</select>
|
52 |
</label>
|
53 |
<label>
|
54 |
<span class="screen-reader-text"><?php _e( 'Day', 'post-expirator' ); ?></span>
|
55 |
+
<input name="expirationdate_day" placeholder="<?php echo $day; ?>" value="" size="2"
|
56 |
+
maxlength="2" autocomplete="off" type="text">
|
57 |
+
</label>,
|
58 |
<label>
|
59 |
<span class="screen-reader-text"><?php _e( 'Year', 'post-expirator' ); ?></span>
|
60 |
+
<input name="expirationdate_year" placeholder="<?php echo $year; ?>" value="" size="4"
|
61 |
+
maxlength="4" autocomplete="off" type="text">
|
62 |
+
</label> @
|
63 |
<label>
|
64 |
<span class="screen-reader-text"><?php _e( 'Hour', 'post-expirator' ); ?></span>
|
65 |
+
<input name="expirationdate_hour" placeholder="<?php echo $hour; ?>" value="" size="2"
|
66 |
+
maxlength="2" autocomplete="off" type="text">
|
67 |
</label> :
|
68 |
<label>
|
69 |
<span class="screen-reader-text"><?php _e( 'Minute', 'post-expirator' ); ?></span>
|
70 |
+
<input name="expirationdate_minute" placeholder="<?php echo $minute; ?>" value=""
|
71 |
+
size="2" maxlength="2" autocomplete="off" type="text">
|
72 |
</label>
|
73 |
</span>
|
74 |
</div>
|
79 |
</legend>
|
80 |
<label>
|
81 |
<?php
|
82 |
+
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post_type ) );
|
83 |
+
_postexpirator_expire_type( array( 'name' => 'expirationdate_expiretype',
|
84 |
+
'selected' => empty( $defaults ) ? 'draft' : $defaults['expireType'],
|
85 |
+
'post_type' => $post_type
|
86 |
+
) );
|
87 |
?>
|
88 |
</label>
|
89 |
</div>
|
92 |
<span class="title"><?php echo $tax_label; ?></span>
|
93 |
<span class="screen-reader-text"><?php _e( 'Expiration Categories', 'post-expirator' ); ?></span>
|
94 |
</legend>
|
95 |
+
<ul id="categorychecklist"
|
96 |
+
class="list:category categorychecklist cat-checklist category-checklist">
|
97 |
+
<?php
|
98 |
+
if ( ! empty( $taxonomy ) ) {
|
99 |
+
$walker = new Walker_PostExpirator_Category_Checklist();
|
100 |
+
wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy,
|
101 |
+
'walker' => $walker,
|
102 |
+
'checked_ontop' => false
|
103 |
+
) );
|
104 |
+
}
|
105 |
+
?>
|
106 |
</ul>
|
107 |
</div>
|
108 |
</span>
|
110 |
<input name="expirationdate_quickedit" value="true" type="hidden"/>
|
111 |
</fieldset>
|
112 |
</div>
|
|
|
113 |
</div>
|
114 |
+
</div>
|
views/classic-metabox.php
CHANGED
@@ -1,124 +1,135 @@
|
|
1 |
<p>
|
2 |
-
<input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"'
|
|
|
3 |
<label for="enable-expirationdate"><?php _e( 'Enable Post Expiration', 'post-expirator' ); ?></label>
|
4 |
</p>
|
5 |
|
6 |
<?php
|
7 |
if ( $default === 'publish' ) {
|
8 |
?>
|
9 |
-
|
10 |
<?php
|
11 |
return;
|
12 |
}
|
13 |
?>
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
}
|
32 |
-
?>
|
33 |
-
<option <?php echo $selected; ?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
|
34 |
-
<?php
|
35 |
}
|
36 |
?>
|
37 |
-
|
38 |
-
</div>
|
39 |
-
<div>
|
40 |
-
<label><?php _e( 'Month', 'post-expirator' ); ?></label>
|
41 |
-
<select name="expirationdate_month" id="expirationdate_month" >
|
42 |
<?php
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
?>
|
54 |
-
|
55 |
-
</div>
|
56 |
-
<div>
|
57 |
-
<label><?php _e( 'Day', 'post-expirator' ); ?></label>
|
58 |
-
<input type="text" id="expirationdate_day" name="expirationdate_day" value="<?php echo $defaultday; ?>" size="2" />
|
59 |
-
</div>
|
60 |
-
<div>
|
61 |
-
<label><?php _e( 'Hour', 'post-expirator' ); ?> (<?php echo date_i18n( 'T', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ); ?>)</label>
|
62 |
-
<select name="expirationdate_hour" id="expirationdate_hour" >
|
63 |
<?php
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
</div>
|
78 |
-
<div>
|
79 |
-
<label><?php _e( 'Minute', 'post-expirator' ); ?></label>
|
80 |
-
<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="<?php echo $defaultminute; ?>" size="2" />
|
81 |
-
</div>
|
82 |
-
<div>
|
83 |
-
<label><?php _e( 'How to expire', 'post-expirator' ); ?></label>
|
84 |
-
<?php _postexpirator_expire_type( array('type' => $post->post_type, 'name' => 'expirationdate_expiretype', 'selected' => $expireType ) ); ?>
|
85 |
-
</div>
|
86 |
-
|
87 |
<?php
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
91 |
} else {
|
92 |
-
$
|
93 |
}
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
|
99 |
-
echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
|
100 |
-
$walker = new Walker_PostExpirator_Category_Checklist();
|
101 |
-
$taxonomies = get_object_taxonomies( $post->post_type, 'object' );
|
102 |
-
$taxonomies = wp_filter_object_list( $taxonomies, array('hierarchical' => true) );
|
103 |
-
if ( sizeof( $taxonomies ) === 0 ) {
|
104 |
-
echo '<p>' . __( 'You must assign a heirarchical taxonomy to this post type to use this feature.', 'post-expirator' ) . '</p>';
|
105 |
-
} elseif ( sizeof( $taxonomies ) > 1 && ! isset( $defaults['taxonomy'] ) ) {
|
106 |
-
echo '<p>' . __( 'More than 1 heirachical taxonomy detected. You must assign a default taxonomy on the settings screen.', 'post-expirator' ) . '</p>';
|
107 |
-
} else {
|
108 |
-
$keys = array_keys( $taxonomies );
|
109 |
-
$taxonomy = isset( $defaults['taxonomy'] ) ? $defaults['taxonomy'] : $keys[0];
|
110 |
-
wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false ) );
|
111 |
-
echo '<input type="hidden" name="taxonomy-heirarchical" value="' . $taxonomy . '" />';
|
112 |
-
}
|
113 |
-
echo '</ul>';
|
114 |
-
echo '</div>';
|
115 |
-
if ( isset( $taxonomy ) ) {
|
116 |
-
echo '<p class="post-expirator-taxonomy-name">' . __( 'Taxonomy Name', 'post-expirator' ) . ': ' . $taxonomy . '</p>';
|
117 |
-
}
|
118 |
-
echo '</div>';
|
119 |
}
|
120 |
?>
|
121 |
-
</
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<p>
|
2 |
+
<input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"'
|
3 |
+
. <?php echo $enabled; ?>/>
|
4 |
<label for="enable-expirationdate"><?php _e( 'Enable Post Expiration', 'post-expirator' ); ?></label>
|
5 |
</p>
|
6 |
|
7 |
<?php
|
8 |
if ( $default === 'publish' ) {
|
9 |
?>
|
10 |
+
<em><?php _e( 'The published date/time will be used as the expiration value', 'post-expirator' ); ?></em>
|
11 |
<?php
|
12 |
return;
|
13 |
}
|
14 |
?>
|
15 |
+
<div class="pe-classic-fields" style="display: <?php echo empty( $enabled ) ? 'none' : 'flex'; ?>">
|
16 |
+
<div>
|
17 |
+
<label><?php _e( 'Year', 'post-expirator' ); ?></label>
|
18 |
+
<select name="expirationdate_year" id="expirationdate_year">
|
19 |
+
<?php
|
20 |
+
$currentyear = date( 'Y' );
|
21 |
|
22 |
+
if ( $defaultyear < $currentyear ) {
|
23 |
+
$currentyear = $defaultyear;
|
24 |
+
}
|
25 |
|
26 |
+
for ( $i = $currentyear; $i <= $currentyear + 10; $i ++ ) {
|
27 |
+
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
28 |
+
if ( $i == $defaultyear ) {
|
29 |
+
$selected = ' selected="selected"';
|
30 |
+
} else {
|
31 |
+
$selected = '';
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
?>
|
34 |
+
<option <?php echo $selected; ?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
|
|
|
|
|
|
|
|
|
35 |
<?php
|
36 |
+
}
|
37 |
+
?>
|
38 |
+
</select>
|
39 |
+
</div>
|
40 |
+
<div>
|
41 |
+
<label><?php _e( 'Month', 'post-expirator' ); ?></label>
|
42 |
+
<select name="expirationdate_month" id="expirationdate_month">
|
43 |
+
<?php
|
44 |
+
for ( $i = 1; $i <= 12; $i ++ ) {
|
45 |
+
if ( $defaultmonth === date_i18n( 'm', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ) ) {
|
46 |
+
$selected = ' selected="selected"';
|
47 |
+
} else {
|
48 |
+
$selected = '';
|
49 |
}
|
50 |
?>
|
51 |
+
<option value="<?php echo date_i18n( 'm', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ); ?>" <?php echo $selected; ?>><?php echo date_i18n( 'F', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ); ?></option>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
<?php
|
53 |
+
}
|
54 |
+
?>
|
55 |
+
</select>
|
56 |
+
</div>
|
57 |
+
<div>
|
58 |
+
<label><?php _e( 'Day', 'post-expirator' ); ?></label>
|
59 |
+
<input type="text" id="expirationdate_day" name="expirationdate_day" value="<?php echo $defaultday; ?>"
|
60 |
+
size="2"/>
|
61 |
+
</div>
|
62 |
+
<div>
|
63 |
+
<label><?php _e( 'Hour', 'post-expirator' ); ?>
|
64 |
+
(<?php echo date_i18n( 'T', mktime( 0, 0, 0, $i, 1, date_i18n( 'Y' ) ) ); ?>)</label>
|
65 |
+
<select name="expirationdate_hour" id="expirationdate_hour">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
<?php
|
67 |
+
for ( $i = 1; $i <= 24; $i ++ ) {
|
68 |
+
$hour = date_i18n( 'H', mktime( $i, 0, 0, date_i18n( 'n' ), date_i18n( 'j' ), date_i18n( 'Y' ) ) );
|
69 |
+
if ( $defaulthour === $hour ) {
|
70 |
+
$selected = ' selected="selected"';
|
71 |
} else {
|
72 |
+
$selected = '';
|
73 |
}
|
74 |
+
?>
|
75 |
+
<option value="<?php echo $hour; ?>" <?php echo $selected; ?>><?php echo $hour; ?></option>
|
76 |
+
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
}
|
78 |
?>
|
79 |
+
</select>
|
80 |
+
</div>
|
81 |
+
<div>
|
82 |
+
<label><?php _e( 'Minute', 'post-expirator' ); ?></label>
|
83 |
+
<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="<?php echo $defaultminute; ?>"
|
84 |
+
size="2"/>
|
85 |
+
</div>
|
86 |
+
<div>
|
87 |
+
<label><?php _e( 'How to expire', 'post-expirator' ); ?></label>
|
88 |
+
<?php _postexpirator_expire_type( array( 'type' => $post->post_type,
|
89 |
+
'name' => 'expirationdate_expiretype',
|
90 |
+
'selected' => $expireType
|
91 |
+
) ); ?>
|
92 |
+
</div>
|
93 |
+
|
94 |
+
<?php
|
95 |
+
if ( $post->post_type !== 'page' ) {
|
96 |
+
if ( isset( $expireType ) && ( $expireType === 'category' || $expireType === 'category-add' || $expireType === 'category-remove' ) ) {
|
97 |
+
$catdisplay = 'block';
|
98 |
+
} else {
|
99 |
+
$catdisplay = 'none';
|
100 |
+
}
|
101 |
+
|
102 |
+
echo '<div id="expired-category-selection" style="display: ' . $catdisplay . '">';
|
103 |
+
echo '<br/>' . __( 'Expiration Categories', 'post-expirator' ) . ':<br/>';
|
104 |
+
|
105 |
+
echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
|
106 |
+
echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
|
107 |
+
$walker = new Walker_PostExpirator_Category_Checklist();
|
108 |
+
$taxonomies = get_object_taxonomies( $post->post_type, 'object' );
|
109 |
+
$taxonomies = wp_filter_object_list( $taxonomies, array( 'hierarchical' => true ) );
|
110 |
+
if ( sizeof( $taxonomies ) === 0 ) {
|
111 |
+
echo '<p>' . __( 'You must assign a heirarchical taxonomy to this post type to use this feature.', 'post-expirator' ) . '</p>';
|
112 |
+
} elseif ( sizeof( $taxonomies ) > 1 && ! isset( $defaults['taxonomy'] ) ) {
|
113 |
+
echo '<p>' . __( 'More than 1 heirachical taxonomy detected. You must assign a default taxonomy on the settings screen.', 'post-expirator' ) . '</p>';
|
114 |
+
} else {
|
115 |
+
$keys = array_keys( $taxonomies );
|
116 |
+
$taxonomy = isset( $defaults['taxonomy'] ) ? $defaults['taxonomy'] : $keys[0];
|
117 |
+
wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy,
|
118 |
+
'walker' => $walker,
|
119 |
+
'selected_cats' => $categories,
|
120 |
+
'checked_ontop' => false
|
121 |
+
) );
|
122 |
+
echo '<input type="hidden" name="taxonomy-heirarchical" value="' . $taxonomy . '" />';
|
123 |
+
}
|
124 |
+
echo '</ul>';
|
125 |
+
echo '</div>';
|
126 |
+
if ( isset( $taxonomy ) ) {
|
127 |
+
echo '<p class="post-expirator-taxonomy-name">' . __( 'Taxonomy Name', 'post-expirator' ) . ': ' . $taxonomy . '</p>';
|
128 |
+
}
|
129 |
+
echo '</div>';
|
130 |
+
}
|
131 |
+
?>
|
132 |
+
</div>
|
133 |
+
|
134 |
+
<input type="hidden" name="expirationdate_formcheck" value="true"/>
|
135 |
+
<?php wp_nonce_field( '__postexpirator', '_postexpiratornonce' ); ?>
|
views/expire-column.php
CHANGED
@@ -1,48 +1,53 @@
|
|
1 |
-
<div class="post-expire-col" data-id="<?php echo esc_attr( $id ); ?>"
|
2 |
-
<?php
|
|
|
3 |
$display = __( 'Never', 'post-expirator' );
|
4 |
-
$ed
|
5 |
-
if ( $ed ) {
|
6 |
-
|
7 |
-
}
|
8 |
|
9 |
-
$defaults
|
10 |
$expireType = 'draft';
|
11 |
-
if ( isset( $defaults['expireType'] ) ) {
|
12 |
-
|
13 |
-
}
|
14 |
|
15 |
// these defaults will be used by quick edit
|
16 |
$defaults = PostExpirator_Facade::get_default_expiry( $post_type );
|
17 |
|
18 |
-
$year
|
19 |
-
$month
|
20 |
-
$day
|
21 |
-
$hour
|
22 |
-
$minute
|
23 |
-
$enabled
|
24 |
$categories = '';
|
25 |
|
26 |
// Values for Quick Edit
|
27 |
-
if ( $ed ) {
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
-
}
|
42 |
|
43 |
// the hidden fields will be used by quick edit
|
44 |
|
45 |
-
?>
|
46 |
<?php echo esc_html( $display ); ?>
|
47 |
<span id="expirationdate_year-<?php echo $id; ?>" style="display: none;"><?php echo $year; ?></span>
|
48 |
<span id="expirationdate_month-<?php echo $id; ?>" style="display: none;"><?php echo $month; ?></span>
|
1 |
+
<div class="post-expire-col" data-id="<?php echo esc_attr( $id ); ?>"
|
2 |
+
data-expire-attributes="<?php echo esc_attr( json_encode( $attributes ) ); ?>">
|
3 |
+
<?php
|
4 |
$display = __( 'Never', 'post-expirator' );
|
5 |
+
$ed = get_post_meta( $id, '_expiration-date', true );
|
6 |
+
if ( $ed ) {
|
7 |
+
$display = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $ed + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
|
8 |
+
}
|
9 |
|
10 |
+
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post_type ) );
|
11 |
$expireType = 'draft';
|
12 |
+
if ( isset( $defaults['expireType'] ) ) {
|
13 |
+
$expireType = $defaults['expireType'];
|
14 |
+
}
|
15 |
|
16 |
// these defaults will be used by quick edit
|
17 |
$defaults = PostExpirator_Facade::get_default_expiry( $post_type );
|
18 |
|
19 |
+
$year = $defaults['year'];
|
20 |
+
$month = $defaults['month'];
|
21 |
+
$day = $defaults['day'];
|
22 |
+
$hour = $defaults['hour'];
|
23 |
+
$minute = $defaults['minute'];
|
24 |
+
$enabled = 'false';
|
25 |
$categories = '';
|
26 |
|
27 |
// Values for Quick Edit
|
28 |
+
if ( $ed ) {
|
29 |
+
$enabled = 'true';
|
30 |
+
$date = gmdate( 'Y-m-d H:i:s', $ed );
|
31 |
+
$year = get_date_from_gmt( $date, 'Y' );
|
32 |
+
$month = get_date_from_gmt( $date, 'm' );
|
33 |
+
$day = get_date_from_gmt( $date, 'd' );
|
34 |
+
$hour = get_date_from_gmt( $date, 'H' );
|
35 |
+
$minute = get_date_from_gmt( $date, 'i' );
|
36 |
+
if ( isset( $attributes['expireType'] ) ) {
|
37 |
+
$expireType = $attributes['expireType'];
|
38 |
+
}
|
39 |
+
if ( isset( $attributes['category'] ) && ! empty( $attributes['category'] ) && in_array( $expireType, array(
|
40 |
+
'category',
|
41 |
+
'category-add',
|
42 |
+
'category-remove'
|
43 |
+
), true ) ) {
|
44 |
+
$categories = implode( ',', $attributes['category'] );
|
45 |
+
}
|
46 |
}
|
|
|
47 |
|
48 |
// the hidden fields will be used by quick edit
|
49 |
|
50 |
+
?>
|
51 |
<?php echo esc_html( $display ); ?>
|
52 |
<span id="expirationdate_year-<?php echo $id; ?>" style="display: none;"><?php echo $year; ?></span>
|
53 |
<span id="expirationdate_month-<?php echo $id; ?>" style="display: none;"><?php echo $month; ?></span>
|
views/how-to-expire.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
|
6 |
if ( ! isset( $name ) ) {
|
7 |
return false;
|
@@ -13,23 +13,23 @@ if ( ! isset( $type ) ) {
|
|
13 |
$type = '';
|
14 |
}
|
15 |
|
16 |
-
|
17 |
if ( empty( $type ) && isset( $opts['post_type'] ) ) {
|
18 |
$type = $opts['post_type'];
|
19 |
}
|
20 |
|
21 |
-
|
22 |
?>
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
<?php if ( $type !== 'page' ) { ?>
|
31 |
<option value="category" <?php echo $selected === 'category' ? 'selected="selected"' : ''; ?>><?php _e( 'Category: Replace', 'post-expirator' ); ?></option>
|
32 |
<option value="category-add" <?php echo $selected === 'category-add' ? 'selected="selected"' : ''; ?>><?php _e( 'Category: Add', 'post-expirator' ); ?></option>
|
33 |
<option value="category-remove" <?php echo $selected === 'category-remove' ? 'selected="selected"' : ''; ?>><?php _e( 'Category: Remove', 'post-expirator' ); ?></option>
|
34 |
-
<?php } ?>
|
35 |
-
|
1 |
<?php
|
2 |
+
// @TODO remove extract
|
3 |
+
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
|
4 |
+
extract( $opts );
|
5 |
|
6 |
if ( ! isset( $name ) ) {
|
7 |
return false;
|
13 |
$type = '';
|
14 |
}
|
15 |
|
16 |
+
// maybe settings have not been configured
|
17 |
if ( empty( $type ) && isset( $opts['post_type'] ) ) {
|
18 |
$type = $opts['post_type'];
|
19 |
}
|
20 |
|
21 |
+
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
22 |
?>
|
23 |
+
<select name="<?php echo $name; ?>" id="<?php echo $id; ?>" class="pe-howtoexpire">
|
24 |
+
<option value="draft" <?php echo $selected === 'draft' ? 'selected="selected"' : ''; ?>><?php _e( 'Draft', 'post-expirator' ); ?></option>
|
25 |
+
<option value="delete" <?php echo $selected === 'delete' ? 'selected="selected"' : ''; ?>><?php _e( 'Delete', 'post-expirator' ); ?></option>
|
26 |
+
<option value="trash" <?php echo $selected === 'trash' ? 'selected="selected"' : ''; ?>><?php _e( 'Trash', 'post-expirator' ); ?></option>
|
27 |
+
<option value="private" <?php echo $selected === 'private' ? 'selected="selected"' : ''; ?>><?php _e( 'Private', 'post-expirator' ); ?></option>
|
28 |
+
<option value="stick" <?php echo $selected === 'stick' ? 'selected="selected"' : ''; ?>><?php _e( 'Stick', 'post-expirator' ); ?></option>
|
29 |
+
<option value="unstick" <?php echo $selected === 'unstick' ? 'selected="selected"' : ''; ?>><?php _e( 'Unstick', 'post-expirator' ); ?></option>
|
30 |
+
<?php if ( $type !== 'page' ) { ?>
|
31 |
<option value="category" <?php echo $selected === 'category' ? 'selected="selected"' : ''; ?>><?php _e( 'Category: Replace', 'post-expirator' ); ?></option>
|
32 |
<option value="category-add" <?php echo $selected === 'category-add' ? 'selected="selected"' : ''; ?>><?php _e( 'Category: Add', 'post-expirator' ); ?></option>
|
33 |
<option value="category-remove" <?php echo $selected === 'category-remove' ? 'selected="selected"' : ''; ?>><?php _e( 'Category: Remove', 'post-expirator' ); ?></option>
|
34 |
+
<?php } ?>
|
35 |
+
</select>
|
views/menu-defaults.php
CHANGED
@@ -1,131 +1,168 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
<?php
|
8 |
-
foreach ( $types as $type ) {
|
9 |
-
$post_type_object = get_post_type_object( $type );
|
10 |
-
echo '<fieldset>';
|
11 |
-
echo "<legend> {$post_type_object->labels->singular_name} </legend>";
|
12 |
-
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
|
13 |
-
|
14 |
-
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
15 |
-
if ( isset( $defaults['autoEnable'] ) && $defaults['autoEnable'] == 1 ) {
|
16 |
-
$expiredautoenabled = 'checked = "checked"';
|
17 |
-
$expiredautodisabled = '';
|
18 |
-
} else {
|
19 |
-
$expiredautoenabled = '';
|
20 |
-
$expiredautodisabled = 'checked = "checked"';
|
21 |
-
}
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
} else {
|
35 |
-
$expiredactivemetadisabled = '';
|
36 |
-
$expiredactivemetaenabled = 'checked = "checked"';
|
37 |
-
}
|
38 |
-
}
|
39 |
-
if ( ! isset( $defaults['taxonomy'] ) ) {
|
40 |
-
$defaults['taxonomy'] = false;
|
41 |
-
}
|
42 |
-
if ( ! isset( $defaults['emailnotification'] ) ) {
|
43 |
-
$defaults['emailnotification'] = '';
|
44 |
-
}
|
45 |
-
if ( ! isset( $defaults['default-expire-type'] ) ) {
|
46 |
-
$defaults['default-expire-type'] = '';
|
47 |
-
}
|
48 |
-
?>
|
49 |
-
<table class="form-table">
|
50 |
-
<tr valign="top">
|
51 |
-
<th scope="row"><label for="expirationdate_activemeta-<?php echo $type; ?>"><?php _e( 'Active', 'post-expirator' ); ?></label></th>
|
52 |
-
<td>
|
53 |
-
<input type="radio" name="expirationdate_activemeta-<?php echo $type; ?>" id="expirationdate_activemeta-true-<?php echo $type; ?>" value="active" <?php echo $expiredactivemetaenabled; ?>/> <label for="expirationdate_activemeta-true-<?php echo $type; ?>"><?php _e( 'Active', 'post-expirator' ); ?></label>
|
54 |
-
|
55 |
-
<input type="radio" name="expirationdate_activemeta-<?php echo $type; ?>" id="expirationdate_activemeta-false-<?php echo $type; ?>" value="inactive" <?php echo $expiredactivemetadisabled; ?>/> <label for="expirationdate_activemeta-false-<?php echo $type; ?>"><?php _e( 'Inactive', 'post-expirator' ); ?></label>
|
56 |
-
<p class="description"><?php _e( 'Select whether the post expirator meta box is active for this post type.', 'post-expirator' ); ?></p>
|
57 |
-
</td>
|
58 |
-
</tr>
|
59 |
-
<tr valign="top">
|
60 |
-
<th scope="row"><label for="expirationdate_expiretype-<?php echo $type; ?>"><?php _e( 'How to expire', 'post-expirator' ); ?></label></th>
|
61 |
-
<td>
|
62 |
-
<?php _postexpirator_expire_type( array('name' => 'expirationdate_expiretype-' . $type, 'selected' => ( isset( $defaults['expireType'] ) ? $defaults['expireType'] : '' ) ) ); ?>
|
63 |
-
<p class="description"><?php _e( 'Select the default expire action for the post type.', 'post-expirator' ); ?></p>
|
64 |
-
</td>
|
65 |
-
</tr>
|
66 |
-
<tr valign="top">
|
67 |
-
<th scope="row"><label for="expirationdate_autoenable-<?php echo $type; ?>"><?php _e( 'Auto-Enable?', 'post-expirator' ); ?></label></th>
|
68 |
-
<td>
|
69 |
-
<input type="radio" name="expirationdate_autoenable-<?php echo $type; ?>" id="expirationdate_autoenable-true-<?php echo $type; ?>" value="1" <?php echo $expiredautoenabled; ?>/> <label for="expirationdate_autoenable-true-<?php echo $type; ?>"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
|
70 |
-
|
71 |
-
<input type="radio" name="expirationdate_autoenable-<?php echo $type; ?>" id="expirationdate_autoenable-false-<?php echo $type; ?>" value="0" <?php echo $expiredautodisabled; ?>/> <label for="expirationdate_autoenable-false-<?php echo $type; ?>"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
|
72 |
-
<p class="description"><?php _e( 'Select whether the post expirator is enabled for all new posts.', 'post-expirator' ); ?></p>
|
73 |
-
</td>
|
74 |
-
</tr>
|
75 |
-
<tr valign="top">
|
76 |
-
<th scope="row"><label for="expirationdate_taxonomy-<?php echo $type; ?>"><?php _e( 'Taxonomy (hierarchical)', 'post-expirator' ); ?></label></th>
|
77 |
-
<td>
|
78 |
-
<?php echo _postexpirator_taxonomy( array('type' => $type, 'name' => 'expirationdate_taxonomy-' . $type, 'selected' => $defaults['taxonomy']) ); ?>
|
79 |
-
</td>
|
80 |
-
</tr>
|
81 |
-
<tr valign="top">
|
82 |
-
<th scope="row"><label for="expirationdate_emailnotification-<?php echo $type; ?>"><?php _e( 'Who to notify', 'post-expirator' ); ?></label></th>
|
83 |
-
<td>
|
84 |
-
<input class="large-text" type="text" name="expirationdate_emailnotification-<?php echo $type; ?>" id="expirationdate_emailnotification-<?php echo $type; ?>" value="<?php echo $defaults['emailnotification']; ?>" />
|
85 |
-
<p class="description"><?php _e( 'Enter a comma separate list of emails that you would like to be notified when the post expires.', 'post-expirator' ); ?></p>
|
86 |
-
</td>
|
87 |
-
</tr>
|
88 |
-
<?php
|
89 |
-
$values = array(
|
90 |
-
'' => __( 'None', 'post-expirator' ),
|
91 |
-
'inherit' => __( 'Inherit from General Settings', 'post-expirator' ),
|
92 |
-
'custom' => __( 'Custom', 'post-expirator' ),
|
93 |
-
'publish' => __( 'Publish Time', 'post-expirator' ),
|
94 |
-
);
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
if ( $defaults['default-expire-type'] === 'custom' ) {
|
99 |
-
$show = 'block';
|
100 |
-
$customDate = $defaults['default-custom-date'];
|
101 |
-
}
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
}
|
|
|
127 |
?>
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<form method="post">
|
2 |
+
<?php wp_nonce_field( 'postexpirator_menu_defaults', '_postExpiratorMenuDefaults_nonce' ); ?>
|
3 |
+
<h3><?php _e( 'Default Expiration Values', 'post-expirator' ); ?></h3>
|
4 |
|
5 |
+
<p><?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' ); ?></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
<?php
|
8 |
+
foreach ( $types as $type ) {
|
9 |
+
$post_type_object = get_post_type_object( $type );
|
10 |
+
echo '<fieldset>';
|
11 |
+
echo "<legend> {$post_type_object->labels->singular_name} </legend>";
|
12 |
+
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $type ) );
|
13 |
|
14 |
+
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
|
15 |
+
if ( isset( $defaults['autoEnable'] ) && $defaults['autoEnable'] == 1 ) {
|
16 |
+
$expiredautoenabled = 'checked = "checked"';
|
17 |
+
$expiredautodisabled = '';
|
18 |
+
} else {
|
19 |
+
$expiredautoenabled = '';
|
20 |
+
$expiredautodisabled = 'checked = "checked"';
|
21 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
$expiredactivemetaenabled = '';
|
24 |
+
$expiredactivemetadisabled = 'checked = "checked"';
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
// if settings are not configured, show the metabox by default only for posts and pages
|
27 |
+
if ( ! isset( $defaults['activeMetaBox'] ) && in_array( $type, array( 'post', 'page' ), true ) ) {
|
28 |
+
$expiredactivemetaenabled = 'checked = "checked"';
|
29 |
+
$expiredactivemetadisabled = '';
|
30 |
+
} elseif ( isset( $defaults['activeMetaBox'] ) ) {
|
31 |
+
if ( $defaults['activeMetaBox'] === 'inactive' ) {
|
32 |
+
$expiredactivemetaenabled = '';
|
33 |
+
$expiredactivemetadisabled = 'checked = "checked"';
|
34 |
+
} else {
|
35 |
+
$expiredactivemetadisabled = '';
|
36 |
+
$expiredactivemetaenabled = 'checked = "checked"';
|
37 |
+
}
|
38 |
+
}
|
39 |
+
if ( ! isset( $defaults['taxonomy'] ) ) {
|
40 |
+
$defaults['taxonomy'] = false;
|
41 |
+
}
|
42 |
+
if ( ! isset( $defaults['emailnotification'] ) ) {
|
43 |
+
$defaults['emailnotification'] = '';
|
44 |
+
}
|
45 |
+
if ( ! isset( $defaults['default-expire-type'] ) ) {
|
46 |
+
$defaults['default-expire-type'] = '';
|
47 |
+
}
|
48 |
+
?>
|
49 |
+
<table class="form-table">
|
50 |
+
<tr valign="top">
|
51 |
+
<th scope="row"><label
|
52 |
+
for="expirationdate_activemeta-<?php echo $type; ?>"><?php _e( 'Active', 'post-expirator' ); ?></label>
|
53 |
+
</th>
|
54 |
+
<td>
|
55 |
+
<input type="radio" name="expirationdate_activemeta-<?php echo $type; ?>"
|
56 |
+
id="expirationdate_activemeta-true-<?php echo $type; ?>"
|
57 |
+
value="active" <?php echo $expiredactivemetaenabled; ?>/> <label
|
58 |
+
for="expirationdate_activemeta-true-<?php echo $type; ?>"><?php _e( 'Active', 'post-expirator' ); ?></label>
|
59 |
+
|
60 |
+
<input type="radio" name="expirationdate_activemeta-<?php echo $type; ?>"
|
61 |
+
id="expirationdate_activemeta-false-<?php echo $type; ?>"
|
62 |
+
value="inactive" <?php echo $expiredactivemetadisabled; ?>/> <label
|
63 |
+
for="expirationdate_activemeta-false-<?php echo $type; ?>"><?php _e( 'Inactive', 'post-expirator' ); ?></label>
|
64 |
+
<p class="description"><?php _e( 'Select whether the post expirator meta box is active for this post type.', 'post-expirator' ); ?></p>
|
65 |
+
</td>
|
66 |
+
</tr>
|
67 |
+
<tr valign="top">
|
68 |
+
<th scope="row"><label
|
69 |
+
for="expirationdate_expiretype-<?php echo $type; ?>"><?php _e( 'How to expire', 'post-expirator' ); ?></label>
|
70 |
+
</th>
|
71 |
+
<td>
|
72 |
+
<?php _postexpirator_expire_type( array( 'name' => 'expirationdate_expiretype-' . $type,
|
73 |
+
'selected' => ( isset( $defaults['expireType'] ) ? $defaults['expireType'] : '' )
|
74 |
+
) ); ?>
|
75 |
+
<p class="description"><?php _e( 'Select the default expire action for the post type.', 'post-expirator' ); ?></p>
|
76 |
+
</td>
|
77 |
+
</tr>
|
78 |
+
<tr valign="top">
|
79 |
+
<th scope="row"><label
|
80 |
+
for="expirationdate_autoenable-<?php echo $type; ?>"><?php _e( 'Auto-Enable?', 'post-expirator' ); ?></label>
|
81 |
+
</th>
|
82 |
+
<td>
|
83 |
+
<input type="radio" name="expirationdate_autoenable-<?php echo $type; ?>"
|
84 |
+
id="expirationdate_autoenable-true-<?php echo $type; ?>"
|
85 |
+
value="1" <?php echo $expiredautoenabled; ?>/> <label
|
86 |
+
for="expirationdate_autoenable-true-<?php echo $type; ?>"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
|
87 |
+
|
88 |
+
<input type="radio" name="expirationdate_autoenable-<?php echo $type; ?>"
|
89 |
+
id="expirationdate_autoenable-false-<?php echo $type; ?>"
|
90 |
+
value="0" <?php echo $expiredautodisabled; ?>/> <label
|
91 |
+
for="expirationdate_autoenable-false-<?php echo $type; ?>"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
|
92 |
+
<p class="description"><?php _e( 'Select whether the post expirator is enabled for all new posts.', 'post-expirator' ); ?></p>
|
93 |
+
</td>
|
94 |
+
</tr>
|
95 |
+
<tr valign="top">
|
96 |
+
<th scope="row"><label
|
97 |
+
for="expirationdate_taxonomy-<?php echo $type; ?>"><?php _e( 'Taxonomy (hierarchical)', 'post-expirator' ); ?></label>
|
98 |
+
</th>
|
99 |
+
<td>
|
100 |
+
<?php echo _postexpirator_taxonomy( array( 'type' => $type,
|
101 |
+
'name' => 'expirationdate_taxonomy-' . $type,
|
102 |
+
'selected' => $defaults['taxonomy']
|
103 |
+
) ); ?>
|
104 |
+
</td>
|
105 |
+
</tr>
|
106 |
+
<tr valign="top">
|
107 |
+
<th scope="row"><label
|
108 |
+
for="expirationdate_emailnotification-<?php echo $type; ?>"><?php _e( 'Who to notify', 'post-expirator' ); ?></label>
|
109 |
+
</th>
|
110 |
+
<td>
|
111 |
+
<input class="large-text" type="text" name="expirationdate_emailnotification-<?php echo $type; ?>"
|
112 |
+
id="expirationdate_emailnotification-<?php echo $type; ?>"
|
113 |
+
value="<?php echo $defaults['emailnotification']; ?>"/>
|
114 |
+
<p class="description"><?php _e( 'Enter a comma separate list of emails that you would like to be notified when the post expires.', 'post-expirator' ); ?></p>
|
115 |
+
</td>
|
116 |
+
</tr>
|
117 |
+
<?php
|
118 |
+
$values = array(
|
119 |
+
'' => __( 'None', 'post-expirator' ),
|
120 |
+
'inherit' => __( 'Inherit from General Settings', 'post-expirator' ),
|
121 |
+
'custom' => __( 'Custom', 'post-expirator' ),
|
122 |
+
'publish' => __( 'Publish Time', 'post-expirator' ),
|
123 |
+
);
|
124 |
|
125 |
+
$show = 'none';
|
126 |
+
$customDate = '';
|
127 |
+
if ( $defaults['default-expire-type'] === 'custom' ) {
|
128 |
+
$show = 'block';
|
129 |
+
$customDate = $defaults['default-custom-date'];
|
130 |
}
|
131 |
+
|
132 |
?>
|
133 |
+
|
134 |
+
<tr valign="top">
|
135 |
+
<th scope="row"><label
|
136 |
+
for="expired-default-date-<?php echo $type; ?>"><?php _e( 'Default Date/Time Duration', 'post-expirator' ); ?></label>
|
137 |
+
</th>
|
138 |
+
<td>
|
139 |
+
<select name="expired-default-date-<?php echo $type; ?>"
|
140 |
+
id="expired-default-date-<?php echo $type; ?>" class="pe-custom-date-toggle">
|
141 |
+
<?php foreach ( $values as $value => $label ) { ?>
|
142 |
+
<option value="<?php echo $value; ?>" <?php selected( $value, $defaults['default-expire-type'] ); ?>><?php echo $label; ?></option>
|
143 |
+
<?php } ?>
|
144 |
+
</select>
|
145 |
+
<p class="description"><?php _e( 'Set the default expiration date to be used when creating a new post of this type.' ); ?></p>
|
146 |
+
<div id="expired-custom-container-<?php echo $type; ?>" class="pe-custom-date-container"
|
147 |
+
style="display: <?php echo $show; ?>;">
|
148 |
+
<br/>
|
149 |
+
<label for="expired-custom-date-<?php echo $type; ?>"><?php _e( 'Custom', 'post-expirator' ); ?>
|
150 |
+
:</label>
|
151 |
+
<input type="text" value="<?php echo $customDate; ?>"
|
152 |
+
name="expired-custom-date-<?php echo $type; ?>"
|
153 |
+
id="expired-custom-date-<?php echo $type; ?>"/>
|
154 |
+
<p class="description"><?php echo sprintf( __( 'Set the custom value to use for the default expiration date. For information on formatting, see %1$s. For example, you could enter %2$s+1 month%3$s or %4$s+1 week 2 days 4 hours 2 seconds%5$s or %6$snext Thursday%7$s.', 'post-expirator' ), '<a href="http://php.net/manual/en/function.strtotime.php" target="_new">PHP strtotime function</a>', '<code>', '</code>', '<code>', '</code>', '<code>', '</code>' ); ?></p>
|
155 |
+
</div>
|
156 |
+
|
157 |
+
</td>
|
158 |
+
</tr>
|
159 |
+
</table>
|
160 |
+
</fieldset>
|
161 |
+
<?php
|
162 |
+
}
|
163 |
+
?>
|
164 |
+
<p class="submit">
|
165 |
+
<input type="submit" name="expirationdateSaveDefaults" class="button-primary"
|
166 |
+
value="<?php _e( 'Save Changes', 'post-expirator' ); ?>"/>
|
167 |
+
</p>
|
168 |
+
</form>
|
views/menu-diagnostics.php
CHANGED
@@ -1,51 +1,54 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
11 |
<input type="submit" class="button" name="debugging-disable" id="debugging-disable" value="(' . __( 'Status: Enabled', 'post-expirator' ) . ') ' . __( 'Disable Debugging', 'post-expirator' ) . '" />
|
12 |
<br/><a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=viewdebug' ) . '">' . __( 'View Debug Logs', 'post-expirator' ) . '</a>';
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
<?php
|
50 |
$cron = _get_cron_array();
|
51 |
foreach ( $cron as $key => $value ) {
|
@@ -81,9 +84,9 @@
|
|
81 |
}
|
82 |
}
|
83 |
?>
|
84 |
-
</table>
|
85 |
-
</div>
|
86 |
-
</td>
|
87 |
-
</tr>
|
88 |
</table>
|
89 |
-
|
|
|
|
|
|
|
|
1 |
+
<form method="post" id="postExpiratorMenuUpgrade">
|
2 |
+
<?php wp_nonce_field( 'postexpirator_menu_diagnostics', '_postExpiratorMenuDiagnostics_nonce' ); ?>
|
3 |
+
<h3><?php _e( 'Advanced Diagnostics', 'post-expirator' ); ?></h3>
|
4 |
+
<table class="form-table">
|
5 |
+
<tr valign="top">
|
6 |
+
<th scope="row"><label for="postexpirator-log"><?php _e( 'Debug Logging', 'post-expirator' ); ?></label>
|
7 |
+
</th>
|
8 |
+
<td>
|
9 |
+
<?php
|
10 |
+
if ( POSTEXPIRATOR_DEBUG ) {
|
11 |
+
echo '
|
12 |
<input type="submit" class="button" name="debugging-disable" id="debugging-disable" value="(' . __( 'Status: Enabled', 'post-expirator' ) . ') ' . __( 'Disable Debugging', 'post-expirator' ) . '" />
|
13 |
<br/><a href="' . admin_url( 'options-general.php?page=post-expirator.php&tab=viewdebug' ) . '">' . __( 'View Debug Logs', 'post-expirator' ) . '</a>';
|
14 |
+
} else {
|
15 |
+
echo '<input type="submit" class="button" name="debugging-enable" id="debugging-enable" value="(' . __( 'Status: Disabled', 'post-expirator' ) . ') ' . __( 'Enable Debugging', 'post-expirator' ) . '" />';
|
16 |
+
}
|
17 |
+
?>
|
18 |
+
</td>
|
19 |
+
</tr>
|
20 |
+
<tr valign="top">
|
21 |
+
<th scope="row"><?php _e( 'Purge Debug Log', 'post-expirator' ); ?></th>
|
22 |
+
<td>
|
23 |
+
<input type="submit" class="button" name="purge-debug" id="purge-debug"
|
24 |
+
value="<?php _e( 'Purge Debug Log', 'post-expirator' ); ?>"/>
|
25 |
+
</td>
|
26 |
+
</tr/>
|
27 |
+
<tr valign="top">
|
28 |
+
<th scope="row"><?php _e( 'WP-Cron Status', 'post-expirator' ); ?></th>
|
29 |
+
<td>
|
30 |
+
<?php
|
31 |
+
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON === true ) {
|
32 |
+
_e( 'DISABLED', 'post-expirator' );
|
33 |
+
} else {
|
34 |
+
_e( 'ENABLED - OK', 'post-expirator' );
|
35 |
+
}
|
36 |
+
?>
|
37 |
+
</td>
|
38 |
+
</tr/>
|
39 |
+
<tr valign="top">
|
40 |
+
<th scope="row"><label for="cron-schedule"><?php _e( 'Current Cron Schedule', 'post-expirator' ); ?></label>
|
41 |
+
</th>
|
42 |
+
<td>
|
43 |
+
<p><?php _e( 'The below table will show all currently scheduled cron events with the next run time.', 'post-expirator' ); ?></p>
|
44 |
|
45 |
+
<div class="pe-scroll">
|
46 |
+
<table cellspacing="0" class="striped">
|
47 |
+
<tr>
|
48 |
+
<th style="width: 30%"><?php _e( 'Date', 'post-expirator' ); ?></th>
|
49 |
+
<th style="width: 30%;"><?php _e( 'Event', 'post-expirator' ); ?></th>
|
50 |
+
<th style="width: 30%;"><?php _e( 'Arguments / Schedule', 'post-expirator' ); ?></th>
|
51 |
+
</tr>
|
52 |
<?php
|
53 |
$cron = _get_cron_array();
|
54 |
foreach ( $cron as $key => $value ) {
|
84 |
}
|
85 |
}
|
86 |
?>
|
|
|
|
|
|
|
|
|
87 |
</table>
|
88 |
+
</div>
|
89 |
+
</td>
|
90 |
+
</tr>
|
91 |
+
</table>
|
92 |
+
</form>
|
views/menu-general.php
CHANGED
@@ -1,194 +1,270 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
21 |
if ( $expireddisplayfooter == 0 ) {
|
22 |
$expireddisplayfooterdisabled = 'checked="checked"';
|
23 |
} elseif ( $expireddisplayfooter == 1 ) {
|
24 |
$expireddisplayfooterenabled = 'checked="checked"';
|
25 |
}
|
26 |
|
27 |
-
|
28 |
-
|
29 |
if ( $expiredemailnotification == 0 ) {
|
30 |
$expiredemailnotificationdisabled = 'checked="checked"';
|
31 |
} elseif ( $expiredemailnotification == 1 ) {
|
32 |
$expiredemailnotificationenabled = 'checked="checked"';
|
33 |
}
|
34 |
|
35 |
-
|
36 |
-
|
37 |
if ( $expiredemailnotificationadmins == 0 ) {
|
38 |
$expiredemailnotificationadminsdisabled = 'checked="checked"';
|
39 |
} elseif ( $expiredemailnotificationadmins == 1 ) {
|
40 |
$expiredemailnotificationadminsenabled = 'checked="checked"';
|
41 |
}
|
42 |
|
|
|
|
|
43 |
?>
|
44 |
-
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
<
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
<
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
<
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
<
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
|
96 |
echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
|
97 |
$walker = new Walker_PostExpirator_Category_Checklist();
|
98 |
-
wp_terms_checklist( 0, array(
|
|
|
|
|
|
|
|
|
|
|
99 |
echo '</ul>';
|
100 |
echo '</div>';
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
<
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
<
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
191 |
</form>
|
192 |
|
193 |
<?php
|
194 |
-
|
1 |
<?php
|
2 |
+
// phpcs:disable WordPress.NamingConventions.ValidVariableName.InterpolatedVariableNotSnakeCase
|
3 |
+
// phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
|
4 |
|
5 |
+
// Get Option
|
6 |
+
$expirationdateDefaultDateFormat = get_option( 'expirationdateDefaultDateFormat', POSTEXPIRATOR_DATEFORMAT );
|
7 |
+
$expirationdateDefaultTimeFormat = get_option( 'expirationdateDefaultTimeFormat', POSTEXPIRATOR_TIMEFORMAT );
|
8 |
+
$expireddisplayfooter = get_option( 'expirationdateDisplayFooter', POSTEXPIRATOR_FOOTERDISPLAY );
|
9 |
+
$expiredemailnotification = get_option( 'expirationdateEmailNotification', POSTEXPIRATOR_EMAILNOTIFICATION );
|
10 |
+
$expiredemailnotificationadmins = get_option( 'expirationdateEmailNotificationAdmins', POSTEXPIRATOR_EMAILNOTIFICATIONADMINS );
|
11 |
+
$expiredemailnotificationlist = get_option( 'expirationdateEmailNotificationList', '' );
|
12 |
+
$expirationdateFooterContents = get_option( 'expirationdateFooterContents', POSTEXPIRATOR_FOOTERCONTENTS );
|
13 |
+
$expirationdateFooterStyle = get_option( 'expirationdateFooterStyle', POSTEXPIRATOR_FOOTERSTYLE );
|
14 |
+
$expirationdateDefaultDate = get_option( 'expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT );
|
15 |
+
$expirationdateDefaultDateCustom = get_option( 'expirationdateDefaultDateCustom' );
|
16 |
|
17 |
+
$categories = get_option( 'expirationdateCategoryDefaults' );
|
18 |
|
19 |
+
$expireddisplayfooterenabled = '';
|
20 |
+
$expireddisplayfooterdisabled = '';
|
21 |
if ( $expireddisplayfooter == 0 ) {
|
22 |
$expireddisplayfooterdisabled = 'checked="checked"';
|
23 |
} elseif ( $expireddisplayfooter == 1 ) {
|
24 |
$expireddisplayfooterenabled = 'checked="checked"';
|
25 |
}
|
26 |
|
27 |
+
$expiredemailnotificationenabled = '';
|
28 |
+
$expiredemailnotificationdisabled = '';
|
29 |
if ( $expiredemailnotification == 0 ) {
|
30 |
$expiredemailnotificationdisabled = 'checked="checked"';
|
31 |
} elseif ( $expiredemailnotification == 1 ) {
|
32 |
$expiredemailnotificationenabled = 'checked="checked"';
|
33 |
}
|
34 |
|
35 |
+
$expiredemailnotificationadminsenabled = '';
|
36 |
+
$expiredemailnotificationadminsdisabled = '';
|
37 |
if ( $expiredemailnotificationadmins == 0 ) {
|
38 |
$expiredemailnotificationadminsdisabled = 'checked="checked"';
|
39 |
} elseif ( $expiredemailnotificationadmins == 1 ) {
|
40 |
$expiredemailnotificationadminsenabled = 'checked="checked"';
|
41 |
}
|
42 |
|
43 |
+
$user_roles = wp_roles()->get_names();
|
44 |
+
$plugin_facade = PostExpirator_Facade::getInstance();
|
45 |
?>
|
46 |
+
<p><?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' ); ?></p>
|
47 |
|
48 |
+
<h3><?php _e( 'Shortcode', 'post-expirator' ); ?></h3>
|
49 |
+
<p><?php echo sprintf( __( 'Valid %s attributes:', 'post-expirator' ), '<code>[postexpirator]</code>' ); ?></p>
|
50 |
+
<ul class="pe-list">
|
51 |
+
<li>
|
52 |
+
<p><?php echo sprintf( __( '%1$s - valid options are %2$sfull%3$s (default), %4$sdate%5$s, %6$stime%7$s', 'post-expirator' ), '<code>type</code>', '<code>', '</code>', '<code>', '</code>', '<code>', '</code>' ); ?></p>
|
53 |
+
</li>
|
54 |
+
<li>
|
55 |
+
<p><?php echo sprintf( __( '%s - format set here will override the value set on the settings page', 'post-expirator' ), '<code>dateformat</code>' ); ?></p>
|
56 |
+
</li>
|
57 |
+
<li>
|
58 |
+
<p><?php echo sprintf( __( '%s - format set here will override the value set on the settings page', 'post-expirator' ), '<code>timeformat</code>' ); ?></p>
|
59 |
+
</li>
|
60 |
+
</ul>
|
61 |
+
<hr/>
|
62 |
|
63 |
+
<form method="post" id="expirationdate_save_options">
|
64 |
+
<?php wp_nonce_field( 'postexpirator_menu_general', '_postExpiratorMenuGeneral_nonce' ); ?>
|
65 |
+
<h3><?php _e( 'Defaults', 'post-expirator' ); ?></h3>
|
66 |
+
<table class="form-table">
|
67 |
+
<tr valign="top">
|
68 |
+
<th scope="row"><label
|
69 |
+
for="expired-default-date-format"><?php _e( 'Date Format', 'post-expirator' ); ?></label>
|
70 |
+
</th>
|
71 |
+
<td>
|
72 |
+
<input type="text" name="expired-default-date-format" id="expired-default-date-format"
|
73 |
+
value="<?php echo $expirationdateDefaultDateFormat; ?>" size="25"/> <span
|
74 |
+
class="description">(<?php echo date_i18n( "$expirationdateDefaultDateFormat" ); ?>)</span>
|
75 |
+
<p class="description"><?php echo sprintf( __( 'The default format to use when displaying the expiration date within a post using the shortcode or within the footer. For information on valid formatting options, see: %s.', 'post-expirator' ), '<a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>' ); ?></p>
|
76 |
+
</td>
|
77 |
+
</tr>
|
78 |
+
<tr valign="top">
|
79 |
+
<th scope="row"><label
|
80 |
+
for="expired-default-time-format"><?php _e( 'Time Format', 'post-expirator' ); ?></label>
|
81 |
+
</th>
|
82 |
+
<td>
|
83 |
+
<input type="text" name="expired-default-time-format" id="expired-default-time-format"
|
84 |
+
value="<?php echo $expirationdateDefaultTimeFormat; ?>" size="25"/> <span
|
85 |
+
class="description">(<?php echo date_i18n( "$expirationdateDefaultTimeFormat" ); ?>)</span>
|
86 |
+
<p class="description"><?php echo sprintf( __( 'The default format to use when displaying the expiration time within a post using the shortcode or within the footer. For information on valid formatting options, see: %s.', 'post-expirator' ), '<a href="http://us2.php.net/manual/en/function.date.php" target="_blank">PHP Date Function</a>' ); ?>
|
87 |
+
</td>
|
88 |
+
</tr>
|
89 |
+
<tr valign="top">
|
90 |
+
<th scope="row"><label
|
91 |
+
for="expired-default-expiration-date"><?php _e( 'Default Date/Time Duration', 'post-expirator' ); ?></label>
|
92 |
+
</th>
|
93 |
+
<td>
|
94 |
+
<select name="expired-default-expiration-date" id="expired-default-expiration-date"
|
95 |
+
class="pe-custom-date-toggle">
|
96 |
+
<option value="null" <?php echo ( $expirationdateDefaultDate == 'null' ) ? ' selected="selected"' : ''; ?>><?php _e( 'None', 'post-expirator' ); ?></option>
|
97 |
+
<option value="custom" <?php echo ( $expirationdateDefaultDate == 'custom' ) ? ' selected="selected"' : ''; ?>><?php _e( 'Custom', 'post-expirator' ); ?></option>
|
98 |
+
<option value="publish" <?php echo ( $expirationdateDefaultDate == 'publish' ) ? ' selected="selected"' : ''; ?>><?php _e( 'Post/Page Publish Time', 'post-expirator' ); ?></option>
|
99 |
+
</select>
|
100 |
+
<p class="description"><?php _e( 'Set the default expiration date to be used when creating new posts and pages. Defaults to none.', 'post-expirator' ); ?></p>
|
101 |
+
<?php $show = ( $expirationdateDefaultDate == 'custom' ) ? 'block' : 'none'; ?>
|
102 |
+
<div id="expired-custom-container" style="display: <?php echo $show; ?>;"
|
103 |
+
class="pe-custom-date-container">
|
104 |
+
<br/>
|
105 |
+
<label for="expired-custom-expiration-date"><?php _e( 'Custom', 'post-expirator' ); ?>:</label>
|
106 |
+
<input type="text" value="<?php echo $expirationdateDefaultDateCustom; ?>"
|
107 |
+
name="expired-custom-expiration-date" id="expired-custom-expiration-date"/>
|
108 |
+
<p class="description"><?php echo sprintf( __( 'Set the custom value to use for the default expiration date. For information on formatting, see %1$s. For example, you could enter %2$s+1 month%3$s or %4$s+1 week 2 days 4 hours 2 seconds%5$s or %6$snext Thursday%7$s.', 'post-expirator' ), '<a href="http://php.net/manual/en/function.strtotime.php" target="_new">PHP strtotime function</a>', '<code>', '</code>', '<code>', '</code>', '<code>', '</code>' ); ?></p>
|
109 |
+
</div>
|
110 |
+
</td>
|
111 |
+
</tr>
|
112 |
+
<tr valign="top">
|
113 |
+
<th scope="row"><?php _e( 'Default Expiration Category', 'post-expirator' ); ?></th>
|
114 |
+
<td>
|
115 |
+
<?php
|
116 |
echo '<div class="wp-tab-panel" id="post-expirator-cat-list">';
|
117 |
echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">';
|
118 |
$walker = new Walker_PostExpirator_Category_Checklist();
|
119 |
+
wp_terms_checklist( 0, array(
|
120 |
+
'taxonomy' => 'category',
|
121 |
+
'walker' => $walker,
|
122 |
+
'selected_cats' => $categories,
|
123 |
+
'checked_ontop' => false
|
124 |
+
) );
|
125 |
echo '</ul>';
|
126 |
echo '</div>';
|
127 |
+
?>
|
128 |
+
<p class="description"><?php _e( 'Sets the default expiration category for the post.', 'post-expirator' ); ?></p>
|
129 |
+
</td>
|
130 |
+
</tr>
|
131 |
+
</table>
|
132 |
|
133 |
+
<h3><?php _e( 'Expiration Email Notification', 'post-expirator' ); ?></h3>
|
134 |
+
<p class="description"><?php _e( 'Whenever a post expires, an email can be sent to alert users of the expiration.', 'post-expirator' ); ?></p>
|
135 |
+
<table class="form-table">
|
136 |
+
<tr valign="top">
|
137 |
+
<th scope="row"><?php _e( 'Enable Email Notification?', 'post-expirator' ); ?></th>
|
138 |
+
<td>
|
139 |
+
<input type="radio" name="expired-email-notification" id="expired-email-notification-true"
|
140 |
+
value="1" <?php echo $expiredemailnotificationenabled; ?>/> <label
|
141 |
+
for="expired-email-notification-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
|
142 |
+
|
143 |
+
<input type="radio" name="expired-email-notification" id="expired-email-notification-false"
|
144 |
+
value="0" <?php echo $expiredemailnotificationdisabled; ?>/> <label
|
145 |
+
for="expired-email-notification-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
|
146 |
+
<p class="description"><?php _e( 'This will enable or disable the send of email notification on post expiration.', 'post-expirator' ); ?></p>
|
147 |
+
</td>
|
148 |
+
</tr>
|
149 |
+
<tr valign="top">
|
150 |
+
<th scope="row"><?php _e( 'Include Blog Administrators?', 'post-expirator' ); ?></th>
|
151 |
+
<td>
|
152 |
+
<input type="radio" name="expired-email-notification-admins"
|
153 |
+
id="expired-email-notification-admins-true"
|
154 |
+
value="1" <?php echo $expiredemailnotificationadminsenabled; ?>/> <label
|
155 |
+
for="expired-email-notification-admins-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
|
156 |
+
|
157 |
+
<input type="radio" name="expired-email-notification-admins"
|
158 |
+
id="expired-email-notification-admins-false"
|
159 |
+
value="0" <?php echo $expiredemailnotificationadminsdisabled; ?>/> <label
|
160 |
+
for="expired-email-notification-admins-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
|
161 |
+
<p class="description"><?php _e( 'This will include all users with the role of "Administrator" in the post expiration email.', 'post-expirator' ); ?></p>
|
162 |
+
</td>
|
163 |
+
</tr>
|
164 |
+
<tr valign="top">
|
165 |
+
<th scope="row"><label
|
166 |
+
for="expired-email-notification-list"><?php _e( 'Who to notify', 'post-expirator' ); ?></label>
|
167 |
+
</th>
|
168 |
+
<td>
|
169 |
+
<input class="large-text" type="text" name="expired-email-notification-list"
|
170 |
+
id="expired-email-notification-list" value="<?php echo $expiredemailnotificationlist; ?>"/>
|
171 |
+
<p class="description"><?php _e( 'Enter a comma separate 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' ); ?></p>
|
172 |
+
</td>
|
173 |
+
</tr>
|
174 |
+
</table>
|
175 |
|
176 |
+
<h3><?php _e( 'Post Footer Display', 'post-expirator' ); ?></h3>
|
177 |
+
<p class="description"><?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>
|
178 |
+
<table class="form-table">
|
179 |
+
<tr valign="top">
|
180 |
+
<th scope="row"><?php _e( 'Show in post footer?', 'post-expirator' ); ?></th>
|
181 |
+
<td>
|
182 |
+
<input type="radio" name="expired-display-footer" id="expired-display-footer-true"
|
183 |
+
value="1" <?php echo $expireddisplayfooterenabled; ?>/> <label
|
184 |
+
for="expired-display-footer-true"><?php _e( 'Enabled', 'post-expirator' ); ?></label>
|
185 |
+
|
186 |
+
<input type="radio" name="expired-display-footer" id="expired-display-footer-false"
|
187 |
+
value="0" <?php echo $expireddisplayfooterdisabled; ?>/> <label
|
188 |
+
for="expired-display-footer-false"><?php _e( 'Disabled', 'post-expirator' ); ?></label>
|
189 |
+
<p class="description"><?php _e( 'This will enable or disable displaying the post expiration date in the post footer.', 'post-expirator' ); ?></p>
|
190 |
+
</td>
|
191 |
+
</tr>
|
192 |
+
<tr valign="top">
|
193 |
+
<th scope="row"><label
|
194 |
+
for="expired-footer-contents"><?php _e( 'Footer Contents', 'post-expirator' ); ?></label>
|
195 |
+
</th>
|
196 |
+
<td>
|
197 |
+
<textarea id="expired-footer-contents" name="expired-footer-contents" rows="3"
|
198 |
+
cols="50"><?php echo $expirationdateFooterContents; ?></textarea>
|
199 |
+
<p class="description"><?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' ); ?></p>
|
200 |
+
<ul class="pe-list">
|
201 |
+
<li><p class="description">EXPIRATIONFULL
|
202 |
+
-> <?php echo date_i18n( "$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat" ); ?></p>
|
203 |
+
</li>
|
204 |
+
<li><p class="description">EXPIRATIONDATE
|
205 |
+
-> <?php echo date_i18n( "$expirationdateDefaultDateFormat" ); ?></p></li>
|
206 |
+
<li><p class="description">EXPIRATIONTIME
|
207 |
+
-> <?php echo date_i18n( "$expirationdateDefaultTimeFormat" ); ?></p></li>
|
208 |
+
</ul>
|
209 |
+
</td>
|
210 |
+
</tr>
|
211 |
+
<tr valign="top">
|
212 |
+
<th scope="row"><label
|
213 |
+
for="expired-footer-style"><?php _e( 'Footer Style', 'post-expirator' ); ?></label></th>
|
214 |
+
<td>
|
215 |
+
<input type="text" name="expired-footer-style" id="expired-footer-style"
|
216 |
+
value="<?php echo $expirationdateFooterStyle; ?>" size="25"/>
|
217 |
+
(<span style="<?php echo $expirationdateFooterStyle; ?>"><?php _e( 'This post will expire on', 'post-expirator' ); ?><?php echo date_i18n( "$expirationdateDefaultDateFormat $expirationdateDefaultTimeFormat" ); ?></span>)
|
218 |
+
<p class="description"><?php _e( 'The inline css which will be used to style the footer text.', 'post-expirator' ); ?></p>
|
219 |
+
</td>
|
220 |
+
</tr>
|
221 |
+
</table>
|
222 |
|
223 |
+
<h3><?php _e( 'Advanced Options', 'post-expirator' ); ?></h3>
|
224 |
+
<p class="description"><?php _e( 'Please do not update anything here unless you know what it entails. For advanced users only.', 'post-expirator' ); ?></p>
|
225 |
+
<?php
|
226 |
+
$gutenberg = get_option( 'expirationdateGutenbergSupport', 1 );
|
227 |
+
?>
|
228 |
+
<table class="form-table">
|
229 |
+
<tr valign="top">
|
230 |
+
<th scope="row"><?php _e( 'Block Editor Support', 'post-expirator' ); ?></th>
|
231 |
+
<td>
|
232 |
+
<input type="radio" name="gutenberg-support" id="gutenberg-support-enabled"
|
233 |
+
value="1" <?php echo intval( $gutenberg ) === 1 ? 'checked' : ''; ?>/> <label
|
234 |
+
for="gutenberg-support-enabled"><?php _e( 'Show Gutenberg style box', 'post-expirator' ); ?></label>
|
235 |
+
|
236 |
+
<input type="radio" name="gutenberg-support" id="gutenberg-support-disabled"
|
237 |
+
value="0" <?php echo intval( $gutenberg ) === 0 ? 'checked' : ''; ?>/> <label
|
238 |
+
for="gutenberg-support-disabled"><?php _e( 'Show Classic Editor style box', 'post-expirator' ); ?></label>
|
239 |
+
<p class="description"><?php _e( 'Toggle between native support for the Block Editor or the backward compatible Classic Editor style metabox.', 'post-expirator' ); ?></p>
|
240 |
+
</td>
|
241 |
+
</tr>
|
242 |
+
<tr valign="top">
|
243 |
+
<th scope="row">
|
244 |
+
<?php _e( 'Choose which user roles can use Post Expirator', 'post-expirator' ); ?>
|
245 |
+
</th>
|
246 |
+
<td class="pe-checklist">
|
247 |
+
<?php foreach ( $user_roles as $role_name => $role_label ) : ?>
|
248 |
+
<label for="allow-user-role-<?php echo esc_attr( $role_name ); ?>">
|
249 |
+
<input type="checkbox"
|
250 |
+
id="allow-user-role-<?php echo esc_attr( $role_name ); ?>"
|
251 |
+
name="allow-user-roles[]"
|
252 |
+
<?php if ( 'administrator' === $role_name ) : echo 'disabled="disabled"'; endif; ?>
|
253 |
+
value="<?php echo esc_attr( $role_name ); ?>"
|
254 |
+
<?php if ( $plugin_facade->user_role_can_expire_posts( $role_name ) ) : ?>checked="checked"<?php endif; ?>
|
255 |
+
/>
|
256 |
+
<?php echo esc_html( $role_label ); ?>
|
257 |
+
</label>
|
258 |
+
<?php endforeach; ?>
|
259 |
+
</td>
|
260 |
+
</tr>
|
261 |
+
</table>
|
262 |
|
263 |
+
<p class="submit">
|
264 |
+
<input type="submit" name="expirationdateSave" class="button-primary"
|
265 |
+
value="<?php _e( 'Save Changes', 'post-expirator' ); ?>"/>
|
266 |
+
</p>
|
267 |
</form>
|
268 |
|
269 |
<?php
|
270 |
+
// phpcs:enable
|
views/quick-edit.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
<div class="inline-edit-group">
|
5 |
-
<label
|
6 |
-
<input name="enable-expirationdate" type="checkbox"
|
7 |
<span class=""><?php _e( 'Enable Post Expiration', 'post-expirator' ); ?></span>
|
8 |
</label>
|
9 |
<fieldset class="inline-edit-date">
|
@@ -13,32 +13,38 @@
|
|
13 |
<label>
|
14 |
<span class="screen-reader-text"><?php _e( 'Month', 'post-expirator' ); ?></span>
|
15 |
<select name="expirationdate_month">
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
</select>
|
26 |
</label>
|
27 |
<label>
|
28 |
<span class="screen-reader-text"><?php _e( 'Day', 'post-expirator' ); ?></span>
|
29 |
-
<input name="expirationdate_day" value="" size="2" maxlength="2" autocomplete="off"
|
30 |
-
|
|
|
31 |
<label>
|
32 |
<span class="screen-reader-text"><?php _e( 'Year', 'post-expirator' ); ?></span>
|
33 |
-
<input name="expirationdate_year" value="" size="4" maxlength="4" autocomplete="off"
|
34 |
-
|
|
|
35 |
<label>
|
36 |
<span class="screen-reader-text"><?php _e( 'Hour', 'post-expirator' ); ?></span>
|
37 |
-
<input name="expirationdate_hour" value="" size="2" maxlength="2" autocomplete="off"
|
|
|
38 |
</label> :
|
39 |
<label>
|
40 |
<span class="screen-reader-text"><?php _e( 'Minute', 'post-expirator' ); ?></span>
|
41 |
-
<input name="expirationdate_minute" value="" size="2" maxlength="2" autocomplete="off"
|
|
|
42 |
</label>
|
43 |
</div>
|
44 |
<div>
|
@@ -47,8 +53,11 @@
|
|
47 |
<span class="screen-reader-text"><?php _e( 'How to expire', 'post-expirator' ); ?></span>
|
48 |
</legend>
|
49 |
<?php
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
52 |
?>
|
53 |
</div>
|
54 |
<div class="pe-category-list">
|
@@ -56,13 +65,17 @@
|
|
56 |
<span class="title"><?php echo $tax_label; ?></span>
|
57 |
<span class="screen-reader-text"><?php _e( 'Expiration Categories', 'post-expirator' ); ?></span>
|
58 |
</legend>
|
59 |
-
<ul id="categorychecklist"
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
66 |
</ul>
|
67 |
</div>
|
68 |
|
@@ -70,5 +83,5 @@
|
|
70 |
<input name="expirationdate_quickedit" value="true" type="hidden"/>
|
71 |
</fieldset>
|
72 |
</div>
|
73 |
-
|
74 |
-
|
1 |
+
<div style="clear:both"></div>
|
2 |
+
<fieldset class="inline-edit-col-left post-expirator-quickedit">
|
3 |
+
<div class="inline-edit-col">
|
4 |
<div class="inline-edit-group">
|
5 |
+
<label>
|
6 |
+
<input name="enable-expirationdate" type="checkbox"/>
|
7 |
<span class=""><?php _e( 'Enable Post Expiration', 'post-expirator' ); ?></span>
|
8 |
</label>
|
9 |
<fieldset class="inline-edit-date">
|
13 |
<label>
|
14 |
<span class="screen-reader-text"><?php _e( 'Month', 'post-expirator' ); ?></span>
|
15 |
<select name="expirationdate_month">
|
16 |
+
<?php
|
17 |
+
for ( $x = 1; $x <= 12; $x ++ ) {
|
18 |
+
$now = mktime( 0, 0, 0, $x, 1, date_i18n( 'Y' ) );
|
19 |
+
$monthNumeric = date_i18n( 'm', $now );
|
20 |
+
$monthStr = date_i18n( 'M', $now );
|
21 |
+
?>
|
22 |
+
<option value="<?php echo $monthNumeric; ?>"
|
23 |
+
data-text="<?php echo $monthStr; ?>"><?php echo $monthNumeric; ?>
|
24 |
+
-<?php echo $monthStr; ?></option>
|
25 |
+
<?php } ?>
|
26 |
|
27 |
</select>
|
28 |
</label>
|
29 |
<label>
|
30 |
<span class="screen-reader-text"><?php _e( 'Day', 'post-expirator' ); ?></span>
|
31 |
+
<input name="expirationdate_day" value="" size="2" maxlength="2" autocomplete="off"
|
32 |
+
type="text" placeholder="<?php echo date( 'd' ); ?>">
|
33 |
+
</label>,
|
34 |
<label>
|
35 |
<span class="screen-reader-text"><?php _e( 'Year', 'post-expirator' ); ?></span>
|
36 |
+
<input name="expirationdate_year" value="" size="4" maxlength="4" autocomplete="off"
|
37 |
+
type="text" placeholder="<?php echo date( 'Y' ); ?>">
|
38 |
+
</label> @
|
39 |
<label>
|
40 |
<span class="screen-reader-text"><?php _e( 'Hour', 'post-expirator' ); ?></span>
|
41 |
+
<input name="expirationdate_hour" value="" size="2" maxlength="2" autocomplete="off"
|
42 |
+
type="text" placeholder="00">
|
43 |
</label> :
|
44 |
<label>
|
45 |
<span class="screen-reader-text"><?php _e( 'Minute', 'post-expirator' ); ?></span>
|
46 |
+
<input name="expirationdate_minute" value="" size="2" maxlength="2" autocomplete="off"
|
47 |
+
type="text" placeholder="00">
|
48 |
</label>
|
49 |
</div>
|
50 |
<div>
|
53 |
<span class="screen-reader-text"><?php _e( 'How to expire', 'post-expirator' ); ?></span>
|
54 |
</legend>
|
55 |
<?php
|
56 |
+
$defaults = get_option( 'expirationdateDefaults' . ucfirst( $post_type ) );
|
57 |
+
_postexpirator_expire_type( array( 'name' => 'expirationdate_expiretype',
|
58 |
+
'selected' => empty( $defaults ) ? 'draft' : $defaults['expireType'],
|
59 |
+
'post_type' => $post_type
|
60 |
+
) );
|
61 |
?>
|
62 |
</div>
|
63 |
<div class="pe-category-list">
|
65 |
<span class="title"><?php echo $tax_label; ?></span>
|
66 |
<span class="screen-reader-text"><?php _e( 'Expiration Categories', 'post-expirator' ); ?></span>
|
67 |
</legend>
|
68 |
+
<ul id="categorychecklist"
|
69 |
+
class="list:category categorychecklist cat-checklist category-checklist">
|
70 |
+
<?php
|
71 |
+
if ( ! empty( $taxonomy ) ) {
|
72 |
+
$walker = new Walker_PostExpirator_Category_Checklist();
|
73 |
+
wp_terms_checklist( 0, array( 'taxonomy' => $taxonomy,
|
74 |
+
'walker' => $walker,
|
75 |
+
'checked_ontop' => false
|
76 |
+
) );
|
77 |
+
}
|
78 |
+
?>
|
79 |
</ul>
|
80 |
</div>
|
81 |
|
83 |
<input name="expirationdate_quickedit" value="true" type="hidden"/>
|
84 |
</fieldset>
|
85 |
</div>
|
86 |
+
</div>
|
87 |
+
</fieldset>
|
views/tabs.php
CHANGED
@@ -1,20 +1,24 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
?>
|
4 |
|
5 |
<div class="wrap">
|
6 |
<h2><?php __( 'Post Expirator Options', 'post-expirator' ); ?></h2>
|
7 |
<div id="pe-settings-tabs">
|
8 |
<nav class="nav-tab-wrapper postexpirator-nav-tab-wrapper">
|
9 |
-
<a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=general' ); ?>"
|
10 |
-
|
11 |
-
<a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=
|
12 |
-
<?php
|
13 |
-
<a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=
|
14 |
-
<?php
|
|
|
|
|
|
|
|
|
15 |
</nav>
|
16 |
-
|
17 |
-
|
18 |
|
19 |
</div>
|
20 |
</div>
|
1 |
<?php
|
2 |
+
$current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( wp_unslash( $_GET['tab'] ) );
|
3 |
?>
|
4 |
|
5 |
<div class="wrap">
|
6 |
<h2><?php __( 'Post Expirator Options', 'post-expirator' ); ?></h2>
|
7 |
<div id="pe-settings-tabs">
|
8 |
<nav class="nav-tab-wrapper postexpirator-nav-tab-wrapper">
|
9 |
+
<a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=general' ); ?>"
|
10 |
+
class="pe-tab nav-tab <?php echo( $current_tab === 'general' ? 'nav-tab-active' : '' ); ?>"><?php _e( 'General Settings', 'post-expirator' ); ?></a>
|
11 |
+
<a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=defaults' ); ?>"
|
12 |
+
class="pe-tab nav-tab <?php echo( $current_tab === 'defaults' ? 'nav-tab-active' : '' ); ?>"><?php _e( 'Post Types', 'post-expirator' ); ?></a>
|
13 |
+
<a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=diagnostics' ); ?>"
|
14 |
+
class="pe-tab nav-tab <?php echo( $current_tab === 'diagnostics' ? 'nav-tab-active' : '' ); ?>"><?php _e( 'Diagnostics', 'post-expirator' ); ?></a>
|
15 |
+
<?php if ( POSTEXPIRATOR_DEBUG ) { ?>
|
16 |
+
<a href="<?php echo admin_url( 'options-general.php?page=post-expirator.php&tab=viewdebug' ); ?>"
|
17 |
+
class="pe-tab nav-tab <?php echo( $current_tab === 'viewdebug' ? 'nav-tab-active' : '' ); ?>"><?php _e( 'View Debug Logs', 'post-expirator' ); ?></a>
|
18 |
+
<?php } ?>
|
19 |
</nav>
|
20 |
+
|
21 |
+
<?php echo $html; ?>
|
22 |
|
23 |
</div>
|
24 |
</div>
|