PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmAddon.php +95 -309 6.286.13 View file →
@@ -4,82 +4,22 @@
4 4 }
5 5
6 6 /** @phpstan-consistent-constructor */
7 7 class FrmAddon {
8 -
9 - /**
10 - * @var string
11 - */
12 8 public $store_url = 'https://formidableforms.com';
13 -
14 - /**
15 - * @var int|string|null
16 - */
17 9 public $download_id;
18 -
19 - /**
20 - * @var string|null
21 - */
22 10 public $plugin_file;
23 -
24 - /**
25 - * @var string
26 - */
27 11 public $plugin_folder;
28 -
29 - /**
30 - * @var string
31 - */
32 12 public $plugin_name;
33 -
34 - /**
35 - * @var string
36 - */
37 13 public $plugin_slug;
38 -
39 - /**
40 - * @var string
41 - */
42 14 public $option_name;
43 -
44 - /**
45 - * @var string|null
46 - */
47 15 public $version;
48 -
49 - /**
50 - * @var string
51 - */
52 - public $author = 'Strategy11';
53 -
54 - /**
55 - * @var bool
56 - */
16 + public $author = 'Strategy11';
57 17 public $is_parent_licence = false;
58 -
59 - /**
60 - * @var bool
61 - */
62 - public $needs_license = true;
63 -
64 - /**
65 - * @var bool
66 - */
18 + public $needs_license = true;
67 19 private $is_expired_addon = false;
68 -
69 - /**
70 - * @var string|null
71 - */
72 20 public $license;
73 -
74 - /**
75 - * @var bool
76 - */
77 21 protected $get_beta = false;
78 -
79 - /**
80 - * @var array|null
81 - */
82 22 protected $save_status;
83 23
84 24 /**
85 25 * This is used to decide whether the license checks should continue.
@@ -108,12 +48,12 @@
108 48 */
109 49 protected $should_clear_cache = true;
110 50
111 51 public function __construct() {
52 +
112 53 if ( empty( $this->plugin_slug ) ) {
113 54 $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) );
114 55 }
115 -
116 56 if ( empty( $this->option_name ) ) {
117 57 $this->option_name = 'edd_' . $this->plugin_slug . '_license_';
118 58 }
119 59
@@ -123,96 +63,71 @@
123 63 add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) );
124 64 $this->edd_plugin_updater();
125 65 }
126 66
127 - /**
128 - * @return void
129 - */
130 67 public static function load_hooks() {
131 68 add_filter( 'frm_include_addon_page', '__return_true' );
132 69 new static();
133 70 }
134 71
135 - /**
136 - * @param array $plugins
137 - *
138 - * @return array
139 - */
140 72 public function insert_installed_addon( $plugins ) {
141 73 $plugins[ $this->plugin_slug ] = $this;
74 +
142 75 return $plugins;
143 76 }
144 77
145 - /**
146 - * @param string $plugin_slug
147 - *
148 - * @return false|FrmAddon
149 - */
150 78 public static function get_addon( $plugin_slug ) {
151 79 $plugins = apply_filters( 'frm_installed_addons', array() );
152 - return $plugins[ $plugin_slug ] ?? false;
80 + $plugin = false;
81 + if ( isset( $plugins[ $plugin_slug ] ) ) {
82 + $plugin = $plugins[ $plugin_slug ];
83 + }
84 +
85 + return $plugin;
153 86 }
154 87
155 - /**
156 - * @return void
157 - */
158 88 public function edd_plugin_updater() {
89 +
159 90 $this->is_license_revoked();
160 91 $license = $this->license;
161 92
162 93 add_action( 'after_plugin_row_' . plugin_basename( $this->plugin_file ), array( $this, 'maybe_show_license_message' ), 10, 2 );
163 94
164 - if ( ! $license ) {
165 - return;
166 - }
95 + if ( ! empty( $license ) ) {
167 96
168 - if ( 'formidable/formidable.php' !== $this->plugin_folder ) {
169 - add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
97 + if ( 'formidable/formidable.php' !== $this->plugin_folder ) {
98 + add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
99 + }
100 +
101 + add_filter( 'site_transient_update_plugins', array( &$this, 'clear_expired_download' ) );
170 102 }
171 -
172 - add_filter( 'site_transient_update_plugins', array( &$this, 'clear_expired_download' ) );
173 103 }
174 104
175 105 /**
176 - * Updates information on the "View version 6.15 details" page with custom data.
106 + * Updates information on the "View version x.x details" page with custom data.
177 107 *
178 108 * @uses api_request()
179 109 *
180 - * @param mixed $_data
181 - * @param string $_action
182 - * @param object|null $_args
110 + * @param mixed $_data
111 + * @param string $_action
112 + * @param object $_args
183 113 *
184 - * @return object Data.
114 + * @return object $_data
185 115 */
186 116 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
187 - if ( $_action !== 'plugin_information' ) {
117 +
118 + if ( $_action != 'plugin_information' ) {
188 119 return $_data;
189 120 }
190 121
191 122 $slug = basename( $this->plugin_file, '.php' );
192 123 $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder );
193 -
194 - if ( empty( $_args->slug ) || ( $_args->slug !== $slug && $_args->slug !== $slug2 ) ) {
124 + if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) {
195 125 return $_data;
196 126 }
197 127
198 128 $item_id = $this->download_id;
199 -
200 - if ( $item_id ) {
201 - $api = new FrmFormApi( $this->license );
202 -
203 - // Force new API info so we can pull changelog data.
204 - // Change log data is intentionally omitted from the cached API response
205 - // To help reduce the size of the autoloaded option.
206 - $api->force_api_request();
207 - $plugins = $api->get_api_info();
208 -
209 - if ( $plugins ) {
210 - $_data = $plugins[ $item_id ];
211 - }
212 - }
213 -
214 - if ( empty( $plugins ) ) {
129 + if ( empty( $item_id ) ) {
215 130 $_data = array(
216 131 'name' => $this->plugin_name,
217 132 'excerpt' => '',
218 133 'changelog' => 'See the full changelog at <a href="' . esc_url( $this->store_url . '/changelog/' ) . '"></a>',
@@ -220,8 +135,12 @@
220 135 'high' => '',
221 136 'low' => 'https://ps.w.org/formidable/assets/banner-1544x500.png',
222 137 ),
223 138 );
139 + } else {
140 + $api = new FrmFormApi( $this->license );
141 + $plugins = $api->get_api_info();
142 + $_data = $plugins[ $item_id ];
224 143 }
225 144
226 145 $_data['sections'] = array(
227 146 'description' => $_data['excerpt'],
@@ -232,31 +151,28 @@
232 151
233 152 return (object) $_data;
234 153 }
235 154
236 - /**
237 - * @return string
238 - */
239 155 public function get_license() {
240 156 $license = $this->maybe_get_pro_license();
241 -
242 - if ( $license ) {
157 + if ( ! empty( $license ) ) {
243 158 return $license;
244 159 }
245 160
246 161 $license = trim( get_option( $this->option_name . 'key' ) );
162 + if ( empty( $license ) ) {
163 + $license = $this->activate_defined_license();
164 + }
247 165
248 - return $license ? $license : $this->activate_defined_license();
166 + return $license;
249 167 }
250 168
251 169 /**
252 170 * @since 3.04.03
253 - *
254 - * @return false|string
255 171 */
256 172 protected function maybe_get_pro_license() {
257 - // Prevent a loop if $this is the pro plugin
258 - $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name !== 'Formidable Pro';
173 + // prevent a loop if $this is the pro plugin
174 + $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name != 'Formidable Pro';
259 175
260 176 if ( ! $get_license ) {
261 177 return false;
262 178 }
@@ -263,16 +179,18 @@
263 179
264 180 $api = new FrmFormApi();
265 181 $api->get_pro_updater();
266 182 $license = $api->get_license();
267 -
268 - if ( ! $license ) {
183 + if ( empty( $license ) ) {
269 184 return false;
270 185 }
271 186
272 187 $this->get_api_info( $license );
188 + if ( ! $this->is_parent_licence ) {
189 + $license = false;
190 + }
273 191
274 - return $this->is_parent_licence ? $license : false;
192 + return $license;
275 193 }
276 194
277 195 /**
278 196 * Activate the license in wp-config.php
@@ -277,17 +195,13 @@
277 195 /**
278 196 * Activate the license in wp-config.php
279 197 *
280 198 * @since 2.04
281 - *
282 - * @return string
283 199 */
284 200 public function activate_defined_license() {
285 201 $license = $this->get_defined_license();
286 -
287 - if ( $license && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) {
202 + if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) {
288 203 $response = $this->activate_license( $license );
289 -
290 204 if ( ! $response['success'] ) {
291 205 $license = '';
292 206 }
293 207 }
@@ -298,28 +212,19 @@
298 212 /**
299 213 * Check the wp-config.php for the license key
300 214 *
301 215 * @since 2.04
302 - *
303 - * @return false|string
304 216 */
305 217 public function get_defined_license() {
306 - $constant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
307 - return defined( $constant_name ) ? constant( $constant_name ) : false;
218 + $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
219 +
220 + return defined( $consant_name ) ? constant( $consant_name ) : false;
308 221 }
309 222
310 - /**
311 - * @param string $license
312 - *
313 - * @return void
314 - */
315 223 public function set_license( $license ) {
316 224 update_option( $this->option_name . 'key', $license );
317 225 }
318 226
319 - /**
320 - * @return mixed
321 - */
322 227 public function is_active() {
323 228 return get_option( $this->option_name . 'active' );
324 229 }
325 230
@@ -326,10 +231,8 @@
326 231 /**
327 232 * @since 3.04.03
328 233 *
329 234 * @param array|string $error
330 - *
331 - * @return void
332 235 */
333 236 public function maybe_clear_license( $error ) {
334 237 if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) {
335 238 $this->clear_license();
@@ -335,23 +238,18 @@
335 238 $this->clear_license();
336 239 }
337 240 }
338 241
339 - /**
340 - * @return void
341 - */
342 242 public function clear_license() {
343 243 delete_option( $this->option_name . 'active' );
344 244 delete_option( $this->option_name . 'key' );
345 245
346 - if ( ! $this->should_clear_cache ) {
347 - return;
246 + if ( $this->should_clear_cache ) {
247 + delete_site_option( $this->transient_key() );
248 + delete_option( $this->transient_key() );
249 + $this->delete_cache();
250 + $this->should_clear_cache = true;
348 251 }
349 -
350 - delete_site_option( $this->transient_key() );
351 - delete_option( $this->transient_key() );
352 - $this->delete_cache();
353 - $this->should_clear_cache = true;
354 252 }
355 253
356 254 /**
357 255 * Don't save an invalid license.
@@ -363,9 +261,8 @@
363 261 * @return void
364 262 */
365 263 protected function maybe_set_active( $is_valid ) {
366 264 update_option( $this->option_name . 'active', $is_valid );
367 -
368 265 if ( $is_valid ) {
369 266 $this->set_active( $is_valid );
370 267 return;
371 268 }
@@ -376,13 +273,8 @@
376 273 delete_option( $this->option_name . 'key' );
377 274 $this->license = '';
378 275 }
379 276
380 - /**
381 - * @param bool $is_active
382 - *
383 - * @return void
384 - */
385 277 public function set_active( $is_active ) {
386 278 $this->delete_cache();
387 279 FrmAppHelper::save_combined_js();
388 280 $this->update_pro_capabilities();
@@ -391,10 +283,8 @@
391 283 /**
392 284 * Updates roles capabilities after pro license is active.
393 285 *
394 286 * @since 5.0
395 - *
396 - * @return void
397 287 */
398 288 protected function update_pro_capabilities() {
399 289 global $wp_roles;
400 290
@@ -404,11 +294,10 @@
404 294
405 295 $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
406 296 $roles = get_editable_roles();
407 297 $settings = new FrmSettings();
408 -
409 298 foreach ( $caps as $cap => $cap_desc ) {
410 - $cap_roles = (array) ( $settings->$cap ?? 'administrator' );
299 + $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' );
411 300
412 301 // Make sure administrators always have permissions.
413 302 if ( ! in_array( 'administrator', $cap_roles, true ) ) {
414 303 array_push( $cap_roles, 'administrator' );
@@ -414,9 +303,9 @@
414 303 array_push( $cap_roles, 'administrator' );
415 304 }
416 305
417 306 foreach ( $roles as $role => $details ) {
418 - if ( in_array( $role, $cap_roles, true ) ) {
307 + if ( in_array( $role, $cap_roles ) ) {
419 308 $wp_roles->add_cap( $role, $cap );
420 309 } else {
421 310 $wp_roles->remove_cap( $role, $cap );
422 311 }
@@ -425,10 +314,8 @@
425 314 }
426 315
427 316 /**
428 317 * @since 3.04.03
429 - *
430 - * @return void
431 318 */
432 319 protected function delete_cache() {
433 320 delete_transient( 'frm_api_licence' );
434 321
@@ -442,14 +329,8 @@
442 329 $api->reset_cached();
443 330
444 331 $api = new FrmApplicationApi( $this->license );
445 332 $api->reset_cached();
446 -
447 - $api = new FrmSalesApi();
448 - $api->reset_cached();
449 -
450 - $api = new FrmStyleApi();
451 - $api->reset_cached();
452 333 }
453 334
454 335 /**
455 336 * The Pro version includes the show_license_message function.
@@ -455,17 +336,12 @@
455 336 * The Pro version includes the show_license_message function.
456 337 * We need an extra check before we allow it to show a message.
457 338 *
458 339 * @since 3.04.03
459 - *
460 - * @param string $file File path of the plugin.
461 - * @param array $plugin Plugin data.
462 - *
463 - * @return void
464 340 */
465 341 public function maybe_show_license_message( $file, $plugin ) {
466 342 if ( $this->is_expired_addon || isset( $plugin['package'] ) ) {
467 - // Let's not show a ton of duplicate messages
343 + // let's not show a ton of duplicate messages
468 344 return;
469 345 }
470 346
471 347 $this->show_license_message( $file, $plugin );
@@ -470,30 +346,22 @@
470 346
471 347 $this->show_license_message( $file, $plugin );
472 348 }
473 349
474 - /**
475 - * @param string $file File path of the plugin.
476 - * @param array $plugin Plugin data.
477 - *
478 - * @return void
479 - */
480 350 public function show_license_message( $file, $plugin ) {
481 351 $message = '';
482 -
483 352 if ( empty( $this->license ) ) {
484 353 /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */
485 - $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">', '</a>' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
354 + $message = sprintf( esc_html__( 'Your %1$s license key is missing. Please add it on the %2$slicenses page%3$s.', 'formidable' ), esc_html( $this->plugin_name ), '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">', '</a>' );
486 355 } else {
487 356 $api = new FrmFormApi( $this->license );
488 357 $errors = $api->error_for_license();
489 -
490 - if ( $errors ) {
358 + if ( ! empty( $errors ) ) {
491 359 $message = reset( $errors );
492 360 }
493 361 }
494 362
495 - if ( ! $message ) {
363 + if ( empty( $message ) ) {
496 364 return;
497 365 }
498 366
499 367 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
@@ -498,19 +366,14 @@
498 366
499 367 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
500 368 $id = sanitize_title( $plugin['Name'] ) . '-next';
501 369
502 - echo '<tr class="plugin-update-tr active" id="' . esc_attr( $id ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice error inline notice-error notice-alt"><p>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
503 - FrmAppHelper::kses_echo( $message, 'a' );
504 - echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
370 + echo '<tr class="plugin-update-tr active" id="' . esc_attr( $id ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="update-message notice error inline notice-error notice-alt"><p>';
371 + echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
372 + echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
505 373 echo '</p></div></td></tr>';
506 374 }
507 375
508 - /**
509 - * @param mixed $transient
510 - *
511 - * @return mixed
512 - */
513 376 public function clear_expired_download( $transient ) {
514 377 if ( ! is_object( $transient ) ) {
515 378 return $transient;
516 379 }
@@ -522,9 +385,9 @@
522 385 }
523 386 } elseif ( isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) ) {
524 387 $this->prepare_update_details( $transient->response[ $this->plugin_folder ] );
525 388
526 - // If the transient has expired, clear the update and trigger it again
389 + // if the transient has expired, clear the update and trigger it again
527 390 if ( $transient->response[ $this->plugin_folder ] === false ) {
528 391 if ( ! $this->has_been_cleared() ) {
529 392 $this->cleared_plugins();
530 393 $this->manually_queue_update();
@@ -541,37 +404,29 @@
541 404 *
542 405 * @since 3.04.03
543 406 *
544 407 * @param object $transient The current plugin info saved for update.
545 - *
546 - * @return void
547 408 */
548 409 private function prepare_update_details( &$transient ) {
549 410 $version_info = $transient;
550 411 $has_beta_url = ! empty( $version_info->beta );
551 -
552 412 if ( $this->get_beta && ! $has_beta_url ) {
553 413 $version_info = (object) $this->get_api_info( $this->license );
554 414 }
555 415
556 - if ( empty( $version_info->new_version ) ) {
557 - return;
558 - }
416 + if ( ! empty( $version_info->new_version ) ) {
417 + $this->clear_old_plugin_version( $version_info );
418 + if ( $version_info === false ) {
419 + // Was cleared with timeout.
420 + $transient = false;
421 + } else {
422 + $this->maybe_use_beta_url( $version_info );
559 423
560 - $this->clear_old_plugin_version( $version_info );
561 -
562 - if ( $version_info === false ) {
563 - // Was cleared with timeout.
564 - $transient = false;
565 -
566 - return;
424 + if ( version_compare( $version_info->new_version, $this->version, '>' ) ) {
425 + $transient = $version_info;
426 + }
427 + }
567 428 }
568 -
569 - $this->maybe_use_beta_url( $version_info );
570 -
571 - if ( version_compare( $version_info->new_version, $this->version, '>' ) ) {
572 - $transient = $version_info;
573 - }
574 429 }
575 430
576 431 /**
577 432 * Get the API info for this plugin
@@ -576,22 +431,18 @@
576 431 /**
577 432 * Get the API info for this plugin
578 433 *
579 434 * @since 3.04.03
580 - *
581 - * @param string $license The license key.
582 - *
583 - * @return array The API info for the plugin.
584 435 */
585 436 protected function get_api_info( $license ) {
586 437 $api = new FrmFormApi( $license );
587 438 $addon = $api->get_addon_for_license( $this );
588 439
589 - // If there is no download url, this license does not apply to the addon
440 + // if there is no download url, this license does not apply to the addon
590 441 if ( isset( $addon['package'] ) ) {
591 442 $this->is_parent_licence = true;
592 443 } elseif ( isset( $addon['error'] ) ) {
593 - // If the license is expired, we must assume all add-ons were packaged
444 + // if the license is expired, we must assume all add-ons were packaged
594 445 $this->is_parent_licence = true;
595 446 $this->is_expired_addon = true;
596 447 }
597 448
@@ -602,24 +453,17 @@
602 453 * Make sure transients don't stick around on sites that
603 454 * don't save the transient expiration
604 455 *
605 456 * @since 2.05.05
606 - *
607 - * @param object $version_info The version info for the plugin.
608 - *
609 - * @return void
610 457 */
611 458 private function clear_old_plugin_version( &$version_info ) {
612 459 $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0;
613 -
614 - if ( ! $timeout || time() <= $timeout ) {
615 - return;
460 + if ( ! empty( $timeout ) && time() > $timeout ) {
461 + // Cache is expired.
462 + $version_info = false;
463 + $api = new FrmFormApi( $this->license );
464 + $api->reset_cached();
616 465 }
617 -
618 - // Cache is expired.
619 - $version_info = false;
620 - $api = new FrmFormApi( $this->license );
621 - $api->reset_cached();
622 466 }
623 467
624 468 /**
625 469 * The beta url is always included if the download has a beta.
@@ -625,18 +469,13 @@
625 469 * The beta url is always included if the download has a beta.
626 470 * Check if the beta should be downloaded.
627 471 *
628 472 * @since 3.04.03
629 - *
630 - * @param object $version_info The version info for the plugin.
631 - *
632 - * @return void
633 473 */
634 474 private function maybe_use_beta_url( &$version_info ) {
635 475 if ( $this->get_beta && ! empty( $version_info->beta ) ) {
636 476 $version_info->new_version = $version_info->beta['version'];
637 477 $version_info->package = $version_info->beta['package'];
638 -
639 478 if ( ! empty( $version_info->plugin ) ) {
640 479 $version_info->plugin = $version_info->beta['plugin'];
641 480 }
642 481 }
@@ -641,13 +480,8 @@
641 480 }
642 481 }
643 482 }
644 483
645 - /**
646 - * @param object $transient
647 - *
648 - * @return bool
649 - */
650 484 private function is_current_version( $transient ) {
651 485 if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) {
652 486 return false;
653 487 }
@@ -652,14 +486,13 @@
652 486 return false;
653 487 }
654 488
655 489 $response = empty( $transient->response );
656 -
657 490 if ( $response ) {
658 491 return true;
659 492 }
660 493
661 - return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
494 + return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version;
662 495 }
663 496
664 497 /**
665 498 * @return bool
@@ -668,18 +501,12 @@
668 501 $last_cleared = get_option( 'frm_last_cleared' );
669 502 return $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) );
670 503 }
671 504
672 - /**
673 - * @return void
674 - */
675 505 private function cleared_plugins() {
676 506 update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
677 507 }
678 508
679 - /**
680 - * @return void
681 - */
682 509 private function is_license_revoked() {
683 510 if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
684 511 return;
685 512 }
@@ -694,9 +521,8 @@
694 521 return;
695 522 }
696 523
697 524 $response = $this->get_license_status();
698 -
699 525 if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) {
700 526 $this->clear_license();
701 527 }
702 528 }
@@ -711,9 +537,8 @@
711 537 */
712 538 private function checked_recently( $time, $required_status = '' ) {
713 539 $last_checked = $this->last_checked();
714 540 $is_429 = isset( $last_checked['response_code'] ) && 429 === $last_checked['response_code'];
715 -
716 541 if ( $is_429 ) {
717 542 // If the last check was a a rate limit, we'll need to check again sooner.
718 543 $time = '5 minutes';
719 544 $required_status = '';
@@ -723,9 +548,9 @@
723 548 // If the last check was invalid, we don't need to check again.
724 549 return true;
725 550 }
726 551
727 - $checked_time = $last_checked['time'] ?? false;
552 + $checked_time = isset( $last_checked['time'] ) ? $last_checked['time'] : false;
728 553 $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) );
729 554 return $checked_time && $checked_time > $time_ago;
730 555 }
731 556
@@ -734,16 +559,18 @@
734 559 *
735 560 * @return array
736 561 */
737 562 private function last_checked() {
738 - $last_checked = is_multisite() ? get_site_option( $this->transient_key() ) : get_option( $this->transient_key() );
739 -
563 + if ( is_multisite() ) {
564 + $last_checked = get_site_option( $this->transient_key() );
565 + } else {
566 + $last_checked = get_option( $this->transient_key() );
567 + }
740 568 if ( $last_checked && ! is_array( $last_checked ) ) {
741 569 // Get string into array for existing values.
742 570 $last_checked = array( 'time' => $last_checked );
743 571 }
744 -
745 - return $last_checked ? $last_checked : array();
572 + return $last_checked ? (array) $last_checked : array();
746 573 }
747 574
748 575 /**
749 576 * @return void
@@ -749,9 +576,8 @@
749 576 * @return void
750 577 */
751 578 private function update_last_checked() {
752 579 $this->save_response['time'] = gmdate( 'Y-m-d H:i:s' );
753 -
754 580 if ( is_multisite() ) {
755 581 update_site_option( $this->transient_key(), $this->save_response );
756 582 } else {
757 583 update_option( $this->transient_key(), $this->save_response );
@@ -759,25 +585,19 @@
759 585 }
760 586
761 587 /**
762 588 * Use a new cache after the license is changed, or Formidable is updated.
763 - *
764 - * @return string
765 589 */
766 590 private function transient_key() {
767 591 return 'frm_' . md5( sanitize_key( $this->license . '_' . $this->plugin_slug ) );
768 592 }
769 593
770 - /**
771 - * @return void
772 - */
773 594 public static function activate() {
774 595 FrmAppHelper::permission_check( 'frm_change_settings' );
775 596 check_ajax_referer( 'frm_ajax', 'nonce' );
776 597
777 598 $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
778 -
779 - if ( ! $license ) {
599 + if ( empty( $license ) ) {
780 600 wp_send_json(
781 601 array(
782 602 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
783 603 'success' => false,
@@ -787,20 +607,13 @@
787 607
788 608 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
789 609 $response = self::activate_license_for_plugin( $license, $plugin_slug );
790 610
791 - FrmInbox::clear_cache();
792 -
793 611 wp_send_json( $response );
794 612 }
795 613
796 614 /**
797 615 * @since 4.08
798 - *
799 - * @param string $license The license key.
800 - * @param string $plugin_slug The plugin slug.
801 - *
802 - * @return array The response from the license activation.
803 616 */
804 617 public static function activate_license_for_plugin( $license, $plugin_slug ) {
805 618 $this_plugin = self::get_addon( $plugin_slug );
806 619 return $this_plugin->activate_license( $license );
@@ -805,13 +618,8 @@
805 618 $this_plugin = self::get_addon( $plugin_slug );
806 619 return $this_plugin->activate_license( $license );
807 620 }
808 621
809 - /**
810 - * @param string $license The license key.
811 - *
812 - * @return array The response from the license activation.
813 - */
814 622 private function activate_license( $license ) {
815 623 $this->set_license( $license );
816 624 $this->license = $license;
817 625
@@ -824,9 +632,8 @@
824 632 if ( $response['error'] ) {
825 633 $response['message'] = $response['status'];
826 634 } else {
827 635 $messages = $this->get_messages();
828 -
829 636 if ( is_string( $response['status'] ) && isset( $messages[ $response['status'] ] ) ) {
830 637 $response['message'] = $messages[ $response['status'] ];
831 638 } else {
832 639 $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) );
@@ -832,9 +639,8 @@
832 639 $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) );
833 640 }
834 641
835 642 $is_valid = false;
836 -
837 643 if ( 'valid' === $response['status'] ) {
838 644 $is_valid = 'valid';
839 645 $response['success'] = true;
840 646 }
@@ -864,11 +670,8 @@
864 670 )
865 671 );
866 672 }
867 673
868 - /**
869 - * @return array
870 - */
871 674 private function get_license_status() {
872 675 $this->set_running();
873 676
874 677 $response = array(
@@ -874,11 +677,11 @@
874 677 $response = array(
875 678 'status' => 'missing',
876 679 'error' => true,
877 680 );
878 -
879 681 if ( empty( $this->license ) ) {
880 682 $response['error'] = false;
683 +
881 684 return $response;
882 685 }
883 686
884 687 try {
@@ -902,11 +705,8 @@
902 705 $this->done_running();
903 706 return $response;
904 707 }
905 708
906 - /**
907 - * @return array
908 - */
909 709 private function get_messages() {
910 710 return array(
911 711 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ),
912 712 'invalid' => __( 'That license key is invalid', 'formidable' ),
@@ -919,10 +719,8 @@
919 719 }
920 720
921 721 /**
922 722 * @since 4.03
923 - *
924 - * @return void
925 723 */
926 724 public static function reset_cache() {
927 725 FrmAppHelper::permission_check( 'frm_change_settings' );
928 726 check_ajax_referer( 'frm_ajax', 'nonce' );
@@ -937,11 +735,8 @@
937 735
938 736 wp_send_json( $response );
939 737 }
940 738
941 - /**
942 - * @return void
943 - */
944 739 public static function deactivate() {
945 740 FrmAppHelper::permission_check( 'frm_change_settings' );
946 741 check_ajax_referer( 'frm_ajax', 'nonce' );
947 742
@@ -950,13 +745,11 @@
950 745 $response = array(
951 746 'success' => false,
952 747 'message' => '',
953 748 );
954 -
955 749 try {
956 750 // $license_data->license will be either "deactivated" or "failed"
957 751 $license_data = $this_plugin->send_mothership_request( 'deactivate_license' );
958 -
959 752 if ( is_array( $license_data ) && 'deactivated' === $license_data['license'] ) {
960 753 $response['success'] = true;
961 754 $response['message'] = __( 'That license was removed successfully', 'formidable' );
962 755 } else {
@@ -966,9 +759,8 @@
966 759 $response['message'] = $e->getMessage();
967 760 }
968 761
969 762 $this_plugin->clear_license();
970 - FrmInbox::clear_cache();
971 763
972 764 wp_send_json( $response );
973 765 }
974 766
@@ -973,10 +765,8 @@
973 765 }
974 766
975 767 /**
976 768 * @since 4.03
977 - *
978 - * @return FrmAddon
979 769 */
980 770 private static function set_license_from_post() {
981 771 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
982 772 $this_plugin = self::get_addon( $plugin_slug );
@@ -985,10 +775,8 @@
985 775 return $this_plugin;
986 776 }
987 777
988 778 /**
989 - * @param string $action
990 - *
991 779 * @return string
992 780 */
993 781 public function send_mothership_request( $action ) {
994 782 $api_params = array(
@@ -995,9 +783,8 @@
995 783 'edd_action' => $action,
996 784 'license' => $this->license,
997 785 'url' => home_url(),
998 786 );
999 -
1000 787 if ( is_numeric( $this->download_id ) ) {
1001 788 $api_params['item_id'] = absint( $this->download_id );
1002 789 } else {
1003 790 $api_params['item_name'] = rawurlencode( $this->plugin_name );
@@ -1016,21 +803,23 @@
1016 803 $body = wp_remote_retrieve_body( $resp );
1017 804 $this->save_status = array( 'response_code' => wp_remote_retrieve_response_code( $resp ) );
1018 805
1019 806 $message = __( 'Your License Key was invalid', 'formidable' );
1020 -
1021 807 if ( is_wp_error( $resp ) ) {
1022 808 $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' );
1023 809 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1024 - $message = sprintf( __( 'You had an error communicating with the Formidable API. %1$sClick here%2$s for more information.', 'formidable' ), '<a href="' . esc_url( $link ) . '" target="_blank">', '</a>' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
810 + $message = sprintf( __( 'You had an error communicating with the Formidable API. %1$sClick here%2$s for more information.', 'formidable' ), '<a href="' . esc_url( $link ) . '" target="_blank">', '</a>' );
1025 811 $message .= ' ' . $resp->get_error_message();
1026 812 } elseif ( 'error' === $body || is_wp_error( $body ) ) {
1027 813 $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' );
1028 814 } else {
1029 815 $json_res = json_decode( $body, true );
1030 -
1031 816 if ( null !== $json_res ) {
1032 - $message = is_array( $json_res ) && isset( $json_res['error'] ) ? $json_res['error'] : $json_res;
817 + if ( is_array( $json_res ) && isset( $json_res['error'] ) ) {
818 + $message = $json_res['error'];
819 + } else {
820 + $message = $json_res;
821 + }
1033 822 } elseif ( ! empty( $resp['response'] ) && ! empty( $resp['response']['code'] ) ) {
1034 823 $resp['body'] = wp_strip_all_tags( $resp['body'] );
1035 824
1036 825 $message = sprintf(
@@ -1044,11 +833,8 @@
1044 833
1045 834 return $message;
1046 835 }
1047 836
1048 - /**
1049 - * @return void
1050 - */
1051 837 public function manually_queue_update() {
1052 838 $updates = new stdClass();
1053 839 $updates->last_checked = 0;
1054 840 $updates->response = array();