-
Notifications
You must be signed in to change notification settings - Fork 9
/
revisionary.php
287 lines (235 loc) · 9.53 KB
/
revisionary.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
287
<?php
/**
* Plugin Name: PublishPress Revisions
* Plugin URI: https://publishpress.com/revisionary/
* Description: Maintain published content with teamwork and precision using the Revisions model to submit, approve and schedule changes.
* Author: PublishPress
* Author URI: https://publishpress.com
* Version: 3.5.15
* Text Domain: revisionary
* Domain Path: /languages/
* Min WP Version: 5.5
* Requires PHP: 7.2.5
*
* 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\Revisions
* @author PublishPress
* @copyright Copyright (C) 2024 PublishPress. All rights reserved.
*
**/
if (!defined('ABSPATH')) exit; // Exit if accessed directly
// Temporary usage within this module only; avoids multiple instances of version string
global $pp_revisions_version;
$pp_revisions_version = '3.5.15';
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 Revisions 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 Revisions requires WordPress version %s or higher.',
esc_html($min_wp_version)
);
echo '</p></div>';
}
}
);
}
if ($invalid_php_version || $invalid_wp_version) {
return;
}
$revisionary_pro_active = false;
global $revisionary_loaded_by_pro;
$revisionary_loaded_by_pro = strpos(str_replace('\\', '/', __FILE__), 'vendor/publishpress/');
// Detect separate Pro plugin activation, but not self-activation (this file loaded in vendor library by Pro)
if (false === $revisionary_loaded_by_pro) {
foreach ((array)get_option('active_plugins') as $plugin_file) {
if (false !== strpos($plugin_file, 'revisionary-pro.php')) {
$revisionary_pro_active = true;
break;
}
}
if (!$revisionary_pro_active && is_multisite()) {
foreach (array_keys((array)get_site_option('active_sitewide_plugins')) as $plugin_file) {
if (false !== strpos($plugin_file, 'revisionary-pro.php')) {
$revisionary_pro_active = true;
break;
}
}
}
if ($revisionary_pro_active) {
add_filter(
'plugin_row_meta',
function($links, $file)
{
if ($file == plugin_basename(__FILE__)) {
$links[]= __('<strong>This plugin can be deleted.</strong>', 'revisionary');
}
return $links;
},
10, 2
);
add_action(
'admin_notices',
function () {
if (current_user_can('activate_plugins')) {
echo '<div class="notice notice-error"><p>'
. 'Revisions Pro requires the free plugin (PublishPress Revisions) to be deactivated.'
. '</p></div>';
}
}
);
return;
}
}
if ( isset($_SERVER['SCRIPT_NAME']) && strpos( esc_url_raw($_SERVER['SCRIPT_NAME']), 'p-admin/index-extra.php' ) || strpos( esc_url_raw($_SERVER['SCRIPT_NAME']), 'p-admin/update.php' ) ) {
return;
}
if (! defined('REVISIONS_INTERNAL_VENDORPATH')) {
define('REVISIONS_INTERNAL_VENDORPATH', __DIR__ . '/lib/vendor');
}
if (!defined('REVISIONARY_FILE') && !$revisionary_loaded_by_pro) {
$includeFileRelativePath = REVISIONS_INTERNAL_VENDORPATH . '/publishpress/publishpress-instance-protection/include.php';
if (file_exists($includeFileRelativePath)) {
require_once $includeFileRelativePath;
}
if (class_exists('PublishPressInstanceProtection\\Config')) {
$pluginCheckerConfig = new PublishPressInstanceProtection\Config();
$pluginCheckerConfig->pluginSlug = 'revisionary';
$pluginCheckerConfig->pluginFolder = 'revisionary';
$pluginCheckerConfig->pluginName = 'PublishPress Revisions';
$pluginChecker = new PublishPressInstanceProtection\InstanceChecker($pluginCheckerConfig);
}
if (! class_exists('ComposerAutoloaderInitRevisionary')
&& file_exists(REVISIONS_INTERNAL_VENDORPATH . '/autoload.php')
) {
require_once REVISIONS_INTERNAL_VENDORPATH . '/autoload.php';
}
}
if (!defined('REVISIONARY_FILE') && (!$revisionary_pro_active || $revisionary_loaded_by_pro)) {
define('REVISIONARY_FILE', __FILE__);
add_action(
'init',
function() {
global $pp_revisions_version;
if (!function_exists('revisionary')) {
require_once(dirname(__FILE__).'/functions.php');
pp_revisions_plugin_updated($pp_revisions_version);
}
},
2
);
// register these functions before any early exits so normal activation/deactivation can still run with RS_DEBUG
register_activation_hook(__FILE__, function()
{
global $pp_revisions_version;
if (!function_exists('revisionary')) {
require_once(dirname(__FILE__).'/functions.php');
}
pp_revisions_plugin_updated($pp_revisions_version);
pp_revisions_plugin_activation();
}
);
register_deactivation_hook(__FILE__, function()
{
if (!function_exists('rvy_init')) {
require_once( dirname(__FILE__).'/rvy_init.php');
}
if (!rvy_is_plugin_active('revisionary-pro/revisionary-pro.php')) {
pp_revisions_plugin_deactivation();
}
}
);
// negative priority to precede any default WP action handlers
function revisionary_load() {
global $pp_revisions_version;
define('PUBLISHPRESS_REVISIONS_VERSION', $pp_revisions_version);
if ( ! defined( 'RVY_VERSION' ) ) {
define( 'RVY_VERSION', PUBLISHPRESS_REVISIONS_VERSION ); // back compat
}
define ('COLS_ALL_RVY', 0);
define ('COL_ID_RVY', 1);
if ( defined('RS_DEBUG') ) {
include_once( dirname(__FILE__).'/lib/debug.php');
add_action( 'admin_footer', 'rvy_echo_usage_message' );
} else
include_once( dirname(__FILE__).'/lib/debug_shell.php');
require_once( dirname(__FILE__).'/defaults_rvy.php');
// === awp_is_mu() function definition and usage: must be executed in this order, and before any checks of IS_MU_RVY constant ===
require_once( dirname(__FILE__).'/lib/agapetry_wp_core_lib.php');
define( 'IS_MU_RVY', awp_is_mu() );
// -------------------------------------------
require_once( dirname(__FILE__).'/content-roles_rvy.php');
if ( is_admin() || defined('XMLRPC_REQUEST') ) {
require_once( dirname(__FILE__).'/lib/agapetry_wp_admin_lib.php');
// skip WP version check and init operations when a WP plugin auto-update is in progress
if (isset($_SERVER['SCRIPT_NAME']) && false !== strpos(esc_url_raw($_SERVER['SCRIPT_NAME']), 'update.php') )
return;
}
require_once( dirname(__FILE__).'/classes/PublishPress/Revisionary.php');
require_once( dirname(__FILE__).'/rvy_init.php'); // Contains activate, deactivate, init functions. Adds mod_rewrite_rules.
require_once( dirname(__FILE__).'/functions.php');
// avoid lockout in case of editing plugin via wp-admin
if ( defined('RS_DEBUG') && is_admin() && isset($_SERVER['REQUEST_URI']) && ( strpos( urldecode(esc_url_raw($_SERVER['REQUEST_URI'])), 'p-admin/plugin-editor.php' ) || strpos( urldecode(esc_url_raw($_SERVER['REQUEST_URI'])), 'p-admin/plugins.php' ) ) && false === strpos( esc_url_raw($_SERVER['REQUEST_URI']), 'activate' ) )
return;
define('RVY_ABSPATH', __DIR__);
if (is_admin() && !defined('PUBLISHPRESS_REVISIONS_PRO_VERSION')) {
require_once(__DIR__ . '/includes/CoreAdmin.php');
new \PublishPress\Revisions\CoreAdmin();
}
rvy_refresh_options_sitewide();
// since sequence of set_current_user and init actions seems unreliable, make sure our current_user is loaded first
add_action('init', 'rvy_init', 1);
if (!defined('IFRAME_REQUEST')) {
add_action('init', 'rvy_add_revisor_custom_caps', 99);
add_action('wp_loaded', 'rvy_add_revisor_custom_caps', 99);
}
add_action('init', 'rvy_configuration_late_init', PHP_INT_MAX - 1);
revisionary();
}
// negative priority to precede any default WP action handlers
if ($revisionary_loaded_by_pro) {
revisionary_load(); // Pro support
} else {
add_action('plugins_loaded', 'revisionary_load', -10);
}
}