updated plugin Menu Icons version 0.13.0

This commit is contained in:
2022-09-02 15:19:58 +00:00
committed by Gitium
parent 1ecbe8cf47
commit 1cd4e9a6d0
47 changed files with 413 additions and 9632 deletions

View File

@ -55,7 +55,7 @@ final class Loader {
'review',
'recommendation',
'notification',
'promotions',
];
/**

View File

@ -30,7 +30,7 @@ class Licenser extends Abstract_Module {
*
* @var int $max_failed Maximum failed checks allowed before show the notice
*/
private static $max_failed = 5;
private static $max_failed = 2;
/**
* License key string.
*
@ -244,7 +244,7 @@ class Licenser extends Abstract_Module {
*/
public function get_distributor_name() {
if ( $this->is_from_partner( $this->product ) ) {
return 'ThemeIsle';
return 'Themeisle';
}
return $this->product->get_store_name();
@ -281,7 +281,7 @@ class Licenser extends Abstract_Module {
$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.' );
$expired_license_string = apply_filters( $this->product->get_key() . '_lc_expired_string', 'Your %s\'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() ) {
?>
@ -413,26 +413,22 @@ class Licenser extends Abstract_Module {
if ( is_wp_error( $response ) ) {
$license_data = new \stdClass();
$license_data->license = 'valid';
$license_data->license = 'invalid';
} else {
$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->failed_checks <= self::$max_failed ) {
$this->increment_failed_checks();
} else {
$this->reset_failed_checks();
}
if ( $this->failed_checks <= self::$max_failed ) {
return $license_old;
}
if ( ! isset( $license_data->key ) ) {
$license_data->key = isset( $license_old->key ) ? $license_old->key : '';
}
$this->reset_failed_checks();
return $license_data;
@ -526,6 +522,10 @@ class Licenser extends Abstract_Module {
return new \WP_Error( 'themeisle-license-invalid', 'ERROR: Invalid license provided.' );
}
// Remove the versions transient upon activation so that newer version for rollback can be acquired.
$versions_cache = $this->product->get_cache_key();
delete_transient( $versions_cache );
return true;
}
@ -633,10 +633,19 @@ class Licenser extends Abstract_Module {
*/
public function theme_update_transient( $value ) {
$update_data = $this->check_for_update();
if ( $update_data ) {
$value->response[ $this->product->get_slug() ] = $update_data;
if ( empty( $value ) ) {
return $value;
}
if ( ! isset( $value->response ) ) {
return $value;
}
if ( ! $update_data ) {
return $value;
}
$value->response[ $this->product->get_slug() ] = $update_data;
return $value;
}
@ -739,6 +748,9 @@ class Licenser extends Abstract_Module {
}
$api_response = $this->api_request();
if ( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
if ( ! isset( $api_response->plugin ) ) {
$api_response->plugin = $this->product->get_slug() . '/' . $this->product->get_file();
}
if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
$_transient_data->response[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response;
} else {

View File

@ -269,8 +269,9 @@ class Notification extends Abstract_Module {
],
];
$notification_details = wp_parse_args( $notification_details, $default );
$notification_html = '<div class="notice notice-success is-dismissible themeisle-sdk-notice" data-notification-id="' . esc_attr( $notification_details['id'] ) . '" id="' . esc_attr( $notification_details['id'] ) . '-notification"> <div class="themeisle-sdk-notification-box">';
global $pagenow;
$notification_details['ctas']['cancel']['link'] = wp_nonce_url( add_query_arg( [ 'nid' => $notification_details['id'] ], admin_url( $pagenow ) ), $notification_details['id'], 'tsdk_dismiss_nonce' );
$notification_html = '<div class="notice notice-success is-dismissible themeisle-sdk-notice" data-notification-id="' . esc_attr( $notification_details['id'] ) . '" id="' . esc_attr( $notification_details['id'] ) . '-notification"> <div class="themeisle-sdk-notification-box">';
if ( ! empty( $notification_details['heading'] ) ) {
$notification_html .= sprintf( '<h4>%s</h4>', wp_kses_post( $notification_details['heading'] ) );
@ -343,16 +344,18 @@ class Notification extends Abstract_Module {
'nonce': '<?php echo esc_attr( wp_create_nonce( (string) __CLASS__ ) ); ?>',
'action': 'themeisle_sdk_dismiss_notice',
'id': notification_id,
'confirm': confirm
}
);
'confirm': confirm,
},
).fail(function() {
location.href = encodeURI(link.attr('href'));
});
if (confirm === 'yes') {
$(this).trigger('themeisle-sdk:confirmed');
} else {
$(this).trigger('themeisle-sdk:canceled');
}
container.hide();
if (link.attr('href') === '#') {
if (confirm === 'no' || link.attr('href') === '#') {
return false;
}
});
@ -383,6 +386,31 @@ class Notification extends Abstract_Module {
do_action( $id . '_process_confirm', $confirm );
wp_send_json( [] );
}
/**
* Dismiss the notification.
*/
public static function dismiss_get() {
$is_nonce_dismiss = sanitize_text_field( isset( $_GET['tsdk_dismiss_nonce'] ) ? $_GET['tsdk_dismiss_nonce'] : '' );
if ( strlen( $is_nonce_dismiss ) < 5 ) {
return;
}
$id = sanitize_text_field( isset( $_GET['nid'] ) ? $_GET['nid'] : '' );
if ( empty( $id ) ) {
return;
}
$nonce = wp_verify_nonce( sanitize_text_field( $_GET['tsdk_dismiss_nonce'] ), $id );
if ( $nonce !== 1 ) {
return;
}
$ids = wp_list_pluck( self::$notifications, 'id' );
if ( ! in_array( $id, $ids, true ) ) {
return;
}
$confirm = 'no';
self::set_last_active_notification_timestamp();
update_option( $id, $confirm );
do_action( $id . '_process_confirm', $confirm );
}
/**
* Check if we should load the notification module.
@ -456,6 +484,7 @@ class Notification extends Abstract_Module {
self::$notifications = $notifications;
add_action( 'admin_notices', array( __CLASS__, 'show_notification' ) );
add_action( 'wp_ajax_themeisle_sdk_dismiss_notice', array( __CLASS__, 'dismiss' ) );
add_action( 'admin_head', array( __CLASS__, 'dismiss_get' ) );
add_action( 'admin_head', array( __CLASS__, 'setup_notifications' ) );
return $this;

View File

@ -0,0 +1,192 @@
<?php
/**
* The promotions model class for ThemeIsle SDK
*
* Here's how to hook it in your plugin: add_filter( 'menu_icons_load_promotions', function() { return array( 'otter' ); } );
*
* @package ThemeIsleSDK
* @subpackage Modules
* @copyright Copyright (c) 2017, Marius Cristea
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 1.0.0
*/
namespace ThemeisleSDK\Modules;
use ThemeisleSDK\Common\Abstract_Module;
use ThemeisleSDK\Product;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Promotions module for ThemeIsle SDK.
*/
class Promotions extends Abstract_Module {
/**
* Fetched feeds items.
*
* @var array Feed items.
*/
private $promotions_to_load = array();
/**
* Should we load this module.
*
* @param Product $product Product object.
*
* @return bool
*/
public function can_load( $product ) {
if ( $this->is_from_partner( $product ) ) {
return false;
}
$this->promotions_to_load = apply_filters( $product->get_key() . '_load_promotions', array() );
if ( 0 === count( $this->promotions_to_load ) ) {
return false;
}
return true;
}
/**
* Registers the hooks.
*
* @param Product $product Product to load.
*
* @return Promotions Module instance.
*/
public function load( $product ) {
if ( 0 === count( $this->promotions_to_load ) ) {
return;
}
$this->product = $product;
if ( in_array( 'otter', $this->promotions_to_load ) && false === apply_filters( 'themeisle_sdk_load_promotions_otter', false ) && ! ( defined( 'OTTER_BLOCKS_VERSION' ) || $this->is_otter_installed() ) && version_compare( get_bloginfo( 'version' ), '5.8', '>=' ) ) {
add_filter( 'themeisle_sdk_load_promotions_otter', '__return_true' );
add_action( 'init', array( $this, 'register_settings' ), 99 );
if ( false !== $this->show_otter_promotion() ) {
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ) );
}
}
return $this;
}
/**
* Register Settings
*
* @since 1.2.0
* @access public
*/
public function register_settings() {
register_setting(
'themeisle_sdk_settings',
'themeisle_sdk_promotions_otter',
array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true,
'default' => '{}',
)
);
}
/**
* Get the Otter Blocks plugin status.
*
* @return string
*/
private function is_otter_installed() {
$status = false;
if ( file_exists( ABSPATH . 'wp-content/plugins/otter-blocks/otter-blocks.php' ) ) {
return true;
}
return $status;
}
/**
* Get status of Otter promotion message.
*
* @return mixed
*/
public function show_otter_promotion() {
$promotions = array(
'blocks_css',
'blocks_animation',
'blocks_conditions',
);
$option = json_decode( get_option( 'themeisle_sdk_promotions_otter', '{}' ), true );
if ( 0 === count( $option ) ) {
return 'blocks-css';
}
if ( isset( $option['blocks-css'] ) && ! isset( $option['blocks-animation'] ) && $option['blocks-css'] < strtotime( '-7 days' ) ) {
return 'blocks-animation';
}
if ( isset( $option['blocks-animation'] ) && ! isset( $option['blocks-conditions'] ) && $option['blocks-animation'] < strtotime( '-7 days' ) ) {
return 'blocks-conditions';
}
return false;
}
/**
* Load Gutenberg editor assets.
*
* @since 1.0.0
* @access public
*/
public function enqueue_editor_assets() {
global $themeisle_sdk_max_path;
$themeisle_sdk_path = dirname( $themeisle_sdk_max_path );
$themeisle_sdk_src = plugins_url( '/', $themeisle_sdk_max_path );
$asset_file = include $themeisle_sdk_path . '/themeisle-sdk/assets/js/build/index.asset.php';
wp_enqueue_script(
'themeisle-sdk-otter-promotions',
$themeisle_sdk_src . 'themeisle-sdk/assets/js/build/index.js',
array_merge( $asset_file['dependencies'], [ 'updates' ] ),
$asset_file['version'],
true
);
$option = get_option( 'themeisle_sdk_promotions_otter', '{}' );
wp_localize_script(
'themeisle-sdk-otter-promotions',
'themeisleSDKPromotions',
array(
'product' => $this->product->get_name(),
'assets' => $themeisle_sdk_src . 'themeisle-sdk/assets/images/',
'showPromotion' => $this->show_otter_promotion(),
'promotions_otter' => $option,
'activationUrl' => esc_url(
add_query_arg(
array(
'plugin_status' => 'all',
'paged' => '1',
'action' => 'activate',
'plugin' => rawurlencode( 'otter-blocks/otter-blocks.php' ),
'_wpnonce' => wp_create_nonce( 'activate-plugin_otter-blocks/otter-blocks.php' ),
),
admin_url( 'plugins.php' )
)
),
)
);
}
}

