BSF_License_Manager::get_remote_license_status( string $purchase_key, int $product_id )
Get remote license status.
Description
Parameters
- $purchase_key
-
(string) (Required) Purchase Key.
- $product_id
-
(int) (Required) Product ID.
Source
File: admin/bsf-core/class-bsf-license-manager.php
public function get_remote_license_status( $purchase_key, $product_id ) { $transient_key = $product_id . '_license_status'; // Check if license status is cached. if ( false !== get_transient( $transient_key ) ) { return (bool) get_transient( $transient_key ); } // Set default license to license status stored in the database. $license_status = $this->bsf_get_product_info( $product_id, 'status' ); if ( 'registered' === $license_status ) { $license_status = '1'; } else { $license_status = '0'; } $path = bsf_get_api_url() . '?referer=license-status-' . $product_id; // Using Brainstorm API v2. $data = array( 'action' => 'bsf_license_status', 'purchase_key' => $purchase_key, 'site_url' => get_site_url(), ); $data = apply_filters( 'bsf_license_status_args', $data ); $response = wp_remote_post( $path, array( 'body' => $data, 'timeout' => '10', ) ); // Try to make a second request to unsecure URL. if ( is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) !== 200 ) { $path = bsf_get_api_url( true ) . '?referer=license-status-' . $product_id; $response = wp_remote_post( $path, array( 'body' => $data, 'timeout' => '8', ) ); } if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) === 200 ) { $response_body = json_decode( wp_remote_retrieve_body( $response ), true ); // Check if status received from API is true. if ( isset( $response_body['status'] ) && true === $response_body['status'] ) { $license_status = '1'; } else { $license_status = '0'; } } // Save license status in transient which will expire in 6 hours. set_transient( $transient_key, $license_status, 6 * HOUR_IN_SECONDS ); return (bool) $license_status; }
Expand full source code Collapse full source code View on Trac