| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
/** |
| 5 |
* The class responsible for handling the surecart. |
| 6 |
* |
| 7 |
* @link https://webdeclic.com |
| 8 |
* @since 3.4.0 |
| 9 |
* |
| 10 |
* @package Quickwebp |
| 11 |
* @subpackage Quickwebp/admin |
| 12 |
*/ |
| 13 |
class Quickwebp_Surecart { |
| 14 |
|
| 15 |
/** |
| 16 |
* The client instance. |
| 17 |
*/ |
| 18 |
private $client; |
| 19 |
|
| 20 |
/** |
| 21 |
* The settings instance. |
| 22 |
*/ |
| 23 |
private $settings; |
| 24 |
|
| 25 |
/** |
| 26 |
* The updater instance. |
| 27 |
*/ |
| 28 |
private $updater; |
| 29 |
|
| 30 |
/** |
| 31 |
* The transient id. |
| 32 |
*/ |
| 33 |
private $transient_id = 'quickwebp_surecart_license'; |
| 34 |
|
| 35 |
/** |
| 36 |
* Init the surecart. |
| 37 |
*/ |
| 38 |
public function init_surecart() { |
| 39 |
global $quickwebp_surecart_client; |
| 40 |
|
| 41 |
if ( ! class_exists( 'SureCartQuickWebP\Licensing\Client' ) ) { |
| 42 |
require_once QUICKWEBP_PLUGIN_PATH . 'licensing/src/Client.php'; |
| 43 |
} |
| 44 |
|
| 45 |
$this->client = new \SureCartQuickWebP\Licensing\Client( 'QuickWebP', 'pt_KNa5RLetAzsYTHKMLAf9Gtey', QUICKWEBP_PLUGIN_FILE ); |
| 46 |
$quickwebp_surecart_client = $this->client; |
| 47 |
|
| 48 |
$this->settings = $this->client->settings(); |
| 49 |
$this->updater = $this->client->updater(); |
| 50 |
|
| 51 |
$this->client->settings()->add_page( array( |
| 52 |
'type' => 'submenu', |
| 53 |
'parent_slug' => 'upload.php', |
| 54 |
'page_title' => esc_html__( 'QuickWebP License', 'quickwebp' ), |
| 55 |
'menu_title' => esc_html__( 'QuickWebP License', 'quickwebp' ), |
| 56 |
'capability' => 'manage_options', |
| 57 |
'menu_slug' => $this->client->slug . '-manage-license', |
| 58 |
'icon_url' => '', |
| 59 |
'position' => null, |
| 60 |
)); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Enqueue scripts and styles |
| 65 |
* |
| 66 |
* @since 1.15.0 |
| 67 |
*/ |
| 68 |
public function enqueue_scripts_styles() { |
| 69 |
global $quickwebp_surecart_client; |
| 70 |
|
| 71 |
$is_pro = false; |
| 72 |
if ( $quickwebp_surecart_client ) { |
| 73 |
$is_pro = $quickwebp_surecart_client->license()->is_valid(); |
| 74 |
} |
| 75 |
|
| 76 |
$surecart_license_assets = include( QUICKWEBP_PLUGIN_PATH . 'public/assets/build/surecart-license.asset.php' ); |
| 77 |
wp_enqueue_style( 'quickwebp_surecart_license', QUICKWEBP_PLUGIN_URL . 'public/assets/build/surecart-license.css', array(), $surecart_license_assets['version'], 'all' ); |
| 78 |
wp_enqueue_script( 'quickwebp_surecart_license', QUICKWEBP_PLUGIN_URL . 'public/assets/build/surecart-license.js', $surecart_license_assets['dependencies'], $surecart_license_assets['version'], true ); |
| 79 |
wp_localize_script( 'quickwebp_surecart_license', 'quickwebp_surecart_license', array( |
| 80 |
'activated' => $is_pro, |
| 81 |
'i18n' => array( |
| 82 |
'upgrade' => esc_js( '� |
| 83 |
' . esc_html( __( 'Upgrade Pro', 'quickwebp' ) ) ), |
| 84 |
), |
| 85 |
)); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* License activated |
| 90 |
* |
| 91 |
* @since 1.15.0 |
| 92 |
*/ |
| 93 |
public function license_activated() { |
| 94 |
$activation = get_transient( $this->transient_id ); |
| 95 |
|
| 96 |
if ( false === $activation ) { |
| 97 |
$activation = $this->settings->get_activation(); |
| 98 |
if ( ! empty( $activation->id ) ) { |
| 99 |
set_transient( $this->transient_id, true, HOUR_IN_SECONDS * 2 ); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
return $activation; |
| 104 |
} |
| 105 |
} |
| 106 |
|