PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.2
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
formidable / classes / models / FrmAddon.php

FrmAddon.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.8.2, at classes/models/FrmAddon.php

789 lines 22.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /** @phpstan-consistent-constructor */
7 class FrmAddon {
8 public $store_url = 'https://formidableforms.com';
9 public $download_id;
10 public $plugin_file;
11 public $plugin_folder;
12 public $plugin_name;
13 public $plugin_slug;
14 public $option_name;
15 public $version;
16 public $author = 'Strategy11';
17 public $is_parent_licence = false;
18 public $needs_license = true;
19 private $is_expired_addon = false;
20 public $license;
21 protected $get_beta = false;
22
23 /**
24 * This is used to flag other add ons not to send a request.
25 * We only want to send a single API request per HTTP request.
26 *
27 * @since 6.7.1
28 *
29 * @var bool
30 */
31 private static $sent_mothership_request = false;
32
33 public function __construct() {
34
35 if ( empty( $this->plugin_slug ) ) {
36 $this->plugin_slug = preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->plugin_name ) ) );
37 }
38 if ( empty( $this->option_name ) ) {
39 $this->option_name = 'edd_' . $this->plugin_slug . '_license_';
40 }
41
42 $this->plugin_folder = plugin_basename( $this->plugin_file );
43 $this->license = $this->get_license();
44
45 add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) );
46 $this->edd_plugin_updater();
47 }
48
49 public static function load_hooks() {
50 add_filter( 'frm_include_addon_page', '__return_true' );
51 new static();
52 }
53
54 public function insert_installed_addon( $plugins ) {
55 $plugins[ $this->plugin_slug ] = $this;
56
57 return $plugins;
58 }
59
60 public static function get_addon( $plugin_slug ) {
61 $plugins = apply_filters( 'frm_installed_addons', array() );
62 $plugin = false;
63 if ( isset( $plugins[ $plugin_slug ] ) ) {
64 $plugin = $plugins[ $plugin_slug ];
65 }
66
67 return $plugin;
68 }
69
70 public function edd_plugin_updater() {
71
72 $this->is_license_revoked();
73 $license = $this->license;
74
75 add_action( 'after_plugin_row_' . plugin_basename( $this->plugin_file ), array( $this, 'maybe_show_license_message' ), 10, 2 );
76
77 if ( ! empty( $license ) ) {
78
79 if ( 'formidable/formidable.php' !== $this->plugin_folder ) {
80 add_filter( 'plugins_api', array( &$this, 'plugins_api_filter' ), 10, 3 );
81 }
82
83 add_filter( 'site_transient_update_plugins', array( &$this, 'clear_expired_download' ) );
84 }
85 }
86
87 /**
88 * Updates information on the "View version x.x details" page with custom data.
89 *
90 * @uses api_request()
91 *
92 * @param mixed $_data
93 * @param string $_action
94 * @param object $_args
95 *
96 * @return object $_data
97 */
98 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
99
100 if ( $_action != 'plugin_information' ) {
101 return $_data;
102 }
103
104 $slug = basename( $this->plugin_file, '.php' );
105 $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder );
106 if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) {
107 return $_data;
108 }
109
110 $item_id = $this->download_id;
111 if ( empty( $item_id ) ) {
112 $_data = array(
113 'name' => $this->plugin_name,
114 'excerpt' => '',
115 'changelog' => 'See the full changelog at <a href="' . esc_url( $this->store_url . '/changelog/' ) . '"></a>',
116 'banners' => array(
117 'high' => '',
118 'low' => 'https://ps.w.org/formidable/assets/banner-1544x500.png',
119 ),
120 );
121 } else {
122 $api = new FrmFormApi( $this->license );
123 $plugins = $api->get_api_info();
124 $_data = $plugins[ $item_id ];
125 }
126
127 $_data['sections'] = array(
128 'description' => $_data['excerpt'],
129 'changelog' => $_data['changelog'],
130 );
131 $_data['author'] = '<a href="' . esc_url( $this->store_url ) . '">' . esc_html( $this->author ) . '</a>';
132 $_data['homepage'] = $this->store_url;
133
134 return (object) $_data;
135 }
136
137 public function get_license() {
138 $license = $this->maybe_get_pro_license();
139 if ( ! empty( $license ) ) {
140 return $license;
141 }
142
143 $license = trim( get_option( $this->option_name . 'key' ) );
144 if ( empty( $license ) ) {
145 $license = $this->activate_defined_license();
146 }
147
148 return $license;
149 }
150
151 /**
152 * @since 3.04.03
153 */
154 protected function maybe_get_pro_license() {
155 // prevent a loop if $this is the pro plugin
156 $get_license = FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::get_updater' ) && $this->plugin_name != 'Formidable Pro';
157
158 if ( ! $get_license ) {
159 return false;
160 }
161
162 $api = new FrmFormApi();
163 $api->get_pro_updater();
164 $license = $api->get_license();
165 if ( empty( $license ) ) {
166 return false;
167 }
168
169 $this->get_api_info( $license );
170 if ( ! $this->is_parent_licence ) {
171 $license = false;
172 }
173
174 return $license;
175 }
176
177 /**
178 * Activate the license in wp-config.php
179 *
180 * @since 2.04
181 */
182 public function activate_defined_license() {
183 $license = $this->get_defined_license();
184 if ( ! empty( $license ) && ! $this->is_active() && $this->is_time_to_auto_activate() ) {
185 $response = $this->activate_license( $license );
186 $this->set_auto_activate_time();
187 if ( ! $response['success'] ) {
188 $license = '';
189 }
190 }
191
192 return $license;
193 }
194
195 /**
196 * Check the wp-config.php for the license key
197 *
198 * @since 2.04
199 */
200 public function get_defined_license() {
201 $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE';
202
203 return defined( $consant_name ) ? constant( $consant_name ) : false;
204 }
205
206 public function set_license( $license ) {
207 update_option( $this->option_name . 'key', $license );
208 }
209
210 /**
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
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
226 public function is_active() {
227 return get_option( $this->option_name . 'active' );
228 }
229
230 /**
231 * @since 3.04.03
232 *
233 * @param array|string $error
234 */
235 public function maybe_clear_license( $error ) {
236 if ( is_array( $error ) && $error['code'] === 'disabled' && $error['license'] === $this->license ) {
237 $this->clear_license();
238 }
239 }
240
241 public function clear_license() {
242 delete_option( $this->option_name . 'active' );
243 delete_option( $this->option_name . 'key' );
244 delete_site_option( $this->transient_key() );
245 delete_option( $this->transient_key() );
246 $this->delete_cache();
247 }
248
249 public function set_active( $is_active ) {
250 update_option( $this->option_name . 'active', $is_active );
251 $this->delete_cache();
252 FrmAppHelper::save_combined_js();
253 $this->update_pro_capabilities();
254 }
255
256 /**
257 * Updates roles capabilities after pro license is active.
258 *
259 * @since 5.0
260 */
261 protected function update_pro_capabilities() {
262 global $wp_roles;
263
264 if ( ! function_exists( 'get_editable_roles' ) ) {
265 require_once ABSPATH . 'wp-admin/includes/user.php';
266 }
267
268 $caps = FrmAppHelper::frm_capabilities( 'pro_only' );
269 $roles = get_editable_roles();
270 $settings = new FrmSettings();
271 foreach ( $caps as $cap => $cap_desc ) {
272 $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' );
273
274 // Make sure administrators always have permissions.
275 if ( ! in_array( 'administrator', $cap_roles ) ) {
276 array_push( $cap_roles, 'administrator' );
277 }
278
279 foreach ( $roles as $role => $details ) {
280 if ( in_array( $role, $cap_roles ) ) {
281 $wp_roles->add_cap( $role, $cap );
282 } else {
283 $wp_roles->remove_cap( $role, $cap );
284 }
285 }
286 }
287 }
288
289 /**
290 * @since 3.04.03
291 */
292 protected function delete_cache() {
293 delete_transient( 'frm_api_licence' );
294
295 $api = new FrmFormApi( $this->license );
296 $api->reset_cached();
297
298 $api = new FrmFormTemplateApi( $this->license );
299 $api->reset_cached();
300
301 $api = new FrmApplicationApi( $this->license );
302 $api->reset_cached();
303 }
304
305 /**
306 * The Pro version includes the show_license_message function.
307 * We need an extra check before we allow it to show a message.
308 *
309 * @since 3.04.03
310 */
311 public function maybe_show_license_message( $file, $plugin ) {
312 if ( $this->is_expired_addon || isset( $plugin['package'] ) ) {
313 // let's not show a ton of duplicate messages
314 return;
315 }
316
317 $this->show_license_message( $file, $plugin );
318 }
319
320 public function show_license_message( $file, $plugin ) {
321 $message = '';
322 if ( empty( $this->license ) ) {
323 /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */
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>' );
325 } else {
326 $api = new FrmFormApi( $this->license );
327 $errors = $api->error_for_license();
328 if ( ! empty( $errors ) ) {
329 $message = reset( $errors );
330 }
331 }
332
333 if ( empty( $message ) ) {
334 return;
335 }
336
337 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
338 $id = sanitize_title( $plugin['Name'] ) . '-next';
339
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>';
341 echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
342 echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>';
343 echo '</p></div></td></tr>';
344 }
345
346 public function clear_expired_download( $transient ) {
347 if ( ! is_object( $transient ) ) {
348 return $transient;
349 }
350
351 if ( $this->is_current_version( $transient ) ) {
352 // Make sure it doesn't show there is an update if plugin is up-to-date.
353 if ( isset( $transient->response[ $this->plugin_folder ] ) ) {
354 unset( $transient->response[ $this->plugin_folder ] );
355 }
356 } elseif ( isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) ) {
357 $this->prepare_update_details( $transient->response[ $this->plugin_folder ] );
358
359 // if the transient has expired, clear the update and trigger it again
360 if ( $transient->response[ $this->plugin_folder ] === false ) {
361 if ( ! $this->has_been_cleared() ) {
362 $this->cleared_plugins();
363 $this->manually_queue_update();
364 }
365 unset( $transient->response[ $this->plugin_folder ] );
366 }
367 }
368
369 return $transient;
370 }
371
372 /**
373 * Check if the plugin information is correct to allow an update
374 *
375 * @since 3.04.03
376 *
377 * @param object $transient The current plugin info saved for update.
378 */
379 private function prepare_update_details( &$transient ) {
380 $version_info = $transient;
381 $has_beta_url = isset( $version_info->beta ) && ! empty( $version_info->beta );
382 if ( $this->get_beta && ! $has_beta_url ) {
383 $version_info = (object) $this->get_api_info( $this->license );
384 }
385
386 if ( isset( $version_info->new_version ) && ! empty( $version_info->new_version ) ) {
387 $this->clear_old_plugin_version( $version_info );
388 if ( $version_info === false ) {
389 // Was cleared with timeout.
390 $transient = false;
391 } else {
392 $this->maybe_use_beta_url( $version_info );
393
394 if ( version_compare( $version_info->new_version, $this->version, '>' ) ) {
395 $transient = $version_info;
396 }
397 }
398 }
399 }
400
401 /**
402 * Get the API info for this plugin
403 *
404 * @since 3.04.03
405 */
406 protected function get_api_info( $license ) {
407 $api = new FrmFormApi( $license );
408 $addon = $api->get_addon_for_license( $this );
409
410 // if there is no download url, this license does not apply to the addon
411 if ( isset( $addon['package'] ) ) {
412 $this->is_parent_licence = true;
413 } elseif ( isset( $addon['error'] ) ) {
414 // if the license is expired, we must assume all add-ons were packaged
415 $this->is_parent_licence = true;
416 $this->is_expired_addon = true;
417 }
418
419 return $addon;
420 }
421
422 /**
423 * Make sure transients don't stick around on sites that
424 * don't save the transient expiration
425 *
426 * @since 2.05.05
427 */
428 private function clear_old_plugin_version( &$version_info ) {
429 $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0;
430 if ( ! empty( $timeout ) && time() > $timeout ) {
431 // Cache is expired.
432 $version_info = false;
433 $api = new FrmFormApi( $this->license );
434 $api->reset_cached();
435 }
436 }
437
438 /**
439 * The beta url is always included if the download has a beta.
440 * Check if the beta should be downloaded.
441 *
442 * @since 3.04.03
443 */
444 private function maybe_use_beta_url( &$version_info ) {
445 if ( $this->get_beta && isset( $version_info->beta ) && ! empty( $version_info->beta ) ) {
446 $version_info->new_version = $version_info->beta['version'];
447 $version_info->package = $version_info->beta['package'];
448 if ( isset( $version_info->plugin ) && ! empty( $version_info->plugin ) ) {
449 $version_info->plugin = $version_info->beta['plugin'];
450 }
451 }
452 }
453
454 private function is_current_version( $transient ) {
455 if ( empty( $transient->checked ) || ! isset( $transient->checked[ $this->plugin_folder ] ) ) {
456 return false;
457 }
458
459 $response = ! isset( $transient->response ) || empty( $transient->response );
460 if ( $response ) {
461 return true;
462 }
463
464 return isset( $transient->response ) && isset( $transient->response[ $this->plugin_folder ] ) && $transient->checked[ $this->plugin_folder ] === $transient->response[ $this->plugin_folder ]->new_version;
465 }
466
467 private function has_been_cleared() {
468 $last_cleared = get_option( 'frm_last_cleared' );
469
470 return ( $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) );
471 }
472
473 private function cleared_plugins() {
474 update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) );
475 }
476
477 private function is_license_revoked() {
478 if ( self::$sent_mothership_request ) {
479 return;
480 }
481
482 if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
483 return;
484 }
485
486 // Only check weekly.
487 if ( $this->checked_recently( '7 days' ) ) {
488 return;
489 }
490
491 self::$sent_mothership_request = true;
492 $this->update_last_checked();
493
494 $response = $this->get_license_status();
495 if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) {
496 $this->clear_license();
497 }
498 }
499
500 /**
501 * Has this been checked too recently?
502 *
503 * @param string $time ie. '1 day'.
504 * @return bool
505 */
506 private function checked_recently( $time ) {
507 $last_checked = $this->last_checked();
508 $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) );
509 return $last_checked && $last_checked > $time_ago;
510 }
511
512 /**
513 * @return bool|string
514 */
515 private function last_checked() {
516 if ( is_multisite() ) {
517 $last_checked = get_site_option( $this->transient_key() );
518 } else {
519 $last_checked = get_option( $this->transient_key() );
520 }
521 return $last_checked;
522 }
523
524 /**
525 * @return void
526 */
527 private function update_last_checked() {
528 if ( is_multisite() ) {
529 update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
530 } else {
531 update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) );
532 }
533 }
534
535 /**
536 * Use a new cache after the license is changed, or Formidable is updated.
537 */
538 private function transient_key() {
539 return 'frm_' . md5( sanitize_key( $this->license . '_' . $this->plugin_slug ) );
540 }
541
542 public static function activate() {
543 FrmAppHelper::permission_check( 'frm_change_settings' );
544 check_ajax_referer( 'frm_ajax', 'nonce' );
545
546 $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) );
547 if ( empty( $license ) ) {
548 wp_send_json(
549 array(
550 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ),
551 'success' => false,
552 )
553 );
554 }
555
556 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
557 $response = self::activate_license_for_plugin( $license, $plugin_slug );
558
559 wp_send_json( $response );
560 }
561
562 /**
563 * @since 4.08
564 */
565 public static function activate_license_for_plugin( $license, $plugin_slug ) {
566 $this_plugin = self::get_addon( $plugin_slug );
567 return $this_plugin->activate_license( $license );
568 }
569
570 private function activate_license( $license ) {
571 $this->set_license( $license );
572 $this->license = $license;
573
574 $this->die_if_not_allowed();
575
576 $response = $this->get_license_status();
577 $response['message'] = '';
578 $response['success'] = false;
579
580 if ( $response['error'] ) {
581 $response['message'] = $response['status'];
582 } else {
583 $messages = $this->get_messages();
584 if ( is_string( $response['status'] ) && isset( $messages[ $response['status'] ] ) ) {
585 $response['message'] = $messages[ $response['status'] ];
586 } else {
587 $response['message'] = FrmAppHelper::kses( $response['status'], array( 'a' ) );
588 }
589
590 $is_valid = false;
591 if ( 'valid' === $response['status'] ) {
592 $is_valid = 'valid';
593 $response['success'] = true;
594 }
595 $this->set_active( $is_valid );
596 }
597
598 $this->update_last_checked();
599
600 return $response;
601 }
602
603 /**
604 * Prevent this check from happening more than once per minute with the same license.
605 *
606 * @return void
607 */
608 private function die_if_not_allowed() {
609 if ( ! $this->checked_recently( '2 minutes' ) ) {
610 return;
611 }
612
613 // Don't check more than once per minute.
614 wp_send_json(
615 array(
616 'message' => __( 'Please wait two minutes before trying again.', 'formidable' ),
617 'success' => false,
618 )
619 );
620 }
621
622 private function get_license_status() {
623 $response = array(
624 'status' => 'missing',
625 'error' => true,
626 );
627 if ( empty( $this->license ) ) {
628 $response['error'] = false;
629
630 return $response;
631 }
632
633 try {
634 $response['error'] = false;
635 $license_data = $this->send_mothership_request( 'activate_license' );
636
637 // $license_data->license will be either "valid" or "invalid"
638 if ( is_array( $license_data ) ) {
639 if ( ! empty( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) {
640 $response['status'] = $license_data['license'];
641 }
642 } else {
643 $response['status'] = $license_data;
644 }
645 } catch ( Exception $e ) {
646 $response['status'] = $e->getMessage();
647 }
648
649 return $response;
650 }
651
652 private function get_messages() {
653 return array(
654 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ),
655 'invalid' => __( 'That license key is invalid', 'formidable' ),
656 'expired' => __( 'That license is expired', 'formidable' ),
657 'revoked' => __( 'That license has been refunded', 'formidable' ),
658 'no_activations_left' => __( 'That license has been used on too many sites', 'formidable' ),
659 'invalid_item_id' => __( 'Oops! That is the wrong license key for this plugin.', 'formidable' ),
660 'missing' => __( 'That license key is invalid', 'formidable' ),
661 );
662 }
663
664 /**
665 * @since 4.03
666 */
667 public static function reset_cache() {
668 FrmAppHelper::permission_check( 'frm_change_settings' );
669 check_ajax_referer( 'frm_ajax', 'nonce' );
670
671 $this_plugin = self::set_license_from_post();
672 $this_plugin->delete_cache();
673
674 $response = array(
675 'success' => true,
676 'message' => __( 'Cache cleared', 'formidable' ),
677 );
678
679 wp_send_json( $response );
680 }
681
682 public static function deactivate() {
683 FrmAppHelper::permission_check( 'frm_change_settings' );
684 check_ajax_referer( 'frm_ajax', 'nonce' );
685
686 $this_plugin = self::set_license_from_post();
687
688 $response = array(
689 'success' => false,
690 'message' => '',
691 );
692 try {
693 // $license_data->license will be either "deactivated" or "failed"
694 $license_data = $this_plugin->send_mothership_request( 'deactivate_license' );
695 if ( is_array( $license_data ) && 'deactivated' === $license_data['license'] ) {
696 $response['success'] = true;
697 $response['message'] = __( 'That license was removed successfully', 'formidable' );
698 } else {
699 $response['message'] = __( 'There was an error deactivating your license.', 'formidable' );
700 }
701 } catch ( Exception $e ) {
702 $response['message'] = $e->getMessage();
703 }
704
705 $this_plugin->clear_license();
706
707 wp_send_json( $response );
708 }
709
710 /**
711 * @since 4.03
712 */
713 private static function set_license_from_post() {
714 $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
715 $this_plugin = self::get_addon( $plugin_slug );
716 $license = $this_plugin->get_license();
717 $this_plugin->license = $license;
718 return $this_plugin;
719 }
720
721 /**
722 * @return string
723 */
724 public function send_mothership_request( $action ) {
725 $api_params = array(
726 'edd_action' => $action,
727 'license' => $this->license,
728 'url' => home_url(),
729 );
730 if ( is_numeric( $this->download_id ) ) {
731 $api_params['item_id'] = absint( $this->download_id );
732 } else {
733 $api_params['item_name'] = rawurlencode( $this->plugin_name );
734 }
735
736 $arg_array = array(
737 'body' => $api_params,
738 'timeout' => 25,
739 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ),
740 );
741
742 $resp = wp_remote_post(
743 $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ),
744 $arg_array
745 );
746 $body = wp_remote_retrieve_body( $resp );
747
748 $message = __( 'Your License Key was invalid', 'formidable' );
749 if ( is_wp_error( $resp ) ) {
750 $link = FrmAppHelper::admin_upgrade_link( 'api', 'knowledgebase/why-cant-i-activate-formidable-pro/' );
751 /* translators: %1$s: Start link HTML, %2$s: End link HTML */
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>' );
753 $message .= ' ' . $resp->get_error_message();
754 } elseif ( 'error' === $body || is_wp_error( $body ) ) {
755 $message = __( 'You had an HTTP error connecting to the Formidable API', 'formidable' );
756 } else {
757 $json_res = json_decode( $body, true );
758 if ( null !== $json_res ) {
759 if ( is_array( $json_res ) && isset( $json_res['error'] ) ) {
760 $message = $json_res['error'];
761 } else {
762 $message = $json_res;
763 }
764 } elseif ( ! empty( $resp['response'] ) && ! empty( $resp['response']['code'] ) ) {
765 $resp['body'] = wp_strip_all_tags( $resp['body'] );
766
767 $message = sprintf(
768 /* translators: %1$s: Error code, %2$s: Error message */
769 esc_html__( 'There was a %1$s error: %2$s', 'formidable' ),
770 esc_html( $resp['response']['code'] ),
771 $resp['response']['message'] . ' ' . $resp['body']
772 );
773 }
774 }//end if
775
776 return $message;
777 }
778
779 public function manually_queue_update() {
780 $updates = new stdClass();
781 $updates->last_checked = 0;
782 $updates->response = array();
783 $updates->translations = array();
784 $updates->no_update = array();
785 $updates->checked = array();
786 set_site_transient( 'update_plugins', $updates );
787 }
788 }
789