| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | 4 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 5 | } |
| 5 | 6 | |
| 6 | -/** @phpstan-consistent-constructor */ | |
| 7 | 7 | class FrmAddon { |
| 8 | 8 | public $store_url = 'https://formidableforms.com'; |
| 9 | 9 | public $download_id; |
| 10 | 10 | public $plugin_file; |
| @@ -14,9 +14,8 @@ | ||
| 14 | 14 | public $option_name; |
| 15 | 15 | public $version; |
| 16 | 16 | public $author = 'Strategy11'; |
| 17 | 17 | public $is_parent_licence = false; |
| 18 | - public $needs_license = true; | |
| 19 | 18 | private $is_expired_addon = false; |
| 20 | 19 | public $license; |
| 21 | 20 | protected $get_beta = false; |
| 22 | 21 | |
| @@ -29,9 +28,9 @@ | ||
| 29 | 28 | $this->option_name = 'edd_' . $this->plugin_slug . '_license_'; |
| 30 | 29 | } |
| 31 | 30 | |
| 32 | 31 | $this->plugin_folder = plugin_basename( $this->plugin_file ); |
| 33 | - $this->license = $this->get_license(); | |
| 32 | + $this->license = $this->get_license(); | |
| 34 | 33 | |
| 35 | 34 | add_filter( 'frm_installed_addons', array( &$this, 'insert_installed_addon' ) ); |
| 36 | 35 | $this->edd_plugin_updater(); |
| 37 | 36 | } |
| @@ -37,24 +36,22 @@ | ||
| 37 | 36 | } |
| 38 | 37 | |
| 39 | 38 | public static function load_hooks() { |
| 40 | 39 | add_filter( 'frm_include_addon_page', '__return_true' ); |
| 41 | - new static(); | |
| 40 | + //new static(); | |
| 42 | 41 | } |
| 43 | 42 | |
| 44 | 43 | public function insert_installed_addon( $plugins ) { |
| 45 | 44 | $plugins[ $this->plugin_slug ] = $this; |
| 46 | - | |
| 47 | 45 | return $plugins; |
| 48 | 46 | } |
| 49 | 47 | |
| 50 | 48 | public static function get_addon( $plugin_slug ) { |
| 51 | 49 | $plugins = apply_filters( 'frm_installed_addons', array() ); |
| 52 | - $plugin = false; | |
| 50 | + $plugin = false; | |
| 53 | 51 | if ( isset( $plugins[ $plugin_slug ] ) ) { |
| 54 | 52 | $plugin = $plugins[ $plugin_slug ]; |
| 55 | 53 | } |
| 56 | - | |
| 57 | 54 | return $plugin; |
| 58 | 55 | } |
| 59 | 56 | |
| 60 | 57 | public function edd_plugin_updater() { |
| @@ -78,12 +75,11 @@ | ||
| 78 | 75 | * Updates information on the "View version x.x details" page with custom data. |
| 79 | 76 | * |
| 80 | 77 | * @uses api_request() |
| 81 | 78 | * |
| 82 | - * @param mixed $_data | |
| 83 | - * @param string $_action | |
| 84 | - * @param object $_args | |
| 85 | - * | |
| 79 | + * @param mixed $_data | |
| 80 | + * @param string $_action | |
| 81 | + * @param object $_args | |
| 86 | 82 | * @return object $_data |
| 87 | 83 | */ |
| 88 | 84 | public function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
| 89 | 85 | |
| @@ -90,11 +86,10 @@ | ||
| 90 | 86 | if ( $_action != 'plugin_information' ) { |
| 91 | 87 | return $_data; |
| 92 | 88 | } |
| 93 | 89 | |
| 94 | - $slug = basename( $this->plugin_file, '.php' ); | |
| 95 | - $slug2 = str_replace( '/' . $slug . '.php', '', $this->plugin_folder ); | |
| 96 | - if ( empty( $_args->slug ) || ( $_args->slug != $slug && $_args->slug !== $slug2 ) ) { | |
| 90 | + $slug = basename( $this->plugin_file, '.php' ); | |
| 91 | + if ( ! isset( $_args->slug ) || $_args->slug != $slug ) { | |
| 97 | 92 | return $_data; |
| 98 | 93 | } |
| 99 | 94 | |
| 100 | 95 | $item_id = $this->download_id; |
| @@ -102,17 +97,17 @@ | ||
| 102 | 97 | $_data = array( |
| 103 | 98 | 'name' => $this->plugin_name, |
| 104 | 99 | 'excerpt' => '', |
| 105 | 100 | 'changelog' => 'See the full changelog at <a href="' . esc_url( $this->store_url . '/changelog/' ) . '"></a>', |
| 106 | - 'banners' => array( | |
| 107 | - 'high' => '', | |
| 108 | - 'low' => 'https://ps.w.org/formidable/assets/banner-1544x500.png', | |
| 109 | - ), | |
| 101 | + 'banners' => array( | |
| 102 | + 'high' => '', | |
| 103 | + 'low' => 'https://ps.w.org/formidable/assets/banner-1544x500.png', | |
| 104 | + ), | |
| 110 | 105 | ); |
| 111 | 106 | } else { |
| 112 | - $api = new FrmFormApi( $this->license ); | |
| 107 | + $api = new FrmFormApi( $this->license ); | |
| 113 | 108 | $plugins = $api->get_api_info(); |
| 114 | - $_data = $plugins[ $item_id ]; | |
| 109 | + $_data = $plugins[ $item_id ]; | |
| 115 | 110 | } |
| 116 | 111 | |
| 117 | 112 | $_data['sections'] = array( |
| 118 | 113 | 'description' => $_data['excerpt'], |
| @@ -177,9 +172,8 @@ | ||
| 177 | 172 | if ( ! $response['success'] ) { |
| 178 | 173 | $license = ''; |
| 179 | 174 | } |
| 180 | 175 | } |
| 181 | - | |
| 182 | 176 | return $license; |
| 183 | 177 | } |
| 184 | 178 | |
| 185 | 179 | /** |
| @@ -188,9 +182,8 @@ | ||
| 188 | 182 | * @since 2.04 |
| 189 | 183 | */ |
| 190 | 184 | public function get_defined_license() { |
| 191 | 185 | $consant_name = 'FRM_' . strtoupper( $this->plugin_slug ) . '_LICENSE'; |
| 192 | - | |
| 193 | 186 | return defined( $consant_name ) ? constant( $consant_name ) : false; |
| 194 | 187 | } |
| 195 | 188 | |
| 196 | 189 | public function set_license( $license ) { |
| @@ -204,9 +197,8 @@ | ||
| 204 | 197 | * @since 2.04 |
| 205 | 198 | */ |
| 206 | 199 | private function is_time_to_auto_activate() { |
| 207 | 200 | $last_try = get_option( $this->option_name . 'last_activate' ); |
| 208 | - | |
| 209 | 201 | return ( ! $last_try || $last_try < strtotime( '-1 day' ) ); |
| 210 | 202 | } |
| 211 | 203 | |
| 212 | 204 | private function set_auto_activate_time() { |
| @@ -218,9 +210,8 @@ | ||
| 218 | 210 | } |
| 219 | 211 | |
| 220 | 212 | /** |
| 221 | 213 | * @since 3.04.03 |
| 222 | - * | |
| 223 | 214 | * @param array error |
| 224 | 215 | */ |
| 225 | 216 | public function maybe_clear_license( $error ) { |
| 226 | 217 | if ( $error['code'] === 'disabled' && $error['license'] === $this->license ) { |
| @@ -239,45 +230,11 @@ | ||
| 239 | 230 | public function set_active( $is_active ) { |
| 240 | 231 | update_option( $this->option_name . 'active', $is_active ); |
| 241 | 232 | $this->delete_cache(); |
| 242 | 233 | FrmAppHelper::save_combined_js(); |
| 243 | - $this->update_pro_capabilities(); | |
| 244 | 234 | } |
| 245 | 235 | |
| 246 | 236 | /** |
| 247 | - * Updates roles capabilities after pro license is active. | |
| 248 | - * | |
| 249 | - * @since 5.0 | |
| 250 | - */ | |
| 251 | - protected function update_pro_capabilities() { | |
| 252 | - global $wp_roles; | |
| 253 | - | |
| 254 | - if ( ! function_exists( 'get_editable_roles' ) ) { | |
| 255 | - require_once ABSPATH . 'wp-admin/includes/user.php'; | |
| 256 | - } | |
| 257 | - | |
| 258 | - $caps = FrmAppHelper::frm_capabilities( 'pro_only' ); | |
| 259 | - $roles = get_editable_roles(); | |
| 260 | - $settings = new FrmSettings(); | |
| 261 | - foreach ( $caps as $cap => $cap_desc ) { | |
| 262 | - $cap_roles = (array) ( isset( $settings->$cap ) ? $settings->$cap : 'administrator' ); | |
| 263 | - | |
| 264 | - // Make sure administrators always have permissions. | |
| 265 | - if ( ! in_array( 'administrator', $cap_roles ) ) { | |
| 266 | - array_push( $cap_roles, 'administrator' ); | |
| 267 | - } | |
| 268 | - | |
| 269 | - foreach ( $roles as $role => $details ) { | |
| 270 | - if ( in_array( $role, $cap_roles ) ) { | |
| 271 | - $wp_roles->add_cap( $role, $cap ); | |
| 272 | - } else { | |
| 273 | - $wp_roles->remove_cap( $role, $cap ); | |
| 274 | - } | |
| 275 | - } | |
| 276 | - } | |
| 277 | - } | |
| 278 | - | |
| 279 | - /** | |
| 280 | 237 | * @since 3.04.03 |
| 281 | 238 | */ |
| 282 | 239 | protected function delete_cache() { |
| 283 | 240 | delete_transient( 'frm_api_licence' ); |
| @@ -286,11 +243,8 @@ | ||
| 286 | 243 | $api->reset_cached(); |
| 287 | 244 | |
| 288 | 245 | $api = new FrmFormTemplateApi( $this->license ); |
| 289 | 246 | $api->reset_cached(); |
| 290 | - | |
| 291 | - $api = new FrmApplicationApi( $this->license ); | |
| 292 | - $api->reset_cached(); | |
| 293 | 247 | } |
| 294 | 248 | |
| 295 | 249 | /** |
| 296 | 250 | * The Pro version includes the show_license_message function. |
| @@ -310,11 +264,11 @@ | ||
| 310 | 264 | public function show_license_message( $file, $plugin ) { |
| 311 | 265 | $message = ''; |
| 312 | 266 | if ( empty( $this->license ) ) { |
| 313 | 267 | /* translators: %1$s: Plugin name, %2$s: Start link HTML, %3$s: end link HTML */ |
| 314 | - $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>' ); | |
| 268 | + $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&t=licenses_settings' ) ) . '">', '</a>' ); | |
| 315 | 269 | } else { |
| 316 | - $api = new FrmFormApi( $this->license ); | |
| 270 | + $api = new FrmFormApi( $this->license ); | |
| 317 | 271 | $errors = $api->error_for_license(); |
| 318 | 272 | if ( ! empty( $errors ) ) { |
| 319 | 273 | $message = reset( $errors ); |
| 320 | 274 | } |
| @@ -324,12 +278,11 @@ | ||
| 324 | 278 | return; |
| 325 | 279 | } |
| 326 | 280 | |
| 327 | 281 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
| 328 | - $id = sanitize_title( $plugin['Name'] ) . '-next'; | |
| 329 | - | |
| 282 | + $id = sanitize_title( $plugin['Name'] ) . '-next'; | |
| 330 | 283 | 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>'; |
| 331 | - echo FrmAppHelper::kses( $message, 'a' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 284 | + echo FrmAppHelper::kses( $message, 'a' ); // WPCS: XSS ok. | |
| 332 | 285 | echo '<script type="text/javascript">var d = document.getElementById("' . esc_attr( $id ) . '").previousSibling;if ( d !== null ){ d.className = d.className + " update"; }</script>'; |
| 333 | 286 | echo '</p></div></td></tr>'; |
| 334 | 287 | } |
| 335 | 288 | |
| @@ -362,9 +315,8 @@ | ||
| 362 | 315 | /** |
| 363 | 316 | * Check if the plugin information is correct to allow an update |
| 364 | 317 | * |
| 365 | 318 | * @since 3.04.03 |
| 366 | - * | |
| 367 | 319 | * @param object $transient - the current plugin info saved for update |
| 368 | 320 | */ |
| 369 | 321 | private function prepare_update_details( &$transient ) { |
| 370 | 322 | $version_info = $transient; |
| @@ -392,15 +344,15 @@ | ||
| 392 | 344 | * |
| 393 | 345 | * @since 3.04.03 |
| 394 | 346 | */ |
| 395 | 347 | protected function get_api_info( $license ) { |
| 396 | - $api = new FrmFormApi( $license ); | |
| 397 | - $addon = $api->get_addon_for_license( $this ); | |
| 348 | + $api = new FrmFormApi( $license ); | |
| 349 | + $addon = $api->get_addon_for_license( $this ); | |
| 398 | 350 | |
| 399 | 351 | // if there is no download url, this license does not apply to the addon |
| 400 | 352 | if ( isset( $addon['package'] ) ) { |
| 401 | 353 | $this->is_parent_licence = true; |
| 402 | - } elseif ( isset( $addon['error'] ) ) { | |
| 354 | + } elseif ( isset( $addons['error'] ) ) { | |
| 403 | 355 | // if the license is expired, we must assume all add-ons were packaged |
| 404 | 356 | $this->is_parent_licence = true; |
| 405 | 357 | $this->is_expired_addon = true; |
| 406 | 358 | } |
| @@ -417,9 +369,9 @@ | ||
| 417 | 369 | private function clear_old_plugin_version( &$version_info ) { |
| 418 | 370 | $timeout = ( isset( $version_info->timeout ) && ! empty( $version_info->timeout ) ) ? $version_info->timeout : 0; |
| 419 | 371 | if ( ! empty( $timeout ) && time() > $timeout ) { |
| 420 | 372 | $version_info = false; // Cache is expired |
| 421 | - $api = new FrmFormApi( $this->license ); | |
| 373 | + $api = new FrmFormApi( $this->license ); | |
| 422 | 374 | $api->reset_cached(); |
| 423 | 375 | } |
| 424 | 376 | } |
| 425 | 377 | |
| @@ -433,9 +385,9 @@ | ||
| 433 | 385 | if ( $this->get_beta && isset( $version_info->beta ) && ! empty( $version_info->beta ) ) { |
| 434 | 386 | $version_info->new_version = $version_info->beta['version']; |
| 435 | 387 | $version_info->package = $version_info->beta['package']; |
| 436 | 388 | if ( isset( $version_info->plugin ) && ! empty( $version_info->plugin ) ) { |
| 437 | - $version_info->plugin = $version_info->beta['plugin']; | |
| 389 | + $version_info->plugin = $version_info->beta['plugin']; | |
| 438 | 390 | } |
| 439 | 391 | } |
| 440 | 392 | } |
| 441 | 393 | |
| @@ -453,72 +405,43 @@ | ||
| 453 | 405 | } |
| 454 | 406 | |
| 455 | 407 | private function has_been_cleared() { |
| 456 | 408 | $last_cleared = get_option( 'frm_last_cleared' ); |
| 457 | - | |
| 458 | - return ( $last_cleared && $last_cleared > gmdate( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) ); | |
| 409 | + return ( $last_cleared && $last_cleared > date( 'Y-m-d H:i:s', strtotime( '-5 minutes' ) ) ); | |
| 459 | 410 | } |
| 460 | 411 | |
| 461 | 412 | private function cleared_plugins() { |
| 462 | - update_option( 'frm_last_cleared', gmdate( 'Y-m-d H:i:s' ) ); | |
| 413 | + update_option( 'frm_last_cleared', date( 'Y-m-d H:i:s' ) ); | |
| 463 | 414 | } |
| 464 | 415 | |
| 465 | 416 | private function is_license_revoked() { |
| 466 | - if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 417 | + if ( empty( $this->license ) || empty( $this->plugin_slug ) || isset( $_POST['license'] ) ) { // WPCS: CSRF ok. | |
| 467 | 418 | return; |
| 468 | 419 | } |
| 469 | 420 | |
| 470 | - // Only check weekly. | |
| 471 | - if ( $this->checked_recently( '7 days' ) ) { | |
| 472 | - return; | |
| 473 | - } | |
| 474 | - | |
| 475 | - $this->update_last_checked(); | |
| 476 | - | |
| 477 | - $response = $this->get_license_status(); | |
| 478 | - if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] || 'missing' === $response['status'] ) { | |
| 479 | - $this->clear_license(); | |
| 480 | - } | |
| 481 | - } | |
| 482 | - | |
| 483 | - /** | |
| 484 | - * Has this been checked too recently? | |
| 485 | - * | |
| 486 | - * @param string $time ie. '1 day' | |
| 487 | - * @return bool | |
| 488 | - */ | |
| 489 | - private function checked_recently( $time ) { | |
| 490 | - $last_checked = $this->last_checked(); | |
| 491 | - $time_ago = gmdate( 'Y-m-d H:i:s', strtotime( '-' . $time ) ); | |
| 492 | - return $last_checked && $last_checked > $time_ago; | |
| 493 | - } | |
| 494 | - | |
| 495 | - /** | |
| 496 | - * @return bool|string | |
| 497 | - */ | |
| 498 | - private function last_checked() { | |
| 499 | 421 | if ( is_multisite() ) { |
| 500 | 422 | $last_checked = get_site_option( $this->transient_key() ); |
| 501 | 423 | } else { |
| 502 | 424 | $last_checked = get_option( $this->transient_key() ); |
| 503 | 425 | } |
| 504 | - return $last_checked; | |
| 505 | - } | |
| 506 | 426 | |
| 507 | - /** | |
| 508 | - * @return void | |
| 509 | - */ | |
| 510 | - private function update_last_checked() { | |
| 511 | - if ( is_multisite() ) { | |
| 512 | - update_site_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) ); | |
| 513 | - } else { | |
| 514 | - update_option( $this->transient_key(), gmdate( 'Y-m-d H:i:s' ) ); | |
| 427 | + $seven_days_ago = date( 'Y-m-d H:i:s', strtotime( '-7 days' ) ); | |
| 428 | + | |
| 429 | + if ( ! $last_checked || $last_checked < $seven_days_ago ) { | |
| 430 | + // check weekly | |
| 431 | + if ( is_multisite() ) { | |
| 432 | + update_site_option( $this->transient_key(), date( 'Y-m-d H:i:s' ) ); | |
| 433 | + } else { | |
| 434 | + update_option( $this->transient_key(), date( 'Y-m-d H:i:s' ) ); | |
| 435 | + } | |
| 436 | + | |
| 437 | + $response = $this->get_license_status(); | |
| 438 | + if ( 'revoked' === $response['status'] || 'blocked' === $response['status'] || 'disabled' === $response['status'] ) { | |
| 439 | + $this->clear_license(); | |
| 440 | + } | |
| 515 | 441 | } |
| 516 | 442 | } |
| 517 | 443 | |
| 518 | - /** | |
| 519 | - * Use a new cache after the license is changed, or Formidable is updated. | |
| 520 | - */ | |
| 521 | 444 | private function transient_key() { |
| 522 | 445 | return 'frm_' . md5( sanitize_key( $this->license . '_' . $this->plugin_slug ) ); |
| 523 | 446 | } |
| 524 | 447 | |
| @@ -525,39 +448,33 @@ | ||
| 525 | 448 | public static function activate() { |
| 526 | 449 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 527 | 450 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 528 | 451 | |
| 529 | - $license = stripslashes( FrmAppHelper::get_param( 'license', '', 'post', 'sanitize_text_field' ) ); | |
| 530 | - if ( empty( $license ) ) { | |
| 531 | - wp_send_json( | |
| 532 | - array( | |
| 533 | - 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ), | |
| 534 | - 'success' => false, | |
| 452 | + if ( ! isset( $_POST['license'] ) || empty( $_POST['license'] ) ) { | |
| 453 | + wp_die( | |
| 454 | + json_encode( | |
| 455 | + array( | |
| 456 | + 'message' => __( 'Oops! You forgot to enter your license number.', 'formidable' ), | |
| 457 | + 'success' => false, | |
| 458 | + ) | |
| 535 | 459 | ) |
| 536 | 460 | ); |
| 537 | 461 | } |
| 538 | 462 | |
| 539 | - $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); | |
| 540 | - $response = self::activate_license_for_plugin( $license, $plugin_slug ); | |
| 463 | + $license = stripslashes( sanitize_text_field( $_POST['license'] ) ); | |
| 464 | + $plugin_slug = sanitize_text_field( $_POST['plugin'] ); | |
| 465 | + $this_plugin = self::get_addon( $plugin_slug ); | |
| 466 | + $response = $this_plugin->activate_license( $license ); | |
| 541 | 467 | |
| 542 | - wp_send_json( $response ); | |
| 468 | + echo json_encode( $response ); | |
| 469 | + wp_die(); | |
| 543 | 470 | } |
| 544 | 471 | |
| 545 | - /** | |
| 546 | - * @since 4.08 | |
| 547 | - */ | |
| 548 | - public static function activate_license_for_plugin( $license, $plugin_slug ) { | |
| 549 | - $this_plugin = self::get_addon( $plugin_slug ); | |
| 550 | - return $this_plugin->activate_license( $license ); | |
| 551 | - } | |
| 552 | - | |
| 553 | 472 | private function activate_license( $license ) { |
| 554 | 473 | $this->set_license( $license ); |
| 555 | 474 | $this->license = $license; |
| 556 | 475 | |
| 557 | - $this->die_if_not_allowed(); | |
| 558 | - | |
| 559 | - $response = $this->get_license_status(); | |
| 476 | + $response = $this->get_license_status(); | |
| 560 | 477 | $response['message'] = ''; |
| 561 | 478 | $response['success'] = false; |
| 562 | 479 | |
| 563 | 480 | if ( $response['error'] ) { |
| @@ -571,38 +488,17 @@ | ||
| 571 | 488 | } |
| 572 | 489 | |
| 573 | 490 | $is_valid = false; |
| 574 | 491 | if ( 'valid' === $response['status'] ) { |
| 575 | - $is_valid = 'valid'; | |
| 492 | + $is_valid = 'valid'; | |
| 576 | 493 | $response['success'] = true; |
| 577 | 494 | } |
| 578 | 495 | $this->set_active( $is_valid ); |
| 579 | 496 | } |
| 580 | 497 | |
| 581 | - $this->update_last_checked(); | |
| 582 | - | |
| 583 | 498 | return $response; |
| 584 | 499 | } |
| 585 | 500 | |
| 586 | - /** | |
| 587 | - * Prevent this check from happening more than once per minute with the same license. | |
| 588 | - * | |
| 589 | - * @return void | |
| 590 | - */ | |
| 591 | - private function die_if_not_allowed() { | |
| 592 | - if ( ! $this->checked_recently( '2 minutes' ) ) { | |
| 593 | - return; | |
| 594 | - } | |
| 595 | - | |
| 596 | - // Don't check more than once per minute. | |
| 597 | - wp_send_json( | |
| 598 | - array( | |
| 599 | - 'message' => __( 'Please wait two minutes before trying again.', 'formidable' ), | |
| 600 | - 'success' => false, | |
| 601 | - ) | |
| 602 | - ); | |
| 603 | - } | |
| 604 | - | |
| 605 | 501 | private function get_license_status() { |
| 606 | 502 | $response = array( |
| 607 | 503 | 'status' => 'missing', |
| 608 | 504 | 'error' => true, |
| @@ -608,19 +504,18 @@ | ||
| 608 | 504 | 'error' => true, |
| 609 | 505 | ); |
| 610 | 506 | if ( empty( $this->license ) ) { |
| 611 | 507 | $response['error'] = false; |
| 612 | - | |
| 613 | 508 | return $response; |
| 614 | 509 | } |
| 615 | 510 | |
| 616 | 511 | try { |
| 617 | 512 | $response['error'] = false; |
| 618 | - $license_data = $this->send_mothership_request( 'activate_license' ); | |
| 513 | + $license_data = $this->send_mothership_request( 'activate_license' ); | |
| 619 | 514 | |
| 620 | 515 | // $license_data->license will be either "valid" or "invalid" |
| 621 | 516 | if ( is_array( $license_data ) ) { |
| 622 | - if ( isset( $license_data['license'] ) && in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) { | |
| 517 | + if ( in_array( $license_data['license'], array( 'valid', 'invalid' ), true ) ) { | |
| 623 | 518 | $response['status'] = $license_data['license']; |
| 624 | 519 | } |
| 625 | 520 | } else { |
| 626 | 521 | $response['status'] = $license_data; |
| @@ -633,41 +528,26 @@ | ||
| 633 | 528 | } |
| 634 | 529 | |
| 635 | 530 | private function get_messages() { |
| 636 | 531 | return array( |
| 637 | - 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ), | |
| 638 | - 'invalid' => __( 'That license key is invalid', 'formidable' ), | |
| 639 | - 'expired' => __( 'That license is expired', 'formidable' ), | |
| 640 | - 'revoked' => __( 'That license has been refunded', 'formidable' ), | |
| 532 | + 'valid' => __( 'Your license has been activated. Enjoy!', 'formidable' ), | |
| 533 | + 'invalid' => __( 'That license key is invalid', 'formidable' ), | |
| 534 | + 'expired' => __( 'That license is expired', 'formidable' ), | |
| 535 | + 'revoked' => __( 'That license has been refunded', 'formidable' ), | |
| 641 | 536 | 'no_activations_left' => __( 'That license has been used on too many sites', 'formidable' ), |
| 642 | - 'invalid_item_id' => __( 'Oops! That is the wrong license key for this plugin.', 'formidable' ), | |
| 643 | - 'missing' => __( 'That license key is invalid', 'formidable' ), | |
| 537 | + 'invalid_item_id' => __( 'Oops! That is the wrong license key for this plugin.', 'formidable' ), | |
| 538 | + 'missing' => __( 'That license key is invalid', 'formidable' ), | |
| 644 | 539 | ); |
| 645 | 540 | } |
| 646 | 541 | |
| 647 | - /** | |
| 648 | - * @since 4.03 | |
| 649 | - */ | |
| 650 | - public static function reset_cache() { | |
| 651 | - FrmAppHelper::permission_check( 'frm_change_settings' ); | |
| 652 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 653 | - | |
| 654 | - $this_plugin = self::set_license_from_post(); | |
| 655 | - $this_plugin->delete_cache(); | |
| 656 | - | |
| 657 | - $response = array( | |
| 658 | - 'success' => true, | |
| 659 | - 'message' => __( 'Cache cleared', 'formidable' ), | |
| 660 | - ); | |
| 661 | - | |
| 662 | - wp_send_json( $response ); | |
| 663 | - } | |
| 664 | - | |
| 665 | 542 | public static function deactivate() { |
| 666 | 543 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 667 | 544 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 668 | 545 | |
| 669 | - $this_plugin = self::set_license_from_post(); | |
| 546 | + $plugin_slug = sanitize_text_field( $_POST['plugin'] ); | |
| 547 | + $this_plugin = self::get_addon( $plugin_slug ); | |
| 548 | + $license = $this_plugin->get_license(); | |
| 549 | + $this_plugin->license = $license; | |
| 670 | 550 | |
| 671 | 551 | $response = array( |
| 672 | 552 | 'success' => false, |
| 673 | 553 | 'message' => '', |
| @@ -686,25 +566,12 @@ | ||
| 686 | 566 | } |
| 687 | 567 | |
| 688 | 568 | $this_plugin->clear_license(); |
| 689 | 569 | |
| 690 | - wp_send_json( $response ); | |
| 570 | + echo json_encode( $response ); | |
| 571 | + wp_die(); | |
| 691 | 572 | } |
| 692 | 573 | |
| 693 | - /** | |
| 694 | - * @since 4.03 | |
| 695 | - */ | |
| 696 | - private static function set_license_from_post() { | |
| 697 | - $plugin_slug = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' ); | |
| 698 | - $this_plugin = self::get_addon( $plugin_slug ); | |
| 699 | - $license = $this_plugin->get_license(); | |
| 700 | - $this_plugin->license = $license; | |
| 701 | - return $this_plugin; | |
| 702 | - } | |
| 703 | - | |
| 704 | - /** | |
| 705 | - * @return string | |
| 706 | - */ | |
| 707 | 574 | public function send_mothership_request( $action ) { |
| 708 | 575 | $api_params = array( |
| 709 | 576 | 'edd_action' => $action, |
| 710 | 577 | 'license' => $this->license, |
| @@ -716,17 +583,14 @@ | ||
| 716 | 583 | $api_params['item_name'] = rawurlencode( $this->plugin_name ); |
| 717 | 584 | } |
| 718 | 585 | |
| 719 | 586 | $arg_array = array( |
| 720 | - 'body' => $api_params, | |
| 721 | - 'timeout' => 25, | |
| 587 | + 'body' => $api_params, | |
| 588 | + 'timeout' => 25, | |
| 722 | 589 | 'user-agent' => $this->plugin_slug . '/' . $this->version . '; ' . get_bloginfo( 'url' ), |
| 723 | 590 | ); |
| 724 | 591 | |
| 725 | - $resp = wp_remote_post( | |
| 726 | - $this->store_url . '?l=' . urlencode( base64_encode( $this->license ) ), | |
| 727 | - $arg_array | |
| 728 | - ); | |
| 592 | + $resp = wp_remote_post( $this->store_url, $arg_array ); | |
| 729 | 593 | $body = wp_remote_retrieve_body( $resp ); |
| 730 | 594 | |
| 731 | 595 | $message = __( 'Your License Key was invalid', 'formidable' ); |
| 732 | 596 | if ( is_wp_error( $resp ) ) { |
| @@ -744,16 +608,10 @@ | ||
| 744 | 608 | } else { |
| 745 | 609 | $message = $json_res; |
| 746 | 610 | } |
| 747 | 611 | } elseif ( isset( $resp['response'] ) && isset( $resp['response']['code'] ) ) { |
| 748 | - $resp['body'] = wp_strip_all_tags( $resp['body'] ); | |
| 749 | - | |
| 750 | - $message = sprintf( | |
| 751 | - /* translators: %1$s: Error code, %2$s: Error message */ | |
| 752 | - esc_html__( 'There was a %1$s error: %2$s', 'formidable' ), | |
| 753 | - esc_html( $resp['response']['code'] ), | |
| 754 | - $resp['response']['message'] . ' ' . $resp['body'] | |
| 755 | - ); | |
| 612 | + /* translators: %1$s: Error code, %2$s: Error message */ | |
| 613 | + $message = sprintf( __( 'There was a %1$s error: %2$s', 'formidable' ), $resp['response']['code'], $resp['response']['message'] . ' ' . $resp['body'] ); | |
| 756 | 614 | } |
| 757 | 615 | } |
| 758 | 616 | |
| 759 | 617 | return $message; |
| @@ -759,13 +617,7 @@ | ||
| 759 | 617 | return $message; |
| 760 | 618 | } |
| 761 | 619 | |
| 762 | 620 | public function manually_queue_update() { |
| 763 | - $updates = new stdClass(); | |
| 764 | - $updates->last_checked = 0; | |
| 765 | - $updates->response = array(); | |
| 766 | - $updates->translations = array(); | |
| 767 | - $updates->no_update = array(); | |
| 768 | - $updates->checked = array(); | |
| 769 | - set_site_transient( 'update_plugins', $updates ); | |
| 621 | + set_site_transient( 'update_plugins', null ); | |
| 770 | 622 | } |
| 771 | 623 | } |