BSF_License_Manager::bsf_process_license_activation( Array $post_data )
BSF Activate license processing.
Description
Parameters
- $post_data
-
(Array) (Required) Post data.
Source
File: admin/bsf-core/class-bsf-license-manager.php
public function bsf_process_license_activation( $post_data ) { $license_key = esc_attr( $post_data['license_key'] ); $product_id = esc_attr( $post_data['product_id'] ); $user_name = isset( $post_data['user_name'] ) ? esc_attr( $post_data['user_name'] ) : ''; $user_email = isset( $post_data['user_email'] ) ? esc_attr( $post_data['user_email'] ) : ''; $privacy_consent = ( isset( $post_data['privacy_consent'] ) && 'true' === $post_data['privacy_consent'] ) ? true : false; $terms_conditions_consent = ( isset( $post_data['terms_conditions_consent'] ) && 'true' === $post_data['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', ) ); $res = array(); 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. $res['success'] = $result['success']; $res['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_data ); } else { $res['success'] = $result['success']; $res['message'] = $result['message']; } } else { $res['success'] = false; $res['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' ); return $res; }
Expand full source code Collapse full source code View on Trac