updated plugin Menu Icons
version 0.12.4
This commit is contained in:
@ -1,3 +1,75 @@
|
||||
##### [Version 3.2.14](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.13...v3.2.14) (2020-06-10)
|
||||
|
||||
> Things are getting better every day. 🚀
|
||||
|
||||
##### [Version 3.2.13](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.12...v3.2.13) (2020-06-10)
|
||||
|
||||
Adds plan logic and expiration
|
||||
|
||||
##### [Version 3.2.12](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.11...v3.2.12) (2020-06-10)
|
||||
|
||||
Adds key filter
|
||||
|
||||
##### [Version 3.2.11](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.10...v3.2.11) (2020-06-04)
|
||||
|
||||
* remove non-printable chars
|
||||
|
||||
##### [Version 3.2.10](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.9...v3.2.10) (2020-05-28)
|
||||
|
||||
* Remove extra files on export
|
||||
|
||||
##### [Version 3.2.9](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.8...v3.2.9) (2020-05-18)
|
||||
|
||||
adds new endpoints
|
||||
|
||||
##### [Version 3.2.8](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.7...v3.2.8) (2020-03-24)
|
||||
|
||||
* change license handler method access
|
||||
|
||||
##### [Version 3.2.7](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.6...v3.2.7) (2020-03-24)
|
||||
|
||||
* fix callback for license processing hook
|
||||
|
||||
##### [Version 3.2.6](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.5...v3.2.6) (2020-03-23)
|
||||
|
||||
* Fix notice on license deactivation
|
||||
|
||||
##### [Version 3.2.5](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.4...v3.2.5) (2020-03-23)
|
||||
|
||||
* always load notification manager last
|
||||
|
||||
##### [Version 3.2.4](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.3...v3.2.4) (2020-03-21)
|
||||
|
||||
* Cast version response to array for icons
|
||||
|
||||
##### [Version 3.2.3](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.2...v3.2.3) (2020-03-21)
|
||||
|
||||
* use product slug instead of the one from api
|
||||
|
||||
##### [Version 3.2.2](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.1...v3.2.2) (2020-03-13)
|
||||
|
||||
* improve notice dismiss mechanism
|
||||
|
||||
##### [Version 3.2.1](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.0...v3.2.1) (2020-03-05)
|
||||
|
||||
Fix rollback call for private products
|
||||
|
||||
#### [Version 3.2.0](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.9...v3.2.0) (2020-03-04)
|
||||
|
||||
* adds license activation/deactivation handlers for wp cli
|
||||
* adds compatibility with the newest license API
|
||||
|
||||
##### [Version 3.1.9](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.8...v3.1.9) (2020-02-24)
|
||||
|
||||
* Add integration with GitHub actions
|
||||
|
||||
## [3.1.8](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.7...v3.1.8) (2019-11-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update developers name ([6aca63e](https://github.com/Codeinwp/themeisle-sdk/commit/6aca63e))
|
||||
|
||||
## [3.1.7](https://github.com/Codeinwp/themeisle-sdk/compare/v3.1.6...v3.1.7) (2019-11-07)
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
return;
|
||||
}
|
||||
// Current SDK version and path.
|
||||
$themeisle_sdk_version = '3.1.7';
|
||||
$themeisle_sdk_version = '3.2.14';
|
||||
$themeisle_sdk_path = dirname( __FILE__ );
|
||||
|
||||
global $themeisle_sdk_max_version;
|
||||
|
@ -51,11 +51,11 @@ final class Loader {
|
||||
'uninstall_feedback',
|
||||
'licenser',
|
||||
'endpoint',
|
||||
'notification',
|
||||
'logger',
|
||||
'translate',
|
||||
'review',
|
||||
'recommendation',
|
||||
'notification',
|
||||
|
||||
];
|
||||
|
||||
@ -75,6 +75,28 @@ final class Loader {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache token used in API requests.
|
||||
*
|
||||
* @return string Cache token.
|
||||
*/
|
||||
public static function get_cache_token() {
|
||||
$cache_token = get_transient( 'themeisle_sdk_cache_token' );
|
||||
if ( false === $cache_token ) {
|
||||
$cache_token = wp_generate_password( 6, false );
|
||||
set_transient( $cache_token, WEEK_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $cache_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cache token.
|
||||
*/
|
||||
public static function clear_cache_token() {
|
||||
delete_transient( 'themeisle_sdk_cache_token' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register product into SDK.
|
||||
*
|
||||
|
@ -13,6 +13,7 @@ namespace ThemeisleSDK\Modules;
|
||||
|
||||
// Exit if accessed directly.
|
||||
use ThemeisleSDK\Common\Abstract_Module;
|
||||
use ThemeisleSDK\Loader;
|
||||
use ThemeisleSDK\Product;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
@ -55,6 +56,13 @@ class Licenser extends Abstract_Module {
|
||||
*/
|
||||
private $product_key;
|
||||
|
||||
/**
|
||||
* Holds local license object.
|
||||
*
|
||||
* @var null Local license object.
|
||||
*/
|
||||
private $license_local = null;
|
||||
|
||||
/**
|
||||
* Disable wporg updates for premium products.
|
||||
*
|
||||
@ -182,18 +190,37 @@ class Licenser extends Abstract_Module {
|
||||
/**
|
||||
* Return the license status.
|
||||
*
|
||||
* @param bool $check_expiration Should check if license is valid, but expired.
|
||||
*
|
||||
* @return string The License status.
|
||||
*/
|
||||
public function get_license_status() {
|
||||
public function get_license_status( $check_expiration = false ) {
|
||||
|
||||
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
|
||||
|
||||
if ( '' === $license_data ) {
|
||||
return get_option( $this->product->get_key() . '_license_status', 'not_active' );
|
||||
}
|
||||
$status = isset( $license_data->license ) ? $license_data->license : get_option( $this->product->get_key() . '_license_status', 'not_active' );
|
||||
if ( false === $check_expiration ) {
|
||||
return $status;
|
||||
}
|
||||
|
||||
return isset( $license_data->license ) ? $license_data->license : get_option( $this->product->get_key() . '_license_status', 'not_active' );
|
||||
return ( 'valid' === $status && isset( $license_data->is_expired ) && 'yes' === $license_data->is_expired ) ? 'active_expired' : $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* License price id.
|
||||
*
|
||||
* @return int License plan.
|
||||
*/
|
||||
public function get_plan() {
|
||||
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
|
||||
if ( ! isset( $license_data->price_id ) ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int) $license_data->price_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,12 +260,13 @@ class Licenser extends Abstract_Module {
|
||||
}
|
||||
|
||||
if ( apply_filters( $this->product->get_key() . '_hide_license_notices', false ) ) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$status = $this->get_license_status();
|
||||
$no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', 'No activations left for %s !!!. You need to upgrade your plan in order to use %s on more websites. Please ask the %s Staff for more details.' );
|
||||
$no_valid_string = apply_filters( $this->product->get_key() . '_lc_no_valid_string', 'In order to benefit from updates and support for %s, please add your license code from your <a href="%s" target="_blank">purchase history</a> and validate it <a href="%s">here</a>. ' );
|
||||
|
||||
$status = $this->get_license_status( true );
|
||||
$no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', 'No more activations left for %s. You need to upgrade your plan in order to use %s on more websites. If you need assistance, please get in touch with %s staff.' );
|
||||
$no_valid_string = apply_filters( $this->product->get_key() . '_lc_no_valid_string', 'In order to benefit from updates and support for %s, please add your license code from your <a href="%s" target="_blank">purchase history</a> and validate it <a href="%s">here</a>. ' );
|
||||
$expired_license_string = apply_filters( $this->product->get_key() . '_lc_expired_string', 'Your %s License Key has expired. In order to continue receiving support and software updates you must <a href="%s" target="_blank">renew</a> your license key.' );
|
||||
// No activations left for this license.
|
||||
if ( 'valid' != $status && $this->check_activation() ) {
|
||||
?>
|
||||
@ -258,6 +286,19 @@ class Licenser extends Abstract_Module {
|
||||
<?php
|
||||
return false;
|
||||
}
|
||||
|
||||
// Invalid license key.
|
||||
if ( 'active_expired' === $status ) {
|
||||
?>
|
||||
<div class="error">
|
||||
<p>
|
||||
<strong><?php echo sprintf( $expired_license_string, $this->product->get_name() . ' ' . $this->product->get_type(), $this->get_api_url() . '?license=' . $this->license_key ); ?> </strong>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
return false;
|
||||
}
|
||||
// Invalid license key.
|
||||
if ( 'valid' != $status ) {
|
||||
?>
|
||||
@ -285,7 +326,7 @@ class Licenser extends Abstract_Module {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isset( $license_data->error ) ? ( 'no_activations_left' == $license_data->error ) : false;
|
||||
return isset( $license_data->license ) ? ( 'no_activations_left' == $license_data->license ) : false;
|
||||
|
||||
}
|
||||
|
||||
@ -345,40 +386,26 @@ class Licenser extends Abstract_Module {
|
||||
*/
|
||||
public function check_license() {
|
||||
$status = $this->get_license_status();
|
||||
if ( 'not_active' == $status ) {
|
||||
if ( 'not_active' === $status ) {
|
||||
$license_data = new \stdClass();
|
||||
$license_data->license = 'not_active';
|
||||
|
||||
return $license_data;
|
||||
}
|
||||
$license = trim( $this->license_key );
|
||||
$api_params = array(
|
||||
'edd_action' => 'check_license',
|
||||
'license' => $license,
|
||||
'item_name' => rawurlencode( $this->product->get_name() ),
|
||||
'url' => rawurlencode( home_url() ),
|
||||
);
|
||||
// Call the custom API.
|
||||
$response = wp_remote_get(
|
||||
add_query_arg( $api_params, $this->get_api_url() ),
|
||||
array(
|
||||
'timeout' => 15,
|
||||
'sslverify' => false,
|
||||
)
|
||||
);
|
||||
$license = trim( $this->license_key );
|
||||
|
||||
$response = $this->do_license_process( $license, 'check' );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$license_data = new \stdClass();
|
||||
$license_data->license = 'valid';
|
||||
|
||||
} else {
|
||||
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
if ( ! is_object( $license_data ) ) {
|
||||
$license_data = new \stdClass();
|
||||
$license_data->license = 'valid';
|
||||
}
|
||||
$license_data = $response;
|
||||
}
|
||||
|
||||
$license_old = get_option( $this->product->get_key() . '_license_data', '' );
|
||||
if ( 'valid' == $license_old->license && ( $license_data->license != $license_old->license ) ) {
|
||||
|
||||
if ( 'valid' === $license_old->license && ( $license_data->license !== $license_old->license ) ) {
|
||||
$this->increment_failed_checks();
|
||||
} else {
|
||||
$this->reset_failed_checks();
|
||||
@ -388,22 +415,10 @@ class Licenser extends Abstract_Module {
|
||||
return $license_old;
|
||||
}
|
||||
|
||||
if ( isset( $license_old->hide_valid ) ) {
|
||||
$license_data->hide_valid = true;
|
||||
}
|
||||
|
||||
if ( ! isset( $license_data->key ) ) {
|
||||
$license_data->key = isset( $license_old->key ) ? $license_old->key : '';
|
||||
}
|
||||
|
||||
if ( isset( $license_old->hide_expiration ) ) {
|
||||
$license_data->hide_expiration = true;
|
||||
}
|
||||
|
||||
if ( isset( $license_old->hide_activation ) ) {
|
||||
$license_data->hide_activation = true;
|
||||
}
|
||||
|
||||
return $license_data;
|
||||
|
||||
}
|
||||
@ -445,43 +460,65 @@ class Licenser extends Abstract_Module {
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the license remotely.
|
||||
* Do license activation/deactivation.
|
||||
*
|
||||
* @param string $license License key.
|
||||
* @param string $action What do to.
|
||||
*
|
||||
* @return bool|\WP_Error
|
||||
*/
|
||||
function activate_license() {
|
||||
// listen for our activate button to be clicked.
|
||||
if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
|
||||
return;
|
||||
public function do_license_process( $license, $action = 'toggle' ) {
|
||||
if ( strlen( $license ) < 10 ) {
|
||||
return new \WP_Error( 'themeisle-license-invalid-format', 'Invalid license.' );
|
||||
}
|
||||
$status = $this->get_license_status();
|
||||
// retrieve the license from the database.
|
||||
$license = $_POST[ $this->product->get_key() . '_license' ];
|
||||
$api_params = array(
|
||||
'license' => $license,
|
||||
'item_name' => rawurlencode( $this->product->get_name() ),
|
||||
'url' => rawurlencode( home_url() ),
|
||||
);
|
||||
if ( 'valid' != $status ) {
|
||||
// data to send in our API request.
|
||||
$api_params['edd_action'] = 'activate_license';
|
||||
} else {
|
||||
$api_params['edd_action'] = 'deactivate_license';
|
||||
|
||||
if ( 'valid' === $status && 'activate' === $action ) {
|
||||
return new \WP_Error( 'themeisle-license-already-active', 'License is already active.' );
|
||||
}
|
||||
if ( 'valid' !== $status && 'deactivate' === $action ) {
|
||||
return new \WP_Error( 'themeisle-license-already-deactivate', 'License not active.' );
|
||||
}
|
||||
|
||||
if ( 'toggle' === $action ) {
|
||||
$action = ( 'valid' !== $status ? ( 'activate' ) : ( 'deactivate' ) );
|
||||
}
|
||||
|
||||
// Call the custom API.
|
||||
$response = wp_remote_get( add_query_arg( $api_params, $this->get_api_url() ) );
|
||||
if ( 'check' === $action ) {
|
||||
$response = wp_remote_get( sprintf( '%slicense/check/%s/%s/%s/%s', Product::API_URL, rawurlencode( $this->product->get_name() ), $license, rawurlencode( home_url() ), Loader::get_cache_token() ) );
|
||||
} else {
|
||||
$response = wp_remote_post(
|
||||
sprintf( '%slicense/%s/%s/%s', Product::API_URL, $action, rawurlencode( $this->product->get_name() ), $license ),
|
||||
array(
|
||||
'body' => wp_json_encode(
|
||||
array(
|
||||
'url' => rawurlencode( home_url() ),
|
||||
)
|
||||
),
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// make sure the response came back okay.
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$this->set_error( sprintf( 'ERROR: Failed to connect to the license service. Please try again later. Reason: %s', $response->get_error_message() ) );
|
||||
|
||||
return;
|
||||
return new \WP_Error( 'themeisle-license-500', sprintf( 'ERROR: Failed to connect to the license service. Please try again later. Reason: %s', $response->get_error_message() ) );
|
||||
}
|
||||
|
||||
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
||||
|
||||
if ( ! is_object( $license_data ) ) {
|
||||
$this->set_error( 'ERROR: Failed to validate license. Please try again in one minute.' );
|
||||
|
||||
return;
|
||||
return new \WP_Error( 'themeisle-license-404', 'ERROR: Failed to validate license. Please try again in one minute.' );
|
||||
}
|
||||
if ( 'check' === $action ) {
|
||||
return $license_data;
|
||||
}
|
||||
|
||||
Loader::clear_cache_token();
|
||||
|
||||
if ( ! isset( $license_data->license ) ) {
|
||||
$license_data->license = 'invalid';
|
||||
}
|
||||
@ -489,26 +526,50 @@ class Licenser extends Abstract_Module {
|
||||
if ( ! isset( $license_data->key ) ) {
|
||||
$license_data->key = $license;
|
||||
}
|
||||
if ( 'valid' == $license_data->license ) {
|
||||
if ( 'valid' === $license_data->license ) {
|
||||
$this->reset_failed_checks();
|
||||
}
|
||||
|
||||
$this->set_error( '' );
|
||||
|
||||
if ( 'deactivate_license' === $api_params['edd_action'] ) {
|
||||
if ( 'deactivate' === $action ) {
|
||||
|
||||
delete_option( $this->product->get_key() . '_license_data' );
|
||||
delete_option( $this->product->get_key() . '_license_plan' );
|
||||
delete_transient( $this->product->get_key() . '_license_data' );
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
if ( isset( $license_data->plan ) ) {
|
||||
update_option( $this->product->get_key() . '_license_plan', $license_data->plan );
|
||||
}
|
||||
update_option( $this->product->get_key() . '_license_data', $license_data );
|
||||
set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );
|
||||
if ( 'activate' === $action && 'valid' !== $license_data->license ) {
|
||||
return new \WP_Error( 'themeisle-license-invalid', 'ERROR: Invalid license provided.' );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the license remotely.
|
||||
*/
|
||||
function process_license() {
|
||||
// listen for our activate button to be clicked.
|
||||
if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
|
||||
return;
|
||||
}
|
||||
$license = $_POST[ $this->product->get_key() . '_license' ];
|
||||
$response = $this->do_license_process( $license, 'toggle' );
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$this->set_error( $response->get_error_message() );
|
||||
|
||||
return;
|
||||
}
|
||||
if ( true === $response ) {
|
||||
$this->set_error( '' );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -607,17 +668,16 @@ class Licenser extends Abstract_Module {
|
||||
* @return bool|mixed Update api response.
|
||||
*/
|
||||
private function get_version_data() {
|
||||
$api_params = array(
|
||||
'edd_action' => 'get_version',
|
||||
'version' => $this->product->get_version(),
|
||||
'license' => empty( $this->license_key ) ? 'free' : $this->license_key,
|
||||
'name' => rawurlencode( $this->product->get_name() ),
|
||||
'slug' => $this->product->get_slug(),
|
||||
'author' => rawurlencode( $this->get_distributor_name() ),
|
||||
'url' => rawurlencode( home_url() ),
|
||||
);
|
||||
$response = wp_remote_get(
|
||||
add_query_arg( $api_params, $this->get_api_url() ),
|
||||
|
||||
$response = wp_remote_get(
|
||||
sprintf(
|
||||
'%slicense/version/%s/%s/%s/%s',
|
||||
Product::API_URL,
|
||||
rawurlencode( $this->product->get_name() ),
|
||||
( empty( $this->license_key ) ? 'free' : $this->license_key ),
|
||||
$this->product->get_version(),
|
||||
rawurlencode( home_url() )
|
||||
),
|
||||
array(
|
||||
'timeout' => 15,
|
||||
'sslverify' => false,
|
||||
@ -630,6 +690,15 @@ class Licenser extends Abstract_Module {
|
||||
if ( ! is_object( $update_data ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( isset( $update_data->slug ) ) {
|
||||
$update_data->slug = $this->product->get_slug();
|
||||
}
|
||||
if ( isset( $update_data->icons ) ) {
|
||||
$update_data->icons = (array) $update_data->icons;
|
||||
}
|
||||
if ( isset( $update_data->banners ) ) {
|
||||
$update_data->banners = (array) $update_data->banners;
|
||||
}
|
||||
|
||||
return $update_data;
|
||||
}
|
||||
@ -694,7 +763,7 @@ class Licenser extends Abstract_Module {
|
||||
* @return object $_data
|
||||
*/
|
||||
public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
|
||||
if ( ( 'plugin_information' != $_action ) || ! isset( $_args->slug ) || ( $_args->slug != $this->product->get_slug() ) ) {
|
||||
if ( ( 'plugin_information' !== $_action ) || ! isset( $_args->slug ) || ( $_args->slug !== $this->product->get_slug() ) ) {
|
||||
return $_data;
|
||||
}
|
||||
$api_response = $this->api_request();
|
||||
@ -757,6 +826,21 @@ class Licenser extends Abstract_Module {
|
||||
$this->register_license_hooks();
|
||||
}
|
||||
|
||||
$namespace = apply_filters( 'themesle_sdk_namespace_' . md5( $product->get_basefile() ), false );
|
||||
|
||||
if ( false !== $namespace ) {
|
||||
add_filter( 'themeisle_sdk_license_process_' . $namespace, [ $this, 'do_license_process' ], 10, 2 );
|
||||
add_filter( 'product_' . $namespace . '_license_status', [ $this, 'get_license_status' ], PHP_INT_MAX );
|
||||
add_filter( 'product_' . $namespace . '_license_key', [ $this->product, 'get_license' ] );
|
||||
add_filter( 'product_' . $namespace . '_license_plan', [ $this, 'get_plan' ], PHP_INT_MAX );
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
\WP_CLI::add_command( $namespace . ' activate', [ $this, 'cli_activate' ] );
|
||||
\WP_CLI::add_command( $namespace . ' deactivate', [ $this, 'cli_deactivate' ] );
|
||||
\WP_CLI::add_command( $namespace . ' is-active', [ $this, 'cli_is_active' ] );
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'admin_head', [ $this, 'auto_activate' ] );
|
||||
if ( $this->product->is_plugin() ) {
|
||||
add_filter(
|
||||
'pre_set_site_transient_update_plugins',
|
||||
@ -785,12 +869,133 @@ class Licenser extends Abstract_Module {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run license activation on plugin activate.
|
||||
*/
|
||||
public function auto_activate() {
|
||||
if ( ! current_user_can( 'switch_themes' ) ) {
|
||||
return;
|
||||
}
|
||||
$status = $this->get_license_status();
|
||||
if ( 'not_active' !== $status ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$license_file = dirname( $this->product->get_basefile() ) . '/license.json';
|
||||
|
||||
global $wp_filesystem;
|
||||
if ( ! is_file( $license_file ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once( ABSPATH . '/wp-admin/includes/file.php' );
|
||||
\WP_Filesystem();
|
||||
$content = json_decode( $wp_filesystem->get_contents( $license_file ) );
|
||||
if ( ! is_object( $content ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! isset( $content->key ) ) {
|
||||
return;
|
||||
}
|
||||
$this->license_local = $content;
|
||||
$lock_key = $this->product->get_key() . '_autoactivated';
|
||||
|
||||
if ( 'yes' === get_option( $lock_key, '' ) ) {
|
||||
return;
|
||||
}
|
||||
$response = $this->do_license_process( $content->key, 'activate' );
|
||||
|
||||
update_option( $lock_key, 'yes' );
|
||||
|
||||
if ( apply_filters( $this->product->get_key() . '_hide_license_notices', false ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( true === $response ) {
|
||||
add_action( 'admin_notices', [ $this, 'autoactivate_notice' ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show auto-activate notice.
|
||||
*/
|
||||
public function autoactivate_notice() {
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><?php echo sprintf( '<strong>%s</strong> has been successfully activated using <strong>%s</strong> license !', $this->product->get_name(), str_repeat( '*', 20 ) . substr( $this->license_local->key, - 10 ) ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate product license on this site.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* @param array $args Command args.
|
||||
*
|
||||
* [<license-key>]
|
||||
* : Product license key.
|
||||
*/
|
||||
public function cli_activate( $args ) {
|
||||
$license_key = isset( $args[0] ) ? trim( $args[0] ) : '';
|
||||
$response = $this->do_license_process( $license_key, 'activate' );
|
||||
if ( true !== $response ) {
|
||||
\WP_CLI::error( $response->get_error_message() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
\WP_CLI::success( 'Product successfully activated.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate product license on this site.
|
||||
*
|
||||
* @param array $args Command args.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* [<license-key>]
|
||||
* : Product license key.
|
||||
*/
|
||||
public function cli_deactivate( $args ) {
|
||||
$license_key = isset( $args[0] ) ? trim( $args[0] ) : '';
|
||||
$response = $this->do_license_process( $license_key, 'deactivate' );
|
||||
if ( true !== $response ) {
|
||||
\WP_CLI::error( $response->get_error_message() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
\WP_CLI::success( 'Product successfully deactivated.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if product has license activated.
|
||||
*
|
||||
* @param array $args Command args.
|
||||
*
|
||||
* @subcommand is-active
|
||||
*/
|
||||
public function cli_is_active( $args ) {
|
||||
|
||||
$status = $this->get_license_status();
|
||||
if ( 'valid' === $status ) {
|
||||
\WP_CLI::halt( 0 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
\WP_CLI::halt( 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register license fields for the products.
|
||||
*/
|
||||
public function register_license_hooks() {
|
||||
add_action( 'admin_init', array( $this, 'register_settings' ) );
|
||||
add_action( 'admin_init', array( $this, 'activate_license' ) );
|
||||
add_action( 'admin_init', array( $this, 'process_license' ) );
|
||||
add_action( 'admin_init', array( $this, 'product_valid' ), 99999999 );
|
||||
add_action( 'admin_notices', array( $this, 'show_notice' ) );
|
||||
add_filter( $this->product->get_key() . '_license_status', array( $this, 'get_license_status' ) );
|
||||
|
@ -27,7 +27,7 @@ class Logger extends Abstract_Module {
|
||||
/**
|
||||
* Endpoint where to collect logs.
|
||||
*/
|
||||
const TRACKING_ENDPOINT = 'http://log.themeisle.com/wp-json/v1/logs/';
|
||||
const TRACKING_ENDPOINT = 'https://api.themeisle.com/tracking/log';
|
||||
|
||||
|
||||
/**
|
||||
@ -90,19 +90,22 @@ class Logger extends Abstract_Module {
|
||||
* @return bool Is logger active?
|
||||
*/
|
||||
private function is_logger_active() {
|
||||
if ( ! $this->product->is_wordpress_available() ) {
|
||||
return true;
|
||||
}
|
||||
$pro_slug = $this->product->get_pro_slug();
|
||||
$default = 'no';
|
||||
|
||||
if ( ! empty( $pro_slug ) ) {
|
||||
$all_products = Loader::get_products();
|
||||
if ( isset( $all_products[ $pro_slug ] ) ) {
|
||||
return true;
|
||||
if ( ! $this->product->is_wordpress_available() ) {
|
||||
$default = 'yes';
|
||||
} else {
|
||||
$pro_slug = $this->product->get_pro_slug();
|
||||
|
||||
if ( ! empty( $pro_slug ) ) {
|
||||
$all_products = Loader::get_products();
|
||||
if ( isset( $all_products[ $pro_slug ] ) ) {
|
||||
$default = 'yes';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( get_option( $this->product->get_key() . '_logger_flag', 'no' ) === 'yes' );
|
||||
return ( get_option( $this->product->get_key() . '_logger_flag', $default ) === 'yes' );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,6 +154,7 @@ class Logger extends Abstract_Module {
|
||||
$environment['theme'] = array();
|
||||
$environment['theme']['name'] = $theme->get( 'Name' );
|
||||
$environment['theme']['author'] = $theme->get( 'Author' );
|
||||
$environment['theme']['parent'] = $theme->parent() !== false ? $theme->parent()->get( 'Name' ) : $theme->get( 'Name' );
|
||||
$environment['plugins'] = get_option( 'active_plugins' );
|
||||
global $wp_version;
|
||||
wp_remote_post(
|
||||
@ -159,14 +163,12 @@ class Logger extends Abstract_Module {
|
||||
'method' => 'POST',
|
||||
'timeout' => 3,
|
||||
'redirection' => 5,
|
||||
'headers' => array(
|
||||
'X-ThemeIsle-Event' => 'log_site',
|
||||
),
|
||||
'body' => array(
|
||||
'site' => get_site_url(),
|
||||
'slug' => $this->product->get_slug(),
|
||||
'version' => $this->product->get_version(),
|
||||
'wp_version' => $wp_version,
|
||||
'locale' => get_locale(),
|
||||
'data' => apply_filters( $this->product->get_key() . '_logger_data', array() ),
|
||||
'environment' => $environment,
|
||||
'license' => apply_filters( $this->product->get_key() . '_license_status', '' ),
|
||||
|
@ -226,7 +226,7 @@ class Notification extends Abstract_Module {
|
||||
/**
|
||||
* Get last notification details.
|
||||
*
|
||||
* @return array Last notification details.
|
||||
* @return int Last notification details.
|
||||
*/
|
||||
private static function get_last_active_notification_timestamp() {
|
||||
$notification = self::get_notifications_metadata();
|
||||
@ -374,6 +374,10 @@ class Notification extends Abstract_Module {
|
||||
if ( empty( $id ) ) {
|
||||
wp_send_json( [] );
|
||||
}
|
||||
$ids = wp_list_pluck( self::$notifications, 'id' );
|
||||
if ( ! in_array( $id, $ids, true ) ) {
|
||||
wp_send_json( [] );
|
||||
}
|
||||
self::set_last_active_notification_timestamp();
|
||||
update_option( $id, $confirm );
|
||||
do_action( $id . '_process_confirm', $confirm );
|
||||
|
@ -60,14 +60,14 @@ class Review extends Abstract_Module {
|
||||
'Stefan',
|
||||
'Uriahs',
|
||||
'Madalin',
|
||||
'Radu',
|
||||
'Cristi',
|
||||
'Silviu',
|
||||
'Andrei',
|
||||
];
|
||||
|
||||
$link = 'https://wordpress.org/support/' . $this->product->get_type() . '/' . $this->product->get_slug() . '/reviews/#wporg-footer';
|
||||
|
||||
$message = apply_filters( $this->product->get_key() . '_feedback_review_message', '<p>Hey, it’s great to see you have <b>{product}</b> active for a few days now. How is everything going? If you can spare a few moments to rate it on WordPress.org it would help us a lot (and boost my motivation). Cheers! <br/> <br/>~ {developer}, developer of {product}</p>' );
|
||||
$message = apply_filters( $this->product->get_key() . '_feedback_review_message', '<p>Hey, it\'s great to see you have <b>{product}</b> active for a few days now. How is everything going? If you can spare a few moments to rate it on WordPress.org it would help us a lot (and boost my motivation). Cheers! <br/> <br/>~ {developer}, developer of {product}</p>' );
|
||||
|
||||
$button_submit = apply_filters( $this->product->get_key() . '_feedback_review_button_do', 'Ok, I will gladly help.' );
|
||||
$button_cancel = apply_filters( $this->product->get_key() . '_feedback_review_button_cancel', 'No, thanks.' );
|
||||
|
@ -167,7 +167,7 @@ class Rollback extends Abstract_Module {
|
||||
return '';
|
||||
}
|
||||
|
||||
return sprintf( '%s?edd_action=get_versions&name=%s&url=%s&license=%s', $this->product->get_store_url(), urlencode( $this->product->get_name() ), urlencode( get_site_url() ), $license );
|
||||
return sprintf( '%slicense/versions/%s/%s/%s/%s', Product::API_URL, rawurlencode( $this->product->get_name() ), $license, urlencode( get_site_url() ), $this->product->get_version() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -295,7 +295,7 @@ class Translate extends Abstract_Module {
|
||||
),
|
||||
'gn' => array(
|
||||
'slug' => 'gn',
|
||||
'name' => 'Guaraní',
|
||||
'name' => 'Guarani',
|
||||
),
|
||||
'gsw' => array(
|
||||
'slug' => 'gsw',
|
||||
@ -471,7 +471,7 @@ class Translate extends Abstract_Module {
|
||||
),
|
||||
'nb_NO' => array(
|
||||
'slug' => 'nb',
|
||||
'name' => 'Norwegian (Bokmål)',
|
||||
'name' => 'Norwegian (Bokmal)',
|
||||
),
|
||||
'nl_NL' => array(
|
||||
'slug' => 'nl',
|
||||
|
@ -40,7 +40,7 @@ class Uninstall_Feedback extends Abstract_Module {
|
||||
*
|
||||
* @var string Endpoint url.
|
||||
*/
|
||||
const FEEDBACK_ENDPOINT = 'http://feedback.themeisle.com/wordpress/wp-json/__pirate_feedback_/v1/feedback';
|
||||
const FEEDBACK_ENDPOINT = 'https://api.themeisle.com/tracking/uninstall';
|
||||
|
||||
/**
|
||||
* Default options for plugins.
|
||||
@ -109,7 +109,7 @@ class Uninstall_Feedback extends Abstract_Module {
|
||||
*
|
||||
* @var string $heading_plugin The heading of the modal
|
||||
*/
|
||||
private $heading_plugin = 'What’s wrong?';
|
||||
private $heading_plugin = 'What\'s wrong?';
|
||||
/**
|
||||
* Default heading for theme.
|
||||
*
|
||||
@ -698,6 +698,7 @@ class Uninstall_Feedback extends Abstract_Module {
|
||||
'title' => 'Below is a detailed view of all data that ThemeIsle will receive if you fill in this survey. No domain name, email address or IP addresses are transmited after you submit the survey.',
|
||||
'items' => [
|
||||
sprintf( '%s %s version %s %s %s %s', '<strong>', ucwords( $this->product->get_type() ), '</strong>', '<code>', $this->product->get_version(), '</code>' ),
|
||||
sprintf( '%sCurrent website:%s %s %s %s', '<strong>', '</strong>', '<code>', get_site_url(), '</code>' ),
|
||||
sprintf( '%s Uninstall reason %s %s Selected reason from the above survey %s ', '<strong>', '</strong>', '<i>', '</i>' ),
|
||||
],
|
||||
],
|
||||
@ -782,6 +783,7 @@ class Uninstall_Feedback extends Abstract_Module {
|
||||
$version = $this->product->get_version();
|
||||
$attributes['slug'] = $slug;
|
||||
$attributes['version'] = $version;
|
||||
$attributes['url'] = get_site_url();
|
||||
|
||||
$response = wp_remote_post(
|
||||
self::FEEDBACK_ENDPOINT,
|
||||
|
@ -106,7 +106,10 @@ class Product {
|
||||
* @var string $version The product version.
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* Root api endpoint.
|
||||
*/
|
||||
const API_URL = 'https://api.themeisle.com/';
|
||||
/**
|
||||
* ThemeIsle_SDK_Product constructor.
|
||||
*
|
||||
|
Reference in New Issue
Block a user