Untitled diff

Created Diff never expires
0 removals
366 lines
14 additions
380 lines
<?php
<?php
class WP_Stream_API {
class WP_Stream_API {
/**
/**
* API Key key/identifier
* API Key key/identifier
*/
*/
const API_KEY_OPTION_KEY = 'wp_stream_site_api_key';
const API_KEY_OPTION_KEY = 'wp_stream_site_api_key';
/**
/**
* Site UUID key/identifier
* Site UUID key/identifier
*/
*/
const SITE_UUID_OPTION_KEY = 'wp_stream_site_uuid';
const SITE_UUID_OPTION_KEY = 'wp_stream_site_uuid';
/**
/**
* Site Retricted key/identifier
* Site Retricted key/identifier
*/
*/
const RESTRICTED_OPTION_KEY = 'wp_stream_site_restricted';
const RESTRICTED_OPTION_KEY = 'wp_stream_site_restricted';
/**
/**
* The site's API Key
* The site's API Key
*
*
* @var string
* @var string
*/
*/
public $api_key = false;
public $api_key = false;
/**
/**
* The site's unique identifier
* The site's unique identifier
*
*
* @var string
* @var string
*/
*/
public $site_uuid = false;
public $site_uuid = false;
/**
/**
* The site's restriction status
* The site's restriction status
*
*
* @var bool
* @var bool
*/
*/
public static $restricted = true;
public static $restricted = true;
/**
/**
* The API URL
* The API URL
*
*
* @var string
* @var string
*/
*/
public $api_url = 'https://api.wp-stream.com';
public $api_url = 'https://api.wp-stream.com';
/**
/**
* The API Version
* The API Version
*
*
* @var string
* @var string
*/
*/
public $api_version = '0.0.2';
public $api_version = '0.0.2';
/**
/**
* Error messages
* Error messages
*
*
* @var array
* @var array
*/
*/
public $errors = array();
public $errors = array();
/**
/**
* Total API calls made per page load
* Total API calls made per page load
* Used for debugging and optimization
* Used for debugging and optimization
*
*
* @var array
* @var array
*/
*/
public $count = 0;
public $count = 0;
/**
/**
* Public constructor
* Public constructor
*
*
* @return void
* @return void
*/
*/
public function __construct() {
public function __construct() {
$this->api_key = get_option( self::API_KEY_OPTION_KEY, 0 );
$this->api_key = get_option( self::API_KEY_OPTION_KEY, 0 );
$this->site_uuid = get_option( self::SITE_UUID_OPTION_KEY, 0 );
$this->site_uuid = get_option( self::SITE_UUID_OPTION_KEY, 0 );
self::$restricted = get_option( self::RESTRICTED_OPTION_KEY, 1 );
self::$restricted = get_option( self::RESTRICTED_OPTION_KEY, 1 );
}
}
/**
/**
* Check if the current site is restricted
* Check if the current site is restricted
*
*
* @param bool Force the API to send a request to check the site's plan type
* @param bool Force the API to send a request to check the site's plan type
*
*
* @return bool
* @return bool
*/
*/
public static function is_restricted( $force_check = false ) {
public static function is_restricted( $force_check = false ) {
if ( $force_check ) {
if ( $force_check ) {
$site = WP_Stream::$api->get_site();
$site = WP_Stream::$api->get_site();
self::$restricted = ( ! isset( $site->plan->type ) || 'free' === $site->plan->type );
self::$restricted = ( ! isset( $site->plan->type ) || 'free' === $site->plan->type );
}
}
return self::$restricted;
return self::$restricted;
}
}
/**
/**
* Used to prioritise the streams transport which support non-blocking
* Used to prioritise the streams transport which support non-blocking
*
*