View File

@ -98,7 +98,7 @@ class Rollback extends Abstract_Module {
*/
private function get_api_versions() {
$cache_key = $this->product->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->product->get_version() ) . 'versions';
$cache_key = $this->product->get_cache_key();
$cache_versions = get_transient( $cache_key );
if ( false === $cache_versions ) {
$versions = $this->get_remote_versions();
@ -374,11 +374,27 @@ class Rollback extends Abstract_Module {
);
}
/**
* Fires after the option has been updated.
*
* @param mixed $old_value The old option value.
* @param mixed $value The new option value.
* @param string $option Option name.
*/
public function update_active_plugins_action( $old_value, $value, $option ) {
delete_site_transient( 'update_plugins' );
wp_cache_delete( 'plugins', 'plugins' );
}
/**
* Set the rollback hook. Strangely, this does not work if placed in the ThemeIsle_SDK_Rollback class, so it is being called from there instead.
*/
public function add_hooks() {
add_action( 'admin_post_' . $this->product->get_key() . '_rollback', array( $this, 'start_rollback' ) );
add_action( 'admin_footer', array( $this, 'add_footer' ) );
// This hook will be invoked after the plugin activation.
// We use this to force an update of the cache so that Update is present immediate after a rollback.
add_action( 'update_option_active_plugins', array( $this, 'update_active_plugins_action' ), 10, 3 );
}
}

View File

@ -322,6 +322,15 @@ class Product {
return $name;
}
/**
* Return the product version cache key.
*
* @return string The product version cache key.
*/
public function get_cache_key() {
return $this->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->get_version() ) . 'versions';
}
/**
* Getter for product name.
*