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