| @@ -390,12 +390,16 @@ | ||
| 390 | 390 | |
| 391 | 391 | /** |
| 392 | 392 | * Get the SureForms Pro License Key. |
| 393 | 393 | * |
| 394 | + * @param bool $allow_remote_check Whether a license-cache miss may block on the | |
| 395 | + * SureCart API. Pass false from front-end request | |
| 396 | + * paths - see is_pro_license_active(). | |
| 394 | 397 | * @since 2.0.0 |
| 398 | + * @since 2.12.8 Added the $allow_remote_check parameter. | |
| 395 | 399 | * @return string The SureForms Pro License Key. |
| 396 | 400 | */ |
| 397 | - public static function get_license_key() { | |
| 401 | + public static function get_license_key( $allow_remote_check = true ) { | |
| 398 | 402 | $licensing = self::get_licensing_instance(); |
| 399 | 403 | if ( ! $licensing || |
| 400 | 404 | ! method_exists( $licensing, 'licensing_setup' ) || ! method_exists( $licensing->licensing_setup(), 'settings' ) ) { |
| 401 | 405 | return ''; |
| @@ -400,9 +404,9 @@ | ||
| 400 | 404 | ! method_exists( $licensing, 'licensing_setup' ) || ! method_exists( $licensing->licensing_setup(), 'settings' ) ) { |
| 401 | 405 | return ''; |
| 402 | 406 | } |
| 403 | 407 | // Check if the SureForms Pro license is active. |
| 404 | - $is_license_active = self::is_pro_license_active(); | |
| 408 | + $is_license_active = self::is_pro_license_active( $allow_remote_check ); | |
| 405 | 409 | // If the license is active, get the license key. |
| 406 | 410 | $license_setup = $licensing->licensing_setup(); |
| 407 | 411 | return ! empty( $is_license_active ) && is_object( $license_setup ) && method_exists( $license_setup, 'settings' ) ? $license_setup->settings()->license_key : ''; |
| 408 | 412 | } |
| @@ -409,12 +413,22 @@ | ||
| 409 | 413 | |
| 410 | 414 | /** |
| 411 | 415 | * Check if the SureForms Pro license is active. |
| 412 | 416 | * |
| 417 | + * On a cache miss the Pro licensing check makes blocking wp_remote_request calls | |
| 418 | + * with a 30 second timeout each. That is fine on an admin screen, but this helper | |
| 419 | + * is also reached from wp_ajax_nopriv_ checkout handlers, where an unauthenticated | |
| 420 | + * visitor would wait on SureCart before their payment intent is created - and a | |
| 421 | + * single slow response would pin the cached verdict for the whole site. | |
| 422 | + * | |
| 423 | + * Pass false from those paths to read the last known status instead. | |
| 424 | + * | |
| 425 | + * @param bool $allow_remote_check Whether a cache miss may block on the SureCart API. | |
| 413 | 426 | * @since 2.0.0 |
| 427 | + * @since 2.12.8 Added the $allow_remote_check parameter. | |
| 414 | 428 | * @return bool|string True if the SureForms Pro license is active, false otherwise. |
| 415 | 429 | */ |
| 416 | - public static function is_pro_license_active() { | |
| 430 | + public static function is_pro_license_active( $allow_remote_check = true ) { | |
| 417 | 431 | $licensing = self::get_licensing_instance(); |
| 418 | 432 | if ( ! $licensing || ! method_exists( $licensing, 'is_license_active' ) |
| 419 | 433 | ) { |
| 420 | 434 | return ''; |
| @@ -419,9 +433,9 @@ | ||
| 419 | 433 | ) { |
| 420 | 434 | return ''; |
| 421 | 435 | } |
| 422 | 436 | // Check if the SureForms Pro license is active. |
| 423 | - return $licensing->is_license_active(); | |
| 437 | + return $licensing->is_license_active( $allow_remote_check ); | |
| 424 | 438 | } |
| 425 | 439 | |
| 426 | 440 | /** |
| 427 | 441 | * Get the webhook URL for Stripe. |