BSF_License_Manager::bsf_deactivate_license()
BSF Deactivate license.
Description
Source
File: admin/bsf-core/class-bsf-license-manager.php
public function bsf_deactivate_license() { if ( ! isset( $_POST['bsf_deactivate_license'] ) ) { return; } if ( ! isset( $_POST['bsf_graupi_nonce'] ) || ( isset( $_POST['bsf_graupi_nonce'] ) && ! wp_verify_nonce( $_POST['bsf_graupi_nonce'], 'bsf_license_activation_deactivation_nonce' ) ) ) { return; } if ( ! isset( $_POST['bsf_license_manager']['license_key'] ) || empty( $_POST['bsf_license_manager']['license_key'] ) ) { return; } if ( ! isset( $_POST['bsf_license_manager']['product_id'] ) || empty( $_POST['bsf_license_manager']['product_id'] ) ) { return; } $product_id = esc_attr( $_POST['bsf_license_manager']['product_id'] ); $license_key = $this->bsf_get_product_info( $product_id, 'purchase_key' ); // Check if the key is from EDD. $is_edd = $this->is_edd( $license_key ); $path = bsf_get_api_url() . '?referer=deactivate-' . $product_id; // Using Brainstorm API v2. $data = array( 'action' => 'bsf_deactivate_license', 'purchase_key' => $license_key, 'product_id' => $product_id, 'site_url' => get_site_url(), 'is_edd' => $is_edd, 'referer' => 'customer', ); $data = apply_filters( 'bsf_deactivate_license_args', $data ); $response = wp_remote_post( $path, array( 'body' => $data, 'timeout' => '15', ) ); if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) { $result = json_decode( wp_remote_retrieve_body( $response ), true ); if ( isset( $result['success'] ) && ( true === $result['success'] || 'true' === $result['success'] ) ) { // update license saus to the product. $_POST['bsf_license_deactivation']['success'] = $result['success']; $_POST['bsf_license_deactivation']['message'] = $result['message']; unset( $result['success'] ); unset( $result['message'] ); $this->bsf_update_product_info( $product_id, $result ); do_action( 'bsf_deactivate_license_' . $product_id . '_after_success', $result, $response, $_POST ); } else { $_POST['bsf_license_deactivation']['success'] = $result['success']; $_POST['bsf_license_deactivation']['message'] = $result['message']; } } else { // If there is an error, the status will not be changed. hence it's true. $_POST['bsf_license_activation']['success'] = true; $_POST['bsf_license_activation']['message'] = 'There was an error when connecting to our license API - <pre class="bsf-pre">' . $response->get_error_message() . '</pre>'; } // Delete license key status transient. delete_transient( $product_id . '_license_status' ); }
Expand full source code Collapse full source code View on Trac