| @@ -337,15 +337,16 @@ | ||
| 337 | 337 | 'software_slug' => $api_slug, |
| 338 | 338 | ); |
| 339 | 339 | |
| 340 | 340 | $activate_results = MainWP_Api_Manager_Key::instance()->activate( $args ); |
| 341 | - if ( ! empty( $activate_results ) ) { | |
| 342 | - $activate_results = json_decode( $activate_results, true ); | |
| 343 | - } else { | |
| 344 | - $activate_results = array(); | |
| 341 | + $activate_results = is_string( $activate_results ) && '' !== $activate_results ? json_decode( $activate_results, true ) : false; | |
| 342 | + if ( ! is_array( $activate_results ) ) { | |
| 343 | + // Keep the stored key and status, so submitting the same key again goes straight back to activation. | |
| 344 | + $activate_results = false; | |
| 345 | + $return['error'] = esc_html__( 'Connection failed to the License Key API server. Try again later.', 'mainwp' ); | |
| 345 | 346 | } |
| 346 | 347 | |
| 347 | - if ( true === $activate_results['activated'] ) { | |
| 348 | + if ( is_array( $activate_results ) && isset( $activate_results['activated'] ) && true === $activate_results['activated'] ) { | |
| 348 | 349 | $return['result'] = 'SUCCESS'; |
| 349 | 350 | $mess = isset( $activate_results['message'] ) ? $activate_results['message'] : ''; |
| 350 | 351 | $return['message'] = esc_html__( 'The extension has been activated. ', 'mainwp' ) . $mess; |
| 351 | 352 | $options['api_key'] = $api_key; |
| @@ -354,20 +355,8 @@ | ||
| 354 | 355 | $options['mainwp_version'] = MainWP_System::instance()->get_dashboard_version(); |
| 355 | 356 | MainWP_Utility::instance()->get_set_deactivated_licenses_alerted( $api_slug, 0, 'set' ); // so next time deactived it will alerted. |
| 356 | 357 | } |
| 357 | 358 | |
| 358 | - if ( false === $activate_results ) { | |
| 359 | - $apisslverify = get_option( 'mainwp_api_sslVerifyCertificate' ); | |
| 360 | - if ( 1 === $apisslverify ) { | |
| 361 | - MainWP_Utility::update_option( 'mainwp_api_sslVerifyCertificate', 0 ); | |
| 362 | - $return['retry_action'] = 1; | |
| 363 | - } else { | |
| 364 | - $return['error'] = esc_html__( 'Connection failed to the License Key API server. Try again later.', 'mainwp' ); | |
| 365 | - } | |
| 366 | - $options['api_key'] = ''; | |
| 367 | - $options['activated_key'] = 'Deactivated'; | |
| 368 | - } | |
| 369 | - | |
| 370 | 359 | $error = $this->check_response_for_api_errors( $activate_results ); |
| 371 | 360 | if ( ! empty( $error ) ) { |
| 372 | 361 | $return['error'] = $error; |
| 373 | 362 | } |
| @@ -377,10 +366,11 @@ | ||
| 377 | 366 | // The license slot was already consumed at mainwp.com; without the |
| 378 | 367 | // local persist the dashboard will offer to re-activate and burn a |
| 379 | 368 | // second slot. The encrypt filter only fails on broken installs |
| 380 | 369 | // (missing keyfile, un-writable uploads/mainwp/pk/), but when it |
| 381 | - // does the operator needs to know. | |
| 382 | - if ( false === $this->set_activation_info( $api_slug, $options ) ) { | |
| 370 | + // does the operator needs to know. A failed or refused activation keeps | |
| 371 | + // its own error: nothing was activated upstream. | |
| 372 | + if ( false === $this->set_activation_info( $api_slug, $options ) && isset( $return['result'] ) ) { | |
| 383 | 373 | $return['error'] = esc_html__( 'License activated upstream but local state could not be saved. Check uploads/mainwp/pk/ permissions and try the activation again.', 'mainwp' ); |
| 384 | 374 | } |
| 385 | 375 | |
| 386 | 376 | return $return; |