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 +28 -28 3.03.7.1 View file →
@@ -32,9 +32,9 @@
32 32
33 33 /**
34 34 * License data, obtained from the API request.
35 35 *
36 - * @var stdClass
36 + * @var stdClass|null
37 37 */
38 38 public $license_data;
39 39
40 40 /**
@@ -69,13 +69,13 @@
69 69 * Constructor
70 70 *
71 71 * @since 1.9
72 72 *
73 - * @param string $file
74 - * @param string $item_name
75 - * @param string $version
76 - * @param string $author
77 - * @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.
78 78 */
79 79 public function __construct( $file, $item_name, $version, $author, $api_url = null ) {
80 80 $this->id = sanitize_title( $item_name );
81 81 $this->file = $file;
@@ -83,17 +83,18 @@
83 83 $this->version = $version;
84 84 $this->author = $author;
85 85 $this->api_url = empty( $api_url ) ? $this->api_url : $api_url;
86 86
87 - $licenses = get_option( 'polylang_licenses' );
88 - $this->license_key = empty( $licenses[ $this->id ]['key'] ) ? '' : $licenses[ $this->id ]['key'];
89 - if ( ! empty( $licenses[ $this->id ]['data'] ) ) {
90 - $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'];
91 93 }
92 94
93 95 // Updater
94 - add_action( 'admin_init', array( $this, 'auto_updater' ), 0 );
95 - add_action( 'cli_init', array( $this, 'auto_updater' ), 0 ); // For WP CLI.
96 + $this->auto_updater();
96 97
97 98 // Register settings
98 99 add_filter( 'pll_settings_licenses', array( $this, 'settings' ) );
99 100
@@ -124,14 +125,14 @@
124 125 new PLL_Plugin_Updater( $this->api_url, $this->file, $args );
125 126 }
126 127
127 128 /**
128 - * Registers the licence in the Settings
129 + * Registers the licence in the Settings.
129 130 *
130 131 * @since 1.9
131 132 *
132 - * @param array $items
133 - * @return array
133 + * @param PLL_License[] $items Array of objects allowing to manage a license.
134 + * @return PLL_License[]
134 135 */
135 136 public function settings( $items ) {
136 137 $items[ $this->id ] = $this;
137 138 return $items;
@@ -137,31 +138,31 @@
137 138 return $items;
138 139 }
139 140
140 141 /**
141 - * Activate the license key
142 + * Activates the license key.
142 143 *
143 144 * @since 1.9
144 145 *
145 - * @param string $license_key activation key
146 - * @return object updated $this
146 + * @param string $license_key Activation key.
147 + * @return PLL_License Updated PLL_License object.
147 148 */
148 149 public function activate_license( $license_key ) {
149 150 $this->license_key = $license_key;
150 151 $this->api_request( 'activate_license' );
151 152
152 - // Tell WordPress to look for updates
153 - set_site_transient( 'update_plugins', null );
153 + // Tell WordPress to look for updates.
154 + delete_site_transient( 'update_plugins' );
154 155 return $this;
155 156 }
156 157
157 158
158 159 /**
159 - * Deactivate the license key
160 + * Deactivates the license key.
160 161 *
161 162 * @since 1.9
162 163 *
163 - * @return object updated $this
164 + * @return PLL_License Updated PLL_License object.
164 165 */
165 166 public function deactivate_license() {
166 167 $this->api_request( 'deactivate_license' );
167 168 return $this;
@@ -167,17 +168,16 @@
167 168 return $this;
168 169 }
169 170
170 171 /**
171 - * Check if license key is valid
172 + * Checks if the license key is valid.
172 173 *
173 174 * @since 1.9
174 175 *
175 - * @return object updated $this
176 + * @return void
176 177 */
177 178 public function check_license() {
178 179 $this->api_request( 'check_license' );
179 - return $this;
180 180 }
181 181
182 182 /**
183 183 * Sends an api request to check, activate or deactivate the license
@@ -223,11 +223,11 @@
223 223 }
224 224
225 225 // Save new license info
226 226 $licenses[ $this->id ] = array( 'key' => $this->license_key );
227 - $data = json_decode( wp_remote_retrieve_body( $response ) );
227 + $data = (object) json_decode( wp_remote_retrieve_body( $response ) );
228 228
229 - if ( 'deactivated' !== $data->license ) {
229 + if ( isset( $data->license ) && 'deactivated' !== $data->license ) {
230 230 $licenses[ $this->id ]['data'] = $this->license_data = $data;
231 231 }
232 232 }
233 233
@@ -330,9 +330,9 @@
330 330 } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) {
331 331 $class = 'notice-warning notice-alt';
332 332 $message = sprintf(
333 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' ),
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 335 esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ),
336 336 sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account/' ),
337 337 '</a>'
338 338 );