forked from 10up/distributor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distributor.php
206 lines (189 loc) · 5.63 KB
/
distributor.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
<?php
/**
* Plugin Name: Distributor
* Plugin URI: https://github.com/10up/distributor
* Update URI: https://distributorplugin.com
* Description: Makes it easy to distribute and reuse content across your websites, whether inside of a multisite or across the web.
* Version: 2.0.3
* Requires at least: 5.7
* Requires PHP: 7.4
* Author: 10up Inc.
* Author URI: https://distributorplugin.com
* License: GPLv2 or later
* Text Domain: distributor
* Domain Path: /lang/
*
* @package distributor
*
* Developer note: This file is used to test whether the user's server supports
* the minimum software requirements for this plugin prior to bootstrapping.
*
* Unlike the rest of the plugin, this file needs to be compatible with PHP 5.6
* and WordPress 4.7.0.
*/
namespace Distributor;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
define( 'DT_VERSION', '2.0.3' );
define( 'DT_PLUGIN_FILE', preg_replace( '#^.*plugins/(.*)$#i', '$1', __FILE__ ) );
define( 'DT_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'DT_PLUGIN_FULL_FILE', __FILE__ );
// Define a constant if we're network activated to allow plugin to respond accordingly.
$active_plugins = get_site_option( 'active_sitewide_plugins' );
if ( is_multisite() && isset( $active_plugins[ plugin_basename( __FILE__ ) ] ) ) {
define( 'DT_IS_NETWORK', true );
} else {
define( 'DT_IS_NETWORK', false );
}
/**
* Get the minimum version of WordPress required by this plugin.
*
* @since 2.0.0
*
* @return string Minimum version required.
*/
function minimum_wp_requirement() {
return '5.7';
}
/**
* Get the minimum version of PHP required by this plugin.
*
* @since 2.0.0
*
* @return string Minimum version required.
*/
function minimum_php_requirement() {
return '7.4';
}
/**
* Whether WP installation meets the minimum requirements
*
* @since 2.0.0
*
* @return bool True if meets minimum requirements, false otherwise.
*/
function site_meets_wp_requirements() {
global $wp_version;
return version_compare( $wp_version, minimum_wp_requirement(), '>=' );
}
/**
* Whether PHP installation meets the minimum requirements
*
* @since 2.0.0
*
* @return bool True if meets minimum requirements, false otherwise.
*/
function site_meets_php_requirements() {
return version_compare( phpversion(), minimum_php_requirement(), '>=' );
}
/**
* Require PHP 7.4+, WP 5.7+ - throw an error if the plugin is activated on an older version.
*/
register_activation_hook(
__FILE__,
function() {
if (
! site_meets_wp_requirements() &&
! site_meets_php_requirements()
) {
wp_die(
sprintf(
/* translators: %1$s: Minimum required PHP version, %2$s: Minimum required WordPress version */
esc_html__( 'Distributor requires PHP version %1$s or later and WordPress version %2$s or later. Please upgrade your software or disable the plugin.', 'distributor' ),
esc_html( minimum_php_requirement() ),
esc_html( minimum_wp_requirement() )
),
esc_html__( 'Error Activating', 'distributor' )
);
} elseif ( ! site_meets_wp_requirements() ) {
wp_die(
sprintf(
/* translators: %s: Minimum required WordPress version */
esc_html__( 'Distributor requires WordPress version %s or later. Please upgrade WordPress or disable the plugin.', 'distributor' ),
esc_html( minimum_wp_requirement() )
),
esc_html__( 'Error Activating', 'distributor' )
);
} elseif ( ! site_meets_php_requirements() ) {
wp_die(
sprintf(
/* translators: %s: Minimum required PHP version */
esc_html__( 'Distributor requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'distributor' ),
esc_html( minimum_php_requirement() )
),
esc_html__( 'Error Activating', 'distributor' )
);
}
}
);
add_action(
'plugins_loaded',
function() {
if ( site_meets_wp_requirements() && site_meets_php_requirements() ) {
// Do nothing, everything is fine.
return;
}
add_action(
'admin_notices',
function() {
if (
! site_meets_wp_requirements() &&
! site_meets_php_requirements()
) {
?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: %1$s: Minimum required PHP version, %2$s: Minimum required WordPress version */
esc_html__( 'Distributor requires PHP version %1$s or later and WordPress version %2$s or later. Please upgrade your software or disable the plugin.', 'distributor' ),
esc_html( minimum_php_requirement() ),
esc_html( minimum_wp_requirement() )
);
?>
</p>
</div>
<?php
return;
}
if ( ! site_meets_wp_requirements() ) {
?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: %s: Minimum required WordPress version */
esc_html__( 'Distributor requires WordPress version %s or later. Please upgrade WordPress or disable the plugin.', 'distributor' ),
esc_html( minimum_wp_requirement() )
);
?>
</p>
</div>
<?php
return;
}
if ( ! site_meets_php_requirements() ) {
?>
<div class="notice notice-error">
<p>
<?php
printf(
/* translators: %s: Minimum required PHP version */
esc_html__( 'Distributor requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'distributor' ),
esc_html( minimum_php_requirement() )
);
?>
</p>
</div>
<?php
return;
}
}
);
}
);
if ( ! site_meets_wp_requirements() || ! site_meets_php_requirements() ) {
return;
}
require_once __DIR__ . '/includes/bootstrap.php';