PluginProbe
Polylang / 2.1
Polylang v2.1
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/license.php +6 -190 3.02.1 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * A class to easily manage licenses for Polylang Pro and addons
8 5 *
@@ -8,62 +5,10 @@
8 5 *
9 6 * @since 1.9
10 7 */
11 8 class PLL_License {
12 - /**
13 - * Sanitized plugin name.
14 - *
15 - * @var string
16 - */
17 - public $id;
18 -
19 - /**
20 - * Plugin name.
21 - *
22 - * @var string
23 - */
24 - public $name;
25 -
26 - /**
27 - * License key.
28 - *
29 - * @var string
30 - */
31 - public $license_key;
32 -
33 - /**
34 - * License data, obtained from the API request.
35 - *
36 - * @var stdClass
37 - */
38 - public $license_data;
39 -
40 - /**
41 - * Main plugin file.
42 - *
43 - * @var string
44 - */
45 - private $file;
46 -
47 - /**
48 - * Current plugin version.
49 - *
50 - * @var string
51 - */
52 - private $version;
53 -
54 - /**
55 - * Plugin author.
56 - *
57 - * @var string
58 - */
59 - private $author;
60 -
61 - /**
62 - * API url.
63 - *
64 - * @var string.
65 - */
9 + public $id, $name, $license_key, $license_data;
10 + private $file, $version, $author;
66 11 private $api_url = 'https://polylang.pro';
67 12
68 13 /**
69 14 * Constructor
@@ -75,9 +20,9 @@
75 20 * @param string $version
76 21 * @param string $author
77 22 * @param string $api_url optional
78 23 */
79 - public function __construct( $file, $item_name, $version, $author, $api_url = null ) {
24 + function __construct( $file, $item_name, $version, $author, $api_url = null ) {
80 25 $this->id = sanitize_title( $item_name );
81 26 $this->file = $file;
82 27 $this->name = $item_name;
83 28 $this->version = $version;
@@ -84,9 +29,9 @@
84 29 $this->author = $author;
85 30 $this->api_url = empty( $api_url ) ? $this->api_url : $api_url;
86 31
87 32 $licenses = get_option( 'polylang_licenses' );
88 - $this->license_key = empty( $licenses[ $this->id ]['key'] ) ? '' : $licenses[ $this->id ]['key'];
33 + $this->license_key = empty( $licenses[ $this->id ]['key'] ) ? '' : $licenses[ $this->id ]['key'];
89 34 if ( ! empty( $licenses[ $this->id ]['data'] ) ) {
90 35 $this->license_data = $licenses[ $this->id ]['data'];
91 36 }
92 37
@@ -91,9 +36,8 @@
91 36 }
92 37
93 38 // Updater
94 39 add_action( 'admin_init', array( $this, 'auto_updater' ), 0 );
95 - add_action( 'cli_init', array( $this, 'auto_updater' ), 0 ); // For WP CLI.
96 40
97 41 // Register settings
98 42 add_filter( 'pll_settings_licenses', array( $this, 'settings' ) );
99 43
@@ -108,10 +52,8 @@
108 52 /**
109 53 * Auto updater
110 54 *
111 55 * @since 1.9
112 - *
113 - * @return void
114 56 */
115 57 public function auto_updater() {
116 58 $args = array(
117 59 'version' => $this->version,
@@ -185,20 +127,13 @@
185 127 *
186 128 * @since 1.9
187 129 *
188 130 * @param string $request check_license | activate_license | deactivate_license
189 - * @return void
190 131 */
191 132 private function api_request( $request ) {
192 133 $licenses = get_option( 'polylang_licenses' );
134 + unset( $licenses[ $this->id ], $this->license_data );
193 135
194 - if ( is_array( $licenses ) ) {
195 - unset( $licenses[ $this->id ] );
196 - } else {
197 - $licenses = array();
198 - }
199 - unset( $this->license_data );
200 -
201 136 if ( ! empty( $this->license_key ) ) {
202 137 // Data to send in our API request
203 138 $api_params = array(
204 139 'edd_action' => $request,
@@ -210,9 +145,9 @@
210 145 // Call the API
211 146 $response = wp_remote_post(
212 147 $this->api_url,
213 148 array(
214 - 'timeout' => 3,
149 + 'timeout' => 15,
215 150 'sslverify' => false,
216 151 'body' => $api_params,
217 152 )
218 153 );
@@ -231,125 +166,6 @@
231 166 }
232 167 }
233 168
234 169 update_option( 'polylang_licenses', $licenses ); // FIXME called multiple times when saving all licenses
235 - }
236 -
237 - /**
238 - * Get the html form field in a table row (one per license key) for display
239 - *
240 - * @since 2.7
241 - *
242 - * @return string
243 - */
244 - public function get_form_field() {
245 - if ( ! empty( $this->license_data ) ) {
246 - $license = $this->license_data;
247 - }
248 -
249 - $class = 'license-null';
250 - $message = '';
251 -
252 - $out = sprintf(
253 - '<td><label for="pll-licenses[%1$s]">%2$s</label></td>' .
254 - '<td><input name="licenses[%1$s]" id="pll-licenses[%1$s]" type="password" value="%3$s" class="regular-text code" />',
255 - esc_attr( $this->id ),
256 - esc_attr( $this->name ),
257 - esc_html( $this->license_key )
258 - );
259 -
260 - if ( ! empty( $license ) && is_object( $license ) ) {
261 - $now = time();
262 - $expiration = isset( $license->expires ) ? strtotime( $license->expires ) : false;
263 -
264 - // Special case: the license expired after the last check
265 - if ( $license->success && $expiration && $expiration < $now ) {
266 - $license->success = false;
267 - $license->error = 'expired';
268 - }
269 -
270 - if ( false === $license->success ) {
271 - $class = 'notice-error notice-alt';
272 -
273 - switch ( $license->error ) {
274 - case 'expired':
275 - $message = sprintf(
276 - /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */
277 - esc_html__( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ),
278 - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ),
279 - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
280 - '</a>'
281 - );
282 - break;
283 -
284 - case 'disabled':
285 - case 'revoked':
286 - $message = esc_html__( 'Your license key has been disabled.', 'polylang' );
287 - break;
288 -
289 - case 'missing':
290 - $message = sprintf(
291 - /* translators: %1$s is link start tag, %2$s is link end tag. */
292 - esc_html__( 'Invalid license. Please %1$svisit your account page%2$s and verify it.', 'polylang' ),
293 - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
294 - '</a>'
295 - );
296 - break;
297 -
298 - case 'invalid':
299 - case 'site_inactive':
300 - $message = sprintf(
301 - /* translators: %1$s is a product name, %2$s is link start tag, %3$s is link end tag. */
302 - esc_html__( 'Your %1$s license key is not active for this URL. Please %2$svisit your account page%3$s to manage your license key URLs.', 'polylang' ),
303 - esc_html( $this->name ),
304 - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
305 - '</a>'
306 - );
307 - break;
308 -
309 - case 'item_name_mismatch':
310 - /* translators: %s is a product name */
311 - $message = sprintf( esc_html__( 'This is not a %s license key.', 'polylang' ), esc_html( $this->name ) );
312 - break;
313 -
314 - case 'no_activations_left':
315 - $message = sprintf(
316 - /* translators: %1$s is link start tag, %2$s is link end tag */
317 - esc_html__( 'Your license key has reached its activation limit. %1$sView possible upgrades%2$s now.', 'polylang' ),
318 - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
319 - '</a>'
320 - );
321 - break;
322 - }
323 - } else {
324 - $class = 'license-valid';
325 -
326 - $out .= sprintf( '<button id="deactivate_%s" type="button" class="button button-secondary pll-deactivate-license">%s</button>', esc_attr( $this->id ), esc_html__( 'Deactivate', 'polylang' ) );
327 -
328 - if ( 'lifetime' === $license->expires ) {
329 - $message = esc_html__( 'The license key never expires.', 'polylang' );
330 - } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
331 - $class = 'notice-warning notice-alt';
332 - $message = sprintf(
333 - /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */
334 - esc_html__( 'Your license key will expire soon! Precisely, it will expire on %1$s. %2$sRenew your license key today!%3$s.', 'polylang' ),
335 - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ),
336 - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
337 - '</a>'
338 - );
339 - } else {
340 - $message = sprintf(
341 - /* translators: %s is a date */
342 - esc_html__( 'Your license key expires on %s.', 'polylang' ),
343 - esc_html( date_i18n( get_option( 'date_format' ), $expiration ) )
344 - );
345 - }
346 - }
347 - }
348 -
349 - if ( ! empty( $message ) ) {
350 - $out .= '<p>' . $message . '</p>';
351 - }
352 -
353 - return sprintf( '<tr id="pll-license-%s" class="%s">%s</tr>', esc_attr( $this->id ), $class, $out );
354 170 }
355 171 }