-
Notifications
You must be signed in to change notification settings - Fork 0
/
publishpress-statuses.php
286 lines (244 loc) · 10.5 KB
/
publishpress-statuses.php
1
2
3
4
5
6
7
8
9
10
11
12
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
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
96
97
98
99
100
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
/**
* Plugin Name: PublishPress Statuses
* Plugin URI: https://publishpress.com/statuses
* Description: Manage and create post statuses to customize your editorial workflow
* Version: 1.0.9
* Author: PublishPress
* Author URI: https://publishpress.com/
* Text Domain: publishpress-statuses
* Domain Path: /languages/
* Requires at least: 5.5
* Requires PHP: 7.2.5
* License: GPLv3
*
* Copyright (c) 2024 PublishPress
*
* GNU General Public License, Free Software Foundation <https://www.gnu.org/licenses/gpl-3.0.html>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package PublishPress Statuses
* @author PublishPress
* @copyright Copyright (C) 2024 PublishPress. All rights reserved.
* @license GNU General Public License version 3
* @link https://publishpress.com/
*
**/
use PublishPress_Statuses\LibInstanceProtection;
use PublishPress_Statuses\LibWordPressReviews;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
global $wp_version;
$min_php_version = '7.2.5';
$min_wp_version = '5.5';
$invalid_php_version = version_compare(phpversion(), $min_php_version, '<');
$invalid_wp_version = version_compare($wp_version, $min_wp_version, '<');
// If the PHP version is not compatible, terminate the plugin execution and show an admin notice.
if (is_admin() && $invalid_php_version) {
add_action(
'admin_notices',
function () use ($min_php_version) {
if (current_user_can('activate_plugins')) {
echo '<div class="notice notice-error"><p>';
printf(
'PublishPress Statuses requires PHP version %s or higher.',
esc_html($min_php_version)
);
echo '</p></div>';
}
}
);
}
// If the WP version is not compatible, terminate the plugin execution and show an admin notice.
if (is_admin() && $invalid_wp_version) {
add_action(
'admin_notices',
function () use ($min_wp_version) {
if (current_user_can('activate_plugins')) {
echo '<div class="notice notice-error"><p>';
printf(
'PublishPress Statuses requires WordPress version %s or higher.',
esc_html($min_wp_version)
);
echo '</p></div>';
}
}
);
}
if ($invalid_php_version || $invalid_wp_version) {
return;
}
add_action('plugins_loaded', function() {
if (!defined('PUBLISHPRESS_STATUSES_VERSION')) {
if (defined('PUBLISHPRESS_VERSION') && version_compare(PUBLISHPRESS_VERSION, '4.0-beta4', '<')) {
add_action('admin_notices', function() {
?>
<div class="notice error">
<p><?php printf(
// translators: %s is a version number
esc_html__('To use PublishPress Statuses, please upgrade PublishPress Planner to version %s or higher.', 'publishpress-statuses'),
'4.0-beta4'
);
?></p>
</div>
<?php
});
$interrupt_load = true;
}
if (defined('PRESSPERMIT_PRO_VERSION') && version_compare(PRESSPERMIT_PRO_VERSION, '4.0-beta8', '<')) {
add_action('admin_notices', function() {
?>
<div class="notice error">
<p><?php printf(
// translators: %s is a version number
esc_html__('To use PublishPress Statuses, please upgrade PublishPress Permissions Pro to version %s or higher.', 'publishpress-statuses'),
'4.0-beta8'
);
?></p>
</div>
<?php
});
$interrupt_load = true;
}
if (defined('PUBLISHPRESS_CAPS_PRO_VERSION') && version_compare(PUBLISHPRESS_CAPS_PRO_VERSION, '2.11-beta2', '<')) {
add_action('admin_notices', function() {
?>
<div class="notice error">
<p><?php printf(
// translators: %s is a version number
esc_html__('To use PublishPress Statuses, please upgrade PublishPress Capabilities Pro to version %s or higher.', 'publishpress-statuses'),
'2.11-beta2'
);
?></p>
</div>
<?php
});
$interrupt_load = true;
}
global $pagenow;
if (is_admin() && isset($pagenow) && ('customize.php' == $pagenow)) {
$interrupt_load = true;
}
if (empty($interrupt_load)) {
define('PUBLISHPRESS_STATUSES_VERSION', '1.0.9');
define('PUBLISHPRESS_STATUSES_URL', trailingslashit(plugins_url('', __FILE__)));
define('PUBLISHPRESS_STATUSES_DIR', __DIR__);
require_once(__DIR__ . '/lib/PublishPress_Functions.php');
require_once(__DIR__ . '/lib/publishpress-module/Module_Base.php');
new \PublishPress\PPP_Module_Base();
require_once(__DIR__ . '/LibInstanceProtection.php');
new LibInstanceProtection();
// Disable Reviews library until other plugins are updated to fix conflict
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
/*
if (!class_exists('\PublishPress\WordPressReviews\ReviewsController')) {
include_once PUBLISHPRESS_STATUSES_DIR. '/lib/vendor/publishpress/wordpress-reviews/ReviewsController.php';
}
if (class_exists('\PublishPress\WordPressReviews\ReviewsController')) {
$reviews = new \PublishPress\WordPressReviews\ReviewsController(
'publishpress-statuses',
'PublishPress Statuses',
PUBLISHPRESS_STATUSES_URL . 'common/img/permissions-wp-logo.jpg'
);
add_filter('publishpress_wp_reviews_display_banner_publishpress-statuses', [$this, 'shouldDisplayBanner']);
$reviews->init();
}
*/
require_once(__DIR__ . '/PublishPress_Statuses.php');
PublishPress_Statuses::instance();
if (defined('PRESSPERMIT_VERSION')) {
class_alias('\PressShack\LibWP', '\PublishPress_Statuses\PWP');
if (class_exists('\PublishPress\Permissions\Statuses')) {
class_alias('\PublishPress\Permissions\Statuses', '\PublishPress_Statuses\PPS');
}
}
add_action(
'init',
function() {
@load_plugin_textdomain('publishpress-statuses', false, dirname(plugin_basename(__FILE__)) . '/languages');
},
5
);
if (!class_exists('PP_Custom_Status')
&& (defined('PRESSPERMIT_VERSION') || (!defined('PUBLISHPRESS_VERSION') || version_compare(PUBLISHPRESS_VERSION, '4.0', '<')))
) {
class_alias('\PublishPress_Statuses', '\PP_Custom_Status');
}
}
}
}, -5);
register_activation_hook(
__FILE__,
function() {
update_option('publishpress_statuses_activate', true);
}
);
register_deactivation_hook(
__FILE__,
function()
{
delete_transient('publishpress_statuses_maintenance');
delete_option('publishpress_statuses_planner_import_gmt');
if (!get_option('publishpress_version') || defined('PUBLISHPRESS_STATUSES_NO_PLANNER_BACK_COMPAT')) {
return;
}
// Restore archived PublishPress Planner 3.x term descriptions (with encoded status properties), in case it will be re-activated
if ($archived_term_descriptions = get_option('pp_statuses_archived_term_properties')) {
// Use hardcoded taxonomy string here because class PublishPress_Statuses is not loaded
$terms = get_terms('post_status', ['hide_empty' => false]);
if (is_array($terms)) {
foreach ($terms as $term) {
if (!empty($archived_term_descriptions[$term->term_id])) {
$description = $archived_term_descriptions[$term->term_id];
if (preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $description)
&& (strlen($description) > 80) && (false === strpos($description, ' '))
) {
// Use hardcoded taxonomy string here because class PublishPress_Statuses is not loaded
wp_update_term($term->term_id, 'post_status', ['description' => $description]);
}
}
}
}
}
// Set post_types option storage value back to "on" / "off"
$options = get_option('publishpress_custom_status_options');
if (is_object($options) && isset($options->enabled)) {
if ($options->enabled) {
$options->enabled = 'on';
$do_option_update = true;
} else {
$options->enabled = 'off';
$do_option_update = true;
}
}
if (is_object($options) && !empty($options->post_types)) {
foreach ($options->post_types as $post_type => $val) {
if ($val) {
$options->post_types[$post_type] = 'on';
$do_option_update = true;
} else {
$options->post_types[$post_type] = 'off';
$do_option_update = true;
}
}
}
if (!empty($options->loaded_once)) {
unset($options->loaded_once);
$do_option_update = true;
}
if (!empty($do_option_update)) {
update_option('publishpress_custom_status_options', $options);
}
}
);