-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedd-software-licenses.php
More file actions
275 lines (242 loc) · 6.76 KB
/
edd-software-licenses.php
File metadata and controls
275 lines (242 loc) · 6.76 KB
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
<?php
/**
* Plugin Name: Easy Digital Downloads - Software Licensing
* Plugin URI: https://easydigitaldownloads.com/downloads/software-licensing/
* Description: Adds a software licensing system to Easy Digital Downloads.
* Version: 3.8.14
* Requires PHP: 7.1
* Requires at least: 5.4
* Author: Easy Digital Downloads
* Author URI: https://easydigitaldownloads.com/
* Contributors: easydigitaldownloads, mordauk, cklosows
* Text Domain: edd_sl
* Domain Path: languages
*/
if ( ! defined( 'EDD_SL_PLUGIN_DIR' ) ) {
define( 'EDD_SL_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'EDD_SL_PLUGIN_URL' ) ) {
define( 'EDD_SL_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'EDD_SL_PLUGIN_FILE' ) ) {
define( 'EDD_SL_PLUGIN_FILE', __FILE__ );
}
if ( ! defined( 'EDD_SL_VERSION' ) ) {
define( 'EDD_SL_VERSION', '3.8.14' );
}
require_once EDD_SL_PLUGIN_DIR . 'vendor/autoload.php';
require_once EDD_SL_PLUGIN_DIR . 'includes/classes/class-sl-requirements.php';
/**
* Class EDD_SL_Requirements_Check
*
* @since 3.8
*/
final class EDD_SL_Requirements_Check {
/**
* Plugin file
*
* @var string
* @since 3.8
*/
private $file;
/**
* Plugin basename
*
* @var string
* @since 3.8
*/
private $plugin_base;
/**
* Platform versions required to load Software Licensing.
*
* @var array[]
* @since 3.8
*/
private $current_requirements = array(
'php' => array(
'minimum' => '7.1',
'name' => 'PHP',
'local' => true,
),
'wp' => array(
'minimum' => '5.4',
'name' => 'WordPress',
'local' => true,
),
'easy-digital-downloads' => array(
'minimum' => '2.11',
'name' => 'Easy Digital Downloads',
'local' => true,
),
);
/**
* @var EDD_SL_Requirements
*/
private $requirements;
/**
* EDD_SL_Requirements_Check constructor.
*
* @param string $plugin_file
*/
public function __construct( $plugin_file ) {
$this->file = $plugin_file;
$this->plugin_base = plugin_basename( $this->file );
$this->requirements = new EDD_SL_Requirements( $this->current_requirements );
}
/**
* Loads the plugin if requirements have been met, otherwise
* displays "plugin not fully active" UI and exists.
*
* @since 3.8
*/
public function maybe_load() {
$this->requirements->met() ? $this->load() : $this->quit();
}
/**
* Loads Software Licensing
*
* @since 3.8
*/
private function load() {
if ( ! class_exists( 'EDD_Software_Licensing' ) ) {
require_once EDD_SL_PLUGIN_DIR . 'includes/classes/class-edd-software-licensing.php';
}
$this->maybe_install();
// Get Software Licensing running.
edd_software_licensing();
}
/**
* Installs Software Licensing if needed.
*
* @since 3.8
*/
private function maybe_install() {
if ( ! function_exists( 'edd_sl_install' ) ) {
require_once EDD_SL_PLUGIN_DIR . 'includes/install.php';
}
if ( get_option( 'edd_sl_run_install' ) ) {
// Install Software Licensing.
edd_sl_install();
// Delete this option so we don't run the install again.
delete_option( 'edd_sl_run_install' );
}
}
/**
* Adds action hooks to inject our "plugin not fully loaded" UI / text.
*
* @since 3.8
*/
private function quit() {
add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( "after_plugin_row_{$this->plugin_base}", array( $this, 'plugin_row_notice' ) );
}
/**
* Adds CSS to the admin head for our "plugin not fully loaded" UI.
*
* @since 3.8
*/
public function admin_head() {
$name = $this->unmet_requirements_name();
?>
<style id="<?php echo esc_attr( $name ); ?>">
.plugins tr[data-plugin="<?php echo esc_html( $this->plugin_base ); ?>"] th,
.plugins tr[data-plugin="<?php echo esc_html( $this->plugin_base ); ?>"] td,
.plugins .<?php echo esc_html( $name ); ?>-row th,
.plugins .<?php echo esc_html( $name ); ?>-row td {
background: #fff5f5;
}
.plugins tr[data-plugin="<?php echo esc_html( $this->plugin_base ); ?>"] th {
box-shadow: none;
}
.plugins .<?php echo esc_html( $name ); ?>-row th span {
margin-left: 6px;
color: #dc3232;
}
.plugins tr[data-plugin="<?php echo esc_html( $this->plugin_base ); ?>"] th,
.plugins .<?php echo esc_html( $name ); ?>-row th.check-column {
border-left: 4px solid #dc3232 !important;
}
.plugins .<?php echo esc_html( $name ); ?>-row .column-description p {
margin: 0;
padding: 0;
}
.plugins .<?php echo esc_html( $name ); ?>-row .column-description p:not(:last-of-type) {
margin-bottom: 8px;
}
</style>
<?php
}
/**
* Displays a notice on the plugin row about missing requirements.
*
* @since 3.8
*/
public function plugin_row_notice() {
$colspan = function_exists( 'wp_is_auto_update_enabled_for_type' ) && wp_is_auto_update_enabled_for_type( 'plugin' ) ? 2 : 1;
?>
<tr class="active <?php echo esc_attr( $this->unmet_requirements_name() ); ?>-row">
<th class="check-column">
<span class="dashicons dashicons-warning"></span>
</th>
<td class="column-primary">
<?php $this->unmet_requirements_text(); ?>
</td>
<td class="column-description" colspan="<?php echo esc_attr( $colspan ); ?>">
<?php $this->unmet_requirements_description(); ?>
</td>
</tr>
<?php
}
/**
* Plugin specific text used in CSS to identify attribute IDs and classes.
*
* @since 3.8
* @return string
*/
private function unmet_requirements_name() {
return 'edd-sl-requirements';
}
/**
* Outputs a message about the plugin not being fully active.
*
* @since 3.8
*/
private function unmet_requirements_text() {
esc_html_e( 'This plugin is not fully active.', 'edd_sl' );
}
/**
* Displays error messages for all unmet requirements.
*
* @since 3.8
*/
private function unmet_requirements_description() {
foreach ( $this->requirements->get_errors()->get_error_messages() as $message ) {
echo wpautop( wp_kses_post( $message ) );
}
}
}
/**
* Run the requirements check.
*
* This needs to be delayed until `plugins_loaded`, otherwise we won't be able to detect
* EDD install/version.
*/
add_action( 'plugins_loaded', function() {
$requirements_checker = new EDD_SL_Requirements_Check( EDD_SL_PLUGIN_FILE );
$requirements_checker->maybe_load();
} );
/**
* Adds an option flag if the installation has not yet run, to designate that we
* should run it later. The reason we do this is because when installation happens
* the requirements haven't yet been checked, and we only actually want to run the
* full installation once we have.
*
* @see edd_sl_install()
*/
register_activation_hook( EDD_SL_PLUGIN_FILE, function() {
$current_version = get_option( 'edd_sl_version' );
if ( ! $current_version ) {
update_option( 'edd_sl_run_install', time() );
}
update_option( 'edd_sl_version', EDD_SL_VERSION, false );
} );