BSF_License_Manager::bsf_activate_license()
BSF Activate license.
Description
Source
File: admin/bsf-core/class-bsf-license-manager.php
public function bsf_activate_license() { if ( ! isset( $_POST['bsf_activate_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; } $license_key = esc_attr( $_POST['bsf_license_manager']['license_key'] ); $product_id = esc_attr( $_POST['bsf_license_manager']['product_id'] ); $user_name = isset( $_POST['bsf_license_manager']['user_name'] ) ? esc_attr( $_POST['bsf_license_manager']['user_name'] ) : ''; $user_email = isset( $_POST['bsf_license_manager']['user_email'] ) ? esc_attr( $_POST['bsf_license_manager']['user_email'] ) : ''; $privacy_consent = ( isset( $_POST['bsf_license_manager']['privacy_consent'] ) && 'true' === $_POST['bsf_license_manager']['privacy_consent'] ) ? true : false; $terms_conditions_consent = ( isset( $_POST['bsf_license_manager']['terms_conditions_consent'] ) && 'true' === $_POST['bsf_license_manager']['terms_conditions_consent'] ) ? true : false; // Check if the key is from EDD. $is_edd = $this->is_edd( $license_key ); // Server side check if the license key is valid. $path = bsf_get_api_url() . '?referer=activate-' . $product_id; // Using Brainstorm API v2. $data = array( 'action' => 'bsf_activate_license', 'purchase_key' => $license_key, 'product_id' => $product_id, 'user_name' => $user_name, 'user_email' => $user_email, 'privacy_consent' => $privacy_consent, 'terms_conditions_consent' => $terms_conditions_consent, 'site_url' => get_site_url(), 'is_edd' => $is_edd, 'referer' => 'customer', ); $data = apply_filters( 'bsf_activate_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_activation']['success'] = $result['success']; $_POST['bsf_license_activation']['message'] = $result['message']; unset( $result['success'] ); // Update product key. $result['purchase_key'] = $license_key; $this->bsf_update_product_info( $product_id, $result ); do_action( 'bsf_activate_license_' . $product_id . '_after_success', $result, $response, $_POST ); } else { $_POST['bsf_license_activation']['success'] = $result['success']; $_POST['bsf_license_activation']['message'] = $result['message']; } } else { $_POST['bsf_license_activation']['success'] = false; $_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