PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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 +57 -375 6.266.8 View file →
@@ -4,110 +4,32 @@
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 16 public $author = 'Strategy11';
53 -
54 - /**
55 - * @var bool
56 - */
57 17 public $is_parent_licence = false;
58 -
59 - /**
60 - * @var bool
61 - */
62 18 public $needs_license = true;
63 -
64 - /**
65 - * @var bool
66 - */
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 22
79 23 /**
80 - * @var array|null
81 - */
82 - protected $save_status;
83 -
84 - /**
85 - * This is used to decide whether the license checks should continue.
86 - * The point is to avoid license issues when a site url changes.
87 - *
88 - * @since 6.8.3
89 - *
90 - * @var array
91 - */
92 - private $save_response = array();
93 -
94 - /**
95 24 * This is used to flag other add ons not to send a request.
96 - * We only want to send a single API request per page load.
25 + * We only want to send a single API request per HTTP request.
97 26 *
98 - * @since 6.8.3
27 + * @since 6.7.1
99 28 *
100 - * @var string
101 - */
102 - private $transient_lock_key = 'frm_activate_request_lock';
103 -
104 - /**
105 - * @since 6.8.3
106 - *
107 29 * @var bool
108 30 */
109 - protected $should_clear_cache = true;
31 + private static $sent_mothership_request = false;
110 32
111 33 public function __construct() {
112 34
113 35 if ( empty( $this->plugin_slug ) ) {
@@ -112,9 +34,8 @@
112 34
113 35 if ( empty( $this->plugin_slug ) ) {
114 36 $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) );
115 37 }
116 -
117 38 if ( empty( $this->option_name ) ) {
118 39 $this->option_name = 'edd_' . $this->plugin_slug . '_license_';
119 40 }
120 41
@@ -124,21 +45,13 @@
124 45 add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) );
125 46 $this->edd_plugin_updater();
126 47 }
127 48
128 - /**
129 - * @return void
130 - */
131 49 public static function load_hooks() {
132 50 add_filter( 'frm_include_addon_page', '__return_true' );
133 51 new static();
134 52 }
135 53
136 - /**
137 - * @param array $plugins
138 - *
139 - * @return array
140 - */
141 54 public function insert_installed_addon( $plugins ) {
142 55 $plugins[ $this->plugin_slug ] = $this;
143 56
144 57 return $plugins;
@@ -143,17 +56,11 @@
143 56
144 57 return $plugins;
145 58 }
146 59
147 - /**
148 - * @param string $plugin_slug
149 - *
150 - * @return false|FrmAddon
151 - */
152 60 public static function get_addon( $plugin_slug ) {
153 61 $plugins = apply_filters( 'frm_installed_addons', array() );
154 62 $plugin = false;
155 -
156 63 if ( isset( $plugins[ $plugin_slug ] ) ) {
157 64 $plugin = $plugins[ $plugin_slug ];
158 65 }
159 66
@@ -159,11 +66,8 @@
159 66
160 67 return $plugin;
161 68 }
162 69
163 - /**
164 - * @return void
165 - */
166 70 public function edd_plugin_updater() {
167 71
168 72 $this->is_license_revoked();
169 73 $license = $this->license;
@@ -180,9 +84,9 @@
180 84 }
181 85 }
182 86
183 87 /**
184 - * Updates information on the "View version 6.15 details" page with custom data.
88 + * Updates information on the "View version x.x details" page with custom data.
185 89 *
186 90 * @uses api_request()
187 91 *
188 92 * @param mixed $_data
@@ -198,15 +102,13 @@
198 102 }
199 103
200 104 $slug = basename( $this->plugin_file, '.php' );
201 105 $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder );
202 -
203 106 if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) {
204 107 return $_data;
205 108 }
206 109
207 110 $item_id = $this->download_id;
208 -
209 111 if ( empty( $item_id ) ) {
210 112 $_data = array(
211 113 'name' => $this->plugin_name,
212 114 'excerpt' => '',
@@ -231,20 +133,15 @@
231 133
232 134 return (object) $_data;
233 135 }
234 136
235 - /**
236 - * @return string
237 - */
238 137 public function get_license() {
239 138 $license = $this->maybe_get_pro_license();
240 -
241 139 if ( ! empty( $license ) ) {
242 140 return $license;
243 141 }
244 142
245 143 $license = trim( get_option( $this->option_name . 'key' ) );
246 -
247 144 if ( empty( $license ) ) {
248 145 $license = $this->activate_defined_license();
249 146 }
250 147
@@ -252,10 +149,8 @@
252 149 }
253 150
254 151 /**
255 152 * @since 3.04.03
256 - *
257 - * @return false|string
258 153 */
259 154 protected function maybe_get_pro_license() {
260 155 // prevent a loop if $this is the pro plugin
261 156 $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name != 'Formidable Pro';
@@ -266,15 +161,13 @@
266 161
267 162 $api = new FrmFormApi();
268 163 $api->get_pro_updater();
269 164 $license = $api->get_license();
270 -
271 165 if ( empty( $license ) ) {
272 166 return false;
273 167 }
274 168
275 169 $this->get_api_info( $license );
276 -
277 170 if ( ! $this->is_parent_licence ) {
278 171 $license = false;
279 172 }
280 173
@@ -284,17 +177,14 @@
284 177 /**
285 178 * Activate the license in wp-config.php
286 179 *
287 180 * @since 2.04
288 - *
289 - * @return string
290 181 */
291 182 public function activate_defined_license() {
292 183 $license = $this->get_defined_license();
293 -
294 - if ( ! empty( $license ) && ! $this->is_active() && ! $this->checked_recently( '1 day' ) ) {
184 + if ( ! empty( $license ) && ! $this->is_active() && $this->is_time_to_auto_activate() ) {
295 185 $response = $this->activate_license( $license );
296 -
186 + $this->set_auto_activate_time();
297 187 if ( ! $response['success'] ) {
298 188 $license = '';
299 189 }
300 190 }
@@ -305,29 +195,35 @@
305 195 /**
306 196 * Check the wp-config.php for the license key
307 197 *
308 198 * @since 2.04
309 - *
310 - * @return false|string
311 199 */
312 200 public function get_defined_license() {
313 - $constant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
201 + $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
314 202
315 - return defined( $constant_name ) ? constant( $constant_name ) : false;
203 + return defined( $consant_name ) ? constant( $consant_name ) : false;
316 204 }
317 205
318 - /**
319 - * @param string $license
320 - *
321 - * @return void
322 - */
323 206 public function set_license( $license ) {
324 207 update_option( $this->option_name . 'key', $license );
325 208 }
326 209
327 210 /**
328 - * @return mixed
211 + * If the license is in the config, limit the frequency of checks.
212 + * The license may be entered incorrectly, so we don't want to check on every page load.
213 + *
214 + * @since 2.04
329 215 */
216 + private function is_time_to_auto_activate() {
217 + $last_try = get_option( $this->option_name . 'last_activate' );
218 +
219 + return ( ! $last_try || $last_try < strtotime( '-1 day' ) );
220 + }
221 +
222 + private function set_auto_activate_time() {
223 + update_option( $this->option_name . 'last_activate', time() );
224 + }
225 +
330 226 public function is_active() {
331 227 return get_option( $this->option_name . 'active' );
332 228 }
333 229
@@ -333,63 +229,26 @@
333 229
334 230 /**
335 231 * @since 3.04.03
336 232 *
337 - * @param array|string $error
338 - *
339 - * @return void
233 + * @param array $error
340 234 */
341 235 public function maybe_clear_license( $error ) {
342 - if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) {
236 + if ( $error['code'] === 'disabled' && $error['license'] === $this->license ) {
343 237 $this->clear_license();
344 238 }
345 239 }
346 240
347 - /**
348 - * @return void
349 - */
350 241 public function clear_license() {
351 242 delete_option( $this->option_name . 'active' );
352 243 delete_option( $this->option_name . 'key' );
353 -
354 - if ( $this->should_clear_cache ) {
355 - delete_site_option( $this->transient_key() );
356 - delete_option( $this->transient_key() );
357 - $this->delete_cache();
358 - $this->should_clear_cache = true;
359 - }
244 + delete_site_option( $this->transient_key() );
245 + delete_option( $this->transient_key() );
246 + $this->delete_cache();
360 247 }
361 248
362 - /**
363 - * Don't save an invalid license.
364 - *
365 - * @since 6.8.3
366 - *
367 - * @param bool $is_valid If license activation was successful.
368 - *
369 - * @return void
370 - */
371 - protected function maybe_set_active( $is_valid ) {
372 - update_option( $this->option_name . 'active', $is_valid );
373 -
374 - if ( $is_valid ) {
375 - $this->set_active( $is_valid );
376 - return;
377 - }
378 -
379 - // Don't save the license if it's invalid.
380 - $this->should_clear_cache = false;
381 - $this->clear_license();
382 - delete_option( $this->option_name . 'key' );
383 - $this->license = '';
384 - }
385 -
386 - /**
387 - * @param bool $is_active
388 - *
389 - * @return void
390 - */
391 249 public function set_active( $is_active ) {
250 + update_option( $this->option_name . 'active', $is_active );
392 251 $this->delete_cache();
393 252 FrmAppHelper::save_combined_js();
394 253 $this->update_pro_capabilities();
395 254 }
@@ -397,10 +256,8 @@
397 256 /**
398 257 * Updates roles capabilities after pro license is active.
399 258 *
400 259 * @since 5.0
401 - *
402 - * @return void
403 260 */
404 261 protected function update_pro_capabilities() {
405 262 global $wp_roles;
406 263
@@ -410,14 +267,13 @@
410 267
411 268 $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
412 269 $roles = get_editable_roles();
413 270 $settings = new FrmSettings();
414 -
415 271 foreach ( $caps as $cap => $cap_desc ) {
416 - $cap_roles = (array) ( $settings->$cap ?? 'administrator' );
272 + $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' );
417 273
418 274 // Make sure administrators always have permissions.
419 - if ( ! in_array( 'administrator', $cap_roles, true ) ) {
275 + if ( ! in_array( 'administrator', $cap_roles ) ) {
420 276 array_push( $cap_roles, 'administrator' );
421 277 }
422 278
423 279 foreach ( $roles as $role => $details ) {
@@ -431,17 +287,12 @@
431 287 }
432 288
433 289 /**
434 290 * @since 3.04.03
435 - *
436 - * @return void
437 291 */
438 292 protected function delete_cache() {
439 293 delete_transient( 'frm_api_licence' );
440 294
441 - // Cleanup option that has been removed.
442 - delete_option( $this->option_name . 'last_activate' );
443 -
444 295 $api = new FrmFormApi( $this->license );
445 296 $api->reset_cached();
446 297
447 298 $api = new FrmFormTemplateApi( $this->license );
@@ -448,11 +299,8 @@
448 299 $api->reset_cached();
449 300
450 301 $api = new FrmApplicationApi( $this->license );
451 302 $api->reset_cached();
452 -
453 - $api = new FrmSalesApi();
454 - $api->reset_cached();
455 303 }
456 304
457 305 /**
458 306 * The Pro version includes the show_license_message function.
@@ -458,13 +306,8 @@
458 306 * The Pro version includes the show_license_message function.
459 307 * We need an extra check before we allow it to show a message.
460 308 *
461 309 * @since 3.04.03
462 - *
463 - * @param string $file File path of the plugin.
464 - * @param array $plugin Plugin data.
465 - *
466 - * @return void
467 310 */
468 311 public function maybe_show_license_message( $file, $plugin ) {
469 312 if ( $this->is_expired_addon || isset( $plugin['package'] ) ) {
470 313 // let's not show a ton of duplicate messages
@@ -473,17 +316,10 @@
473 316
474 317 $this->show_license_message( $file, $plugin );
475 318 }
476 319
477 - /**
478 - * @param string $file File path of the plugin.
479 - * @param array $plugin Plugin data.
480 - *
481 - * @return void
482 - */
483 320 public function show_license_message( $file, $plugin ) {
484 321 $message = '';
485 -
486 322 if ( empty( $this->license ) ) {
487 323 /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */
488 324 $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>' );
489 325 } else {
@@ -488,9 +324,8 @@
488 324 $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>' );
489 325 } else {
490 326 $api = new FrmFormApi( $this->license );
491 327 $errors = $api->error_for_license();
492 -
493 328 if ( ! empty( $errors ) ) {
494 329 $message = reset( $errors );
495 330 }
496 331 }
@@ -502,18 +337,13 @@
502 337 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
503 338 $id = sanitize_title( $plugin['Name'] ) . '-next';
504 339
505 340 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>';
506 - FrmAppHelper::kses_echo( $message, 'a' );
341 + echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
507 342 echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
508 343 echo '</p></div></td></tr>';
509 344 }
510 345
511 - /**
512 - * @param mixed $transient
513 - *
514 - * @return mixed
515 - */
516 346 public function clear_expired_download( $transient ) {
517 347 if ( ! is_object( $transient ) ) {
518 348 return $transient;
519 349 }
@@ -544,22 +374,18 @@
544 374 *
545 375 * @since 3.04.03
546 376 *
547 377 * @param object $transient The current plugin info saved for update.
548 - *
549 - * @return void
550 378 */
551 379 private function prepare_update_details( &$transient ) {
552 380 $version_info = $transient;
553 - $has_beta_url = ! empty( $version_info->beta );
554 -
381 + $has_beta_url = isset( $version_info->beta ) && ! empty( $version_info->beta );
555 382 if ( $this->get_beta && ! $has_beta_url ) {
556 383 $version_info = (object) $this->get_api_info( $this->license );
557 384 }
558 385
559 - if ( ! empty( $version_info->new_version ) ) {
386 + if ( isset( $version_info->new_version ) && ! empty( $version_info->new_version ) ) {
560 387 $this->clear_old_plugin_version( $version_info );
561 -
562 388 if ( $version_info === false ) {
563 389 // Was cleared with timeout.
564 390 $transient = false;
565 391 } else {
@@ -575,12 +401,8 @@
575 401 /**
576 402 * Get the API info for this plugin
577 403 *
578 404 * @since 3.04.03
579 - *
580 - * @param string $license The license key.
581 - *
582 - * @return array The API info for the plugin.
583 405 */
584 406 protected function get_api_info( $license ) {
585 407 $api = new FrmFormApi( $license );
586 408 $addon = $api->get_addon_for_license( $this );
@@ -601,16 +423,11 @@
601 423 * Make sure transients don't stick around on sites that
602 424 * don't save the transient expiration
603 425 *
604 426 * @since 2.05.05
605 - *
606 - * @param object $version_info The version info for the plugin.
607 - *
608 - * @return void
609 427 */
610 428 private function clear_old_plugin_version( &$version_info ) {
611 - $timeout = ! empty( $version_info->timeout ) ? $version_info->timeout : 0;
612 -
429 + $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0;
613 430 if ( ! empty( $timeout ) && time() > $timeout ) {
614 431 // Cache is expired.
615 432 $version_info = false;
616 433 $api = new FrmFormApi( $this->license );
@@ -622,36 +439,25 @@
622 439 * The beta url is always included if the download has a beta.
623 440 * Check if the beta should be downloaded.
624 441 *
625 442 * @since 3.04.03
626 - *
627 - * @param object $version_info The version info for the plugin.
628 - *
629 - * @return void
630 443 */
631 444 private function maybe_use_beta_url( &$version_info ) {
632 - if ( $this->get_beta && ! empty( $version_info->beta ) ) {
445 + if ( $this->get_beta && isset( $version_info->beta ) && ! empty( $version_info->beta ) ) {
633 446 $version_info->new_version = $version_info->beta['version'];
634 447 $version_info->package = $version_info->beta['package'];
635 -
636 - if ( ! empty( $version_info->plugin ) ) {
448 + if ( isset( $version_info->plugin ) && ! empty( $version_info->plugin ) ) {
637 449 $version_info->plugin = $version_info->beta['plugin'];
638 450 }
639 451 }
640 452 }
641 453
642 - /**
643 - * @param object $transient
644 - *
645 - * @return bool
646 - */
647 454 private function is_current_version( $transient ) {
648 455 if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) {
649 456 return false;
650 457 }
651 458
652 - $response = empty( $transient->response );
653 -
459 + $response = ! isset( $transient->response ) || empty( $transient->response );
654 460 if ( $response ) {
655 461 return true;
656 462 }
657 463
@@ -657,43 +463,36 @@
657 463
658 464 return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version;
659 465 }
660 466
661 - /**
662 - * @return bool
663 - */
664 467 private function has_been_cleared() {
665 468 $last_cleared = get_option( 'frm_last_cleared' );
666 - return $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) );
469 +
470 + return ( $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) );
667 471 }
668 472
669 - /**
670 - * @return void
671 - */
672 473 private function cleared_plugins() {
673 474 update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
674 475 }
675 476
676 - /**
677 - * @return void
678 - */
679 477 private function is_license_revoked() {
680 - if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
478 + if ( self::$sent_mothership_request ) {
681 479 return;
682 480 }
683 481
684 - if ( $this->get_defined_license() ) {
685 - // Don't check if the license is defined in wp-config.php since we can't remove it.
482 + if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
686 483 return;
687 484 }
688 485
689 486 // Only check weekly.
690 - if ( $this->checked_recently( '7 days', 'valid' ) || $this->is_running() ) {
487 + if ( $this->checked_recently( '7 days' ) ) {
691 488 return;
692 489 }
693 490
491 + self::$sent_mothership_request = true;
492 + $this->update_last_checked();
493 +
694 494 $response = $this->get_license_status();
695 -
696 495 if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) {
697 496 $this->clear_license();
698 497 }
699 498 }
@@ -700,37 +499,19 @@
700 499
701 500 /**
702 501 * Has this been checked too recently?
703 502 *
704 - * @param string $time ie. '1 day'.
705 - * @param string $required_status Return false if the last check does not match. ie 'valid'.
706 - *
503 + * @param string $time ie. '1 day'.
707 504 * @return bool
708 505 */
709 - private function checked_recently( $time, $required_status = '' ) {
506 + private function checked_recently( $time ) {
710 507 $last_checked = $this->last_checked();
711 - $is_429 = isset( $last_checked['response_code'] ) && 429 === $last_checked['response_code'];
712 -
713 - if ( $is_429 ) {
714 - // If the last check was a a rate limit, we'll need to check again sooner.
715 - $time = '5 minutes';
716 - $required_status = '';
717 - }
718 -
719 - if ( $required_status && ( ! isset( $last_checked['status'] ) || $last_checked['status'] !== $required_status ) ) {
720 - // If the last check was invalid, we don't need to check again.
721 - return true;
722 - }
723 -
724 - $checked_time = $last_checked['time'] ?? false;
725 508 $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) );
726 - return $checked_time && $checked_time > $time_ago;
509 + return $last_checked && $last_checked > $time_ago;
727 510 }
728 511
729 512 /**
730 - * @since 6.8.3 Switched to an array to store extra response info.
731 - *
732 - * @return array
513 + * @return bool|string
733 514 */
734 515 private function last_checked() {
735 516 if ( is_multisite() ) {
736 517 $last_checked = get_site_option( $this->transient_key() );
@@ -736,15 +517,9 @@
736 517 $last_checked = get_site_option( $this->transient_key() );
737 518 } else {
738 519 $last_checked = get_option( $this->transient_key() );
739 520 }
740 -
741 - if ( $last_checked && ! is_array( $last_checked ) ) {
742 - // Get string into array for existing values.
743 - $last_checked = array( 'time' => $last_checked );
744 - }
745 -
746 - return $last_checked ? $last_checked : array();
521 + return $last_checked;
747 522 }
748 523
749 524 /**
750 525 * @return void
@@ -749,35 +524,27 @@
749 524 /**
750 525 * @return void
751 526 */
752 527 private function update_last_checked() {
753 - $this->save_response['time'] = gmdate( 'Y-m-d H:i:s' );
754 -
755 528 if ( is_multisite() ) {
756 - update_site_option( $this->transient_key(), $this->save_response );
529 + update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
757 530 } else {
758 - update_option( $this->transient_key(), $this->save_response );
531 + update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
759 532 }
760 533 }
761 534
762 535 /**
763 536 * Use a new cache after the license is changed, or Formidable is updated.
764 - *
765 - * @return string
766 537 */
767 538 private function transient_key() {
768 539 return 'frm_' . md5( sanitize_key( $this->license . '_' . $this->plugin_slug ) );
769 540 }
770 541
771 - /**
772 - * @return void
773 - */
774 542 public static function activate() {
775 543 FrmAppHelper::permission_check( 'frm_change_settings' );
776 544 check_ajax_referer( 'frm_ajax', 'nonce' );
777 545
778 546 $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
779 -
780 547 if ( empty( $license ) ) {
781 548 wp_send_json(
782 549 array(
783 550 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
@@ -788,20 +555,13 @@
788 555
789 556 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
790 557 $response = self::activate_license_for_plugin( $license, $plugin_slug );
791 558
792 - FrmInbox::clear_cache();
793 -
794 559 wp_send_json( $response );
795 560 }
796 561
797 562 /**
798 563 * @since 4.08
799 - *
800 - * @param string $license The license key.
801 - * @param string $plugin_slug The plugin slug.
802 - *
803 - * @return array The response from the license activation.
804 564 */
805 565 public static function activate_license_for_plugin( $license, $plugin_slug ) {
806 566 $this_plugin = self::get_addon( $plugin_slug );
807 567 return $this_plugin->activate_license( $license );
@@ -806,13 +566,8 @@
806 566 $this_plugin = self::get_addon( $plugin_slug );
807 567 return $this_plugin->activate_license( $license );
808 568 }
809 569
810 - /**
811 - * @param string $license The license key.
812 - *
813 - * @return array The response from the license activation.
814 - */
815 570 private function activate_license( $license ) {
816 571 $this->set_license( $license );
817 572 $this->license = $license;
818 573
@@ -825,9 +580,8 @@
825 580 if ( $response['error'] ) {
826 581 $response['message'] = $response['status'];
827 582 } else {
828 583 $messages = $this->get_messages();
829 -
830 584 if ( is_string( $response['status'] ) && isset( $messages[ $response['status'] ] ) ) {
831 585 $response['message'] = $messages[ $response['status'] ];
832 586 } else {
833 587 $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) );
@@ -833,14 +587,13 @@
833 587 $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) );
834 588 }
835 589
836 590 $is_valid = false;
837 -
838 591 if ( 'valid' === $response['status'] ) {
839 592 $is_valid = 'valid';
840 593 $response['success'] = true;
841 594 }
842 - $this->maybe_set_active( $is_valid );
595 + $this->set_active( $is_valid );
843 596 }
844 597
845 598 $this->update_last_checked();
846 599
@@ -865,19 +618,13 @@
865 618 )
866 619 );
867 620 }
868 621
869 - /**
870 - * @return array
871 - */
872 622 private function get_license_status() {
873 - $this->set_running();
874 -
875 623 $response = array(
876 624 'status' => 'missing',
877 625 'error' => true,
878 626 );
879 -
880 627 if ( empty( $this->license ) ) {
881 628 $response['error'] = false;
882 629
883 630 return $response;
@@ -889,10 +636,9 @@
889 636
890 637 // $license_data->license will be either "valid" or "invalid"
891 638 if ( is_array( $license_data ) ) {
892 639 if ( ! empty( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
893 - $response['status'] = $license_data['license'];
894 - $this->save_status['status'] = $license_data['license'];
640 + $response['status'] = $license_data['license'];
895 641 }
896 642 } else {
897 643 $response['status'] = $license_data;
898 644 }
@@ -899,16 +645,11 @@
899 645 } catch ( Exception $e ) {
900 646 $response['status'] = $e->getMessage();
901 647 }
902 648
903 - $this->update_last_checked();
904 - $this->done_running();
905 649 return $response;
906 650 }
907 651
908 - /**
909 - * @return array
910 - */
911 652 private function get_messages() {
912 653 return array(
913 654 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ),
914 655 'invalid' => __( 'That license key is invalid', 'formidable' ),
@@ -921,10 +662,8 @@
921 662 }
922 663
923 664 /**
924 665 * @since 4.03
925 - *
926 - * @return void
927 666 */
928 667 public static function reset_cache() {
929 668 FrmAppHelper::permission_check( 'frm_change_settings' );
930 669 check_ajax_referer( 'frm_ajax', 'nonce' );
@@ -939,11 +678,8 @@
939 678
940 679 wp_send_json( $response );
941 680 }
942 681
943 - /**
944 - * @return void
945 - */
946 682 public static function deactivate() {
947 683 FrmAppHelper::permission_check( 'frm_change_settings' );
948 684 check_ajax_referer( 'frm_ajax', 'nonce' );
949 685
@@ -952,13 +688,11 @@
952 688 $response = array(
953 689 'success' => false,
954 690 'message' => '',
955 691 );
956 -
957 692 try {
958 693 // $license_data->license will be either "deactivated" or "failed"
959 694 $license_data = $this_plugin->send_mothership_request( 'deactivate_license' );
960 -
961 695 if ( is_array( $license_data ) && 'deactivated' === $license_data['license'] ) {
962 696 $response['success'] = true;
963 697 $response['message'] = __( 'That license was removed successfully', 'formidable' );
964 698 } else {
@@ -968,9 +702,8 @@
968 702 $response['message'] = $e->getMessage();
969 703 }
970 704
971 705 $this_plugin->clear_license();
972 - FrmInbox::clear_cache();
973 706
974 707 wp_send_json( $response );
975 708 }
976 709
@@ -975,10 +708,8 @@
975 708 }
976 709
977 710 /**
978 711 * @since 4.03
979 - *
980 - * @return FrmAddon
981 712 */
982 713 private static function set_license_from_post() {
983 714 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
984 715 $this_plugin = self::get_addon( $plugin_slug );
@@ -987,10 +718,8 @@
987 718 return $this_plugin;
988 719 }
989 720
990 721 /**
991 - * @param string $action
992 - *
993 722 * @return string
994 723 */
995 724 public function send_mothership_request( $action ) {
996 725 $api_params = array(
@@ -997,9 +726,8 @@
997 726 'edd_action' => $action,
998 727 'license' => $this->license,
999 728 'url' => home_url(),
1000 729 );
1001 -
1002 730 if ( is_numeric( $this->download_id ) ) {
1003 731 $api_params['item_id'] = absint( $this->download_id );
1004 732 } else {
1005 733 $api_params['item_name'] = rawurlencode( $this->plugin_name );
@@ -1010,27 +738,24 @@
1010 738 'timeout' => 25,
1011 739 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
1012 740 );
1013 741
1014 - $resp = wp_remote_post(
742 + $resp = wp_remote_post(
1015 743 $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ),
1016 744 $arg_array
1017 745 );
1018 - $body = wp_remote_retrieve_body( $resp );
1019 - $this->save_status = array( 'response_code' => wp_remote_retrieve_response_code( $resp ) );
746 + $body = wp_remote_retrieve_body( $resp );
1020 747
1021 748 $message = __( 'Your License Key was invalid', 'formidable' );
1022 -
1023 749 if ( is_wp_error( $resp ) ) {
1024 750 $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' );
1025 751 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
1026 - $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>' );
752 + $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>' );
1027 753 $message .= ' ' . $resp->get_error_message();
1028 754 } elseif ( 'error' === $body || is_wp_error( $body ) ) {
1029 755 $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' );
1030 756 } else {
1031 757 $json_res = json_decode( $body, true );
1032 -
1033 758 if ( null !== $json_res ) {
1034 759 if ( is_array( $json_res ) && isset( $json_res['error'] ) ) {
1035 760 $message = $json_res['error'];
1036 761 } else {
@@ -1050,11 +775,8 @@
1050 775
1051 776 return $message;
1052 777 }
1053 778
1054 - /**
1055 - * @return void
1056 - */
1057 779 public function manually_queue_update() {
1058 780 $updates = new stdClass();
1059 781 $updates->last_checked = 0;
1060 782 $updates->response = array();
@@ -1061,46 +783,6 @@
1061 783 $updates->translations = array();
1062 784 $updates->no_update = array();
1063 785 $updates->checked = array();
1064 786 set_site_transient( 'update_plugins', $updates );
1065 - }
1066 -
1067 - /**
1068 - * Set the transient key for the lock. It should be unique to the license.
1069 - *
1070 - * @since 6.8.3
1071 - *
1072 - * @return bool
1073 - */
1074 - protected function lock_key() {
1075 - return $this->transient_lock_key . '_' . $this->license;
1076 - }
1077 -
1078 - /**
1079 - * Prevent multiple requests from running at the same time.
1080 - *
1081 - * @since 6.8.3
1082 - *
1083 - * @return bool
1084 - */
1085 - protected function is_running() {
1086 - return get_transient( $this->lock_key() );
1087 - }
1088 -
1089 - /**
1090 - * @since 6.8.3
1091 - *
1092 - * @return void
1093 - */
1094 - protected function set_running() {
1095 - set_transient( $this->lock_key(), true, 2 * MINUTE_IN_SECONDS );
1096 - }
1097 -
1098 - /**
1099 - * @since 6.8.3
1100 - *
1101 - * @return void
1102 - */
1103 - protected function done_running() {
1104 - delete_transient( $this->lock_key() );
1105 787 }
1106 788 }