PluginProbe
Polylang / 3.7.1
Polylang v3.7.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 +95 -36 2.73.7.1 View file →
@@ -1,5 +1,8 @@
1 1 <?php
2 +/**
3 + * @package Polylang
4 + */
2 5
3 6 /**
4 7 * A class to easily manage licenses for Polylang Pro and addons
5 8 *
@@ -5,10 +8,62 @@
5 8 *
6 9 * @since 1.9
7 10 */
8 11 class PLL_License {
9 - public $id, $name, $license_key, $license_data;
10 - private $file, $version, $author;
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|null
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 + */
11 66 private $api_url = 'https://polylang.pro';
12 67
13 68 /**
14 69 * Constructor
@@ -14,13 +69,13 @@
14 69 * Constructor
15 70 *
16 71 * @since 1.9
17 72 *
18 - * @param string $file
19 - * @param string $item_name
20 - * @param string $version
21 - * @param string $author
22 - * @param string $api_url optional
73 + * @param string $file The plugin file.
74 + * @param string $item_name The plugin name.
75 + * @param string $version The plugin version.
76 + * @param string $author Author name.
77 + * @param string $api_url Optional url of the site managing the license.
23 78 */
24 79 public function __construct( $file, $item_name, $version, $author, $api_url = null ) {
25 80 $this->id = sanitize_title( $item_name );
26 81 $this->file = $file;
@@ -28,17 +83,18 @@
28 83 $this->version = $version;
29 84 $this->author = $author;
30 85 $this->api_url = empty( $api_url ) ? $this->api_url : $api_url;
31 86
32 - $licenses = get_option( 'polylang_licenses' );
33 - $this->license_key = empty( $licenses[ $this->id ]['key'] ) ? '' : $licenses[ $this->id ]['key'];
34 - if ( ! empty( $licenses[ $this->id ]['data'] ) ) {
35 - $this->license_data = $licenses[ $this->id ]['data'];
87 + $licenses = (array) get_option( 'polylang_licenses', array() );
88 + $license = isset( $licenses[ $this->id ] ) && is_array( $licenses[ $this->id ] ) ? $licenses[ $this->id ] : array();
89 + $this->license_key = ! empty( $license['key'] ) ? (string) $license['key'] : '';
90 +
91 + if ( ! empty( $license['data'] ) ) {
92 + $this->license_data = (object) $license['data'];
36 93 }
37 94
38 95 // Updater
39 - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 );
40 - add_action( 'cli_init', array( $this, 'auto_updater' ), 0 ); // For WP CLI.
96 + $this->auto_updater();
41 97
42 98 // Register settings
43 99 add_filter( 'pll_settings_licenses', array( $this, 'settings' ) );
44 100
@@ -53,8 +109,10 @@
53 109 /**
54 110 * Auto updater
55 111 *
56 112 * @since 1.9
113 + *
114 + * @return void
57 115 */
58 116 public function auto_updater() {
59 117 $args = array(
60 118 'version' => $this->version,
@@ -67,14 +125,14 @@
67 125 new PLL_Plugin_Updater( $this->api_url, $this->file, $args );
68 126 }
69 127
70 128 /**
71 - * Registers the licence in the Settings
129 + * Registers the licence in the Settings.
72 130 *
73 131 * @since 1.9
74 132 *
75 - * @param array $items
76 - * @return array
133 + * @param PLL_License[] $items Array of objects allowing to manage a license.
134 + * @return PLL_License[]
77 135 */
78 136 public function settings( $items ) {
79 137 $items[ $this->id ] = $this;
80 138 return $items;
@@ -80,31 +138,31 @@
80 138 return $items;
81 139 }
82 140
83 141 /**
84 - * Activate the license key
142 + * Activates the license key.
85 143 *
86 144 * @since 1.9
87 145 *
88 - * @param string $license_key activation key
89 - * @return object updated $this
146 + * @param string $license_key Activation key.
147 + * @return PLL_License Updated PLL_License object.
90 148 */
91 149 public function activate_license( $license_key ) {
92 150 $this->license_key = $license_key;
93 151 $this->api_request( 'activate_license' );
94 152
95 - // Tell WordPress to look for updates
96 - set_site_transient( 'update_plugins', null );
153 + // Tell WordPress to look for updates.
154 + delete_site_transient( 'update_plugins' );
97 155 return $this;
98 156 }
99 157
100 158
101 159 /**
102 - * Deactivate the license key
160 + * Deactivates the license key.
103 161 *
104 162 * @since 1.9
105 163 *
106 - * @return object updated $this
164 + * @return PLL_License Updated PLL_License object.
107 165 */
108 166 public function deactivate_license() {
109 167 $this->api_request( 'deactivate_license' );
110 168 return $this;
@@ -110,17 +168,16 @@
110 168 return $this;
111 169 }
112 170
113 171 /**
114 - * Check if license key is valid
172 + * Checks if the license key is valid.
115 173 *
116 174 * @since 1.9
117 175 *
118 - * @return object updated $this
176 + * @return void
119 177 */
120 178 public function check_license() {
121 179 $this->api_request( 'check_license' );
122 - return $this;
123 180 }
124 181
125 182 /**
126 183 * Sends an api request to check, activate or deactivate the license
@@ -128,8 +185,9 @@
128 185 *
129 186 * @since 1.9
130 187 *
131 188 * @param string $request check_license | activate_license | deactivate_license
189 + * @return void
132 190 */
133 191 private function api_request( $request ) {
134 192 $licenses = get_option( 'polylang_licenses' );
135 193
@@ -165,11 +223,11 @@
165 223 }
166 224
167 225 // Save new license info
168 226 $licenses[ $this->id ] = array( 'key' => $this->license_key );
169 - $data = json_decode( wp_remote_retrieve_body( $response ) );
227 + $data = (object) json_decode( wp_remote_retrieve_body( $response ) );
170 228
171 - if ( 'deactivated' !== $data->license ) {
229 + if ( isset( $data->license ) && 'deactivated' !== $data->license ) {
172 230 $licenses[ $this->id ]['data'] = $this->license_data = $data;
173 231 }
174 232 }
175 233
@@ -187,13 +245,14 @@
187 245 if ( ! empty( $this->license_data ) ) {
188 246 $license = $this->license_data;
189 247 }
190 248
191 - $class = 'license-null';
249 + $class = 'license-null';
250 + $message = '';
192 251
193 252 $out = sprintf(
194 253 '<td><label for="pll-licenses[%1$s]">%2$s</label></td>' .
195 - '<td><input name="licenses[%1$s]" id="pll-licenses[%1$s]" type="text" value="%3$s" class="regular-text code" />',
254 + '<td><input name="licenses[%1$s]" id="pll-licenses[%1$s]" type="password" value="%3$s" class="regular-text code" />',
196 255 esc_attr( $this->id ),
197 256 esc_attr( $this->name ),
198 257 esc_html( $this->license_key )
199 258 );
@@ -216,9 +275,9 @@
216 275 $message = sprintf(
217 276 /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */
218 277 esc_html__( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ),
219 278 esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ),
220 - sprintf( '<a href="%s" target="_blank">', esc_url( 'https://polylang.pro/checkout/?edd_license_key=' . $this->license_key ) ),
279 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
221 280 '</a>'
222 281 );
223 282 break;
224 283
@@ -230,9 +289,9 @@
230 289 case 'missing':
231 290 $message = sprintf(
232 291 /* translators: %1$s is link start tag, %2$s is link end tag. */
233 292 esc_html__( 'Invalid license. Please %1$svisit your account page%2$s and verify it.', 'polylang' ),
234 - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ),
293 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
235 294 '</a>'
236 295 );
237 296 break;
238 297
@@ -241,9 +300,9 @@
241 300 $message = sprintf(
242 301 /* translators: %1$s is a product name, %2$s is link start tag, %3$s is link end tag. */
243 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' ),
244 303 esc_html( $this->name ),
245 - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ),
304 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
246 305 '</a>'
247 306 );
248 307 break;
249 308
@@ -255,9 +314,9 @@
255 314 case 'no_activations_left':
256 315 $message = sprintf(
257 316 /* translators: %1$s is link start tag, %2$s is link end tag */
258 317 esc_html__( 'Your license key has reached its activation limit. %1$sView possible upgrades%2$s now.', 'polylang' ),
259 - sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ),
318 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
260 319 '</a>'
261 320 );
262 321 break;
263 322 }
@@ -271,11 +330,11 @@
271 330 } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
272 331 $class = 'notice-warning notice-alt';
273 332 $message = sprintf(
274 333 /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */
275 - esc_html__( 'Your license key will expire soon! Precisely, it will expire on %1$s. %2$sRenew your license key today!%3$s.', 'polylang' ),
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' ),
276 335 esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ),
277 - sprintf( '<a href="%s" target="_blank">', esc_url( 'https://polylang.pro/checkout/?edd_license_key=' . $this->license_key ) ),
336 + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
278 337 '</a>'
279 338 );
280 339 } else {
281 340 $message = sprintf(