Created
May 30, 2022 15:32
-
-
Save ronalfy/4483d821bb4e6a57bb5f102d05b4e5c9 to your computer and use it in GitHub Desktop.
Appsero Initialization Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
/** | |
* Installation instructions: https://appsero.com/docs/appsero-developers-guide/appsero-client/ | |
*/ | |
/** | |
* Register a client and provide callbacks to avoid globals. | |
*/ | |
class AppSeroClient { | |
/** | |
* Client object. | |
* | |
* @var Appsero\Client | |
*/ | |
private static $client = null; | |
/** | |
* API Key. | |
* | |
* @var string | |
*/ | |
private static $api_key = null; | |
/** | |
* Return client object. | |
* | |
* @param string $api_key App API Key. | |
*/ | |
public static function get_client( $api_key = '' ) { | |
// If API key is not passed and this is the first time calling, return false for failure. | |
if ( null === self::$api_key && empty( $api_key ) ) { | |
return false; | |
} | |
// Include dependencies. | |
if ( ! class_exists( 'Appsero\Client' ) ) { | |
require_once __DIR__ . '/appsero/src/Client.php'; | |
} | |
// Check if client is set and return that. | |
if ( null !== self::$client ) { | |
return self::$client; | |
} | |
// No client. Create one and store in static var for quick retrieval later. | |
self::$client = new Appsero\Client( $api_key, 'QuotesDLX', __FILE__ ); | |
// Now return the client object. | |
return self::$client; | |
} | |
} | |
$client = AppSeroClient::get_client( 'AppSero-api_key' ); | |
// Active insights. | |
$client->insights()->init(); | |
// Active automatic updater. | |
$client->updater(); | |
// Active license page and checker. | |
// Can comment out if you'd like to roll your own license screen. | |
$args = array( | |
'type' => 'options', | |
'menu_title' => 'QuotesDLX', | |
'page_title' => 'QuotesDLX Settings', | |
'menu_slug' => 'quotesdlx_settings', | |
); | |
$client->license()->add_settings_page( $args ); | |
/** | |
* Available methods: https://github.com/Appsero/client/blob/develop/src/License.php | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment