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

@ -1,3 +1,34 @@
##### [Version 3.2.27](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.26...v3.2.27) (2022-08-23)
- Add Promotion Module
Add the Promotion module for free plugins
##### [Version 3.2.26](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.25...v3.2.26) (2022-05-12)
- [Fix] Solve rollback sometimes not available
##### [Version 3.2.25](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.24...v3.2.25) (2022-03-28)
- Force update request after rollback
##### [Version 3.2.24](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.23...v3.2.24) (2022-02-09)
Fix edge case issue on dismiss
Avoid issues with open_basedir restrictions
##### [Version 3.2.23](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.22...v3.2.23) (2022-02-02)
Fix php 8.1 issues
Fix edge case when update_themes site transient was empty and a fatal error was thrown
##### [Version 3.2.22](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.21...v3.2.22) (2021-10-27)
Fix edge case when reset failed checks was not working properly
##### [Version 3.2.21](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.20...v3.2.21) (2021-06-30)
review and improve compatibility with auto-updates on custom updates endpoint
##### [Version 3.2.20](https://github.com/Codeinwp/themeisle-sdk/compare/v3.2.19...v3.2.20) (2021-03-30)
add wp-config support

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-api', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'a1e161cc7b075bdd9250');

View File

@ -0,0 +1 @@
(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,o=window.wp.i18n,n=window.wp.blockEditor,s=window.wp.components,i=window.wp.compose,r=window.wp.data,a=window.wp.hooks,l=window.wp.api;var c=e.n(l);const d={button:{display:"flex",justifyContent:"center",width:"100%"},image:{padding:"20px 0"},skip:{container:{display:"flex",flexDirection:"column",alignItems:"center"},button:{fontSize:"9px"},poweredby:{fontSize:"9px",textTransform:"uppercase"}}},m={"blocks-css":{title:(0,o.__)("Custom CSS","otter-blocks"),description:(0,o.__)("Enable Otter and add your Custom CSS for this block."),image:"css.jpg"},"blocks-animation":{title:(0,o.__)("Animations","otter-blocks"),description:(0,o.__)("Enable Otter to add Animations to this block."),image:"animation.jpg"},"blocks-conditions":{title:(0,o.__)("Visibility Conditions","otter-blocks"),description:(0,o.__)("Enable Otter to add Visibility Conditions to this block."),image:"conditions.jpg"}},w=e=>{let{onClick:n}=e;return(0,t.createElement)("div",{style:d.skip.container},(0,t.createElement)(s.Button,{style:d.skip.button,variant:"tertiary",onClick:n},(0,o.__)("Skip for now")),(0,t.createElement)("span",{style:d.skip.poweredby},(0,o.__)("Recommended by ")+window.themeisleSDKPromotions.product))},p=(0,i.createHigherOrderComponent)((e=>i=>{if(i.isSelected&&Boolean(window.themeisleSDKPromotions.showPromotion)){const[a,l]=(0,t.useState)(!1),[p,u]=(0,t.useState)("default"),[b,_]=(0,t.useState)(!1),[k,y,h]=(()=>{const{createNotice:e}=(0,r.dispatch)("core/notices"),[n,s]=(0,t.useState)({}),[i,a]=(0,t.useState)("loading"),l=()=>{c().loadPromise.then((async()=>{try{const e=new(c().models.Settings),t=await e.fetch();s(t)}catch(e){a("error")}finally{a("loaded")}}))};return(0,t.useEffect)((()=>{l()}),[]),[e=>null==n?void 0:n[e],function(t,n){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:(0,o.__)("Settings saved.","textdomain");a("saving");const i=new(c().models.Settings)({[t]:n}).save();i.success(((t,n)=>{"success"===n&&(a("loaded"),e("success",s,{isDismissible:!0,type:"snackbar"})),"error"===n&&(a("error"),e("error",(0,o.__)("An unknown error occurred.","textdomain"),{isDismissible:!0,type:"snackbar"})),l()})),i.error((t=>{a("error"),e("error",t.responseJSON.message?t.responseJSON.message:(0,o.__)("An unknown error occurred.","textdomain"),{isDismissible:!0,type:"snackbar"})}))},i]})(),g=async()=>{var e;l(!0),await("otter-blocks",new Promise((e=>{wp.updates.ajax("install-plugin",{slug:"otter-blocks",success:()=>{e({success:!0})},error:t=>{e({success:!1,code:t.errorCode})}})}))),await(e=window.themeisleSDKPromotions.activationUrl,new Promise((t=>{jQuery.get(e).done((()=>{t({success:!0})})).fail((()=>{t({success:!1})}))}))),l(!1),u("installed")},S=()=>"installed"===p?(0,t.createElement)("p",null,(0,o.__)("Awesome! Refresh the page to see Otter in action.")):(0,t.createElement)(s.Button,{variant:"secondary",onClick:g,isBusy:a,style:d.button},(0,o.__)("Install & Activate Otter")),f=()=>{const e=JSON.parse(window.themeisleSDKPromotions.promotions_otter);e[window.themeisleSDKPromotions.showPromotion]=(new Date).getTime()/1e3|0,y("themeisle_sdk_promotions_otter",JSON.stringify(e)),window.themeisleSDKPromotions.showPromotion=!1};return(0,t.useEffect)((()=>{b&&f()}),[b]),b?(0,t.createElement)(e,i):(0,t.createElement)(t.Fragment,null,(0,t.createElement)(e,i),(0,t.createElement)(n.InspectorControls,null,Object.keys(m).map((e=>{if(e===window.themeisleSDKPromotions.showPromotion){const o=m[e];return(0,t.createElement)(s.PanelBody,{title:o.title,initialOpen:!1},(0,t.createElement)("p",null,o.description),(0,t.createElement)(S,null),(0,t.createElement)("img",{style:d.image,src:window.themeisleSDKPromotions.assets+o.image}),(0,t.createElement)(w,{onClick:()=>_(!0)}))}}))))}return(0,t.createElement)(e,i)}),"withInspectorControl");(0,r.select)("core/edit-site")||(0,a.addFilter)("editor.BlockEdit","themeisle-sdk/with-inspector-controls",p)})();

View File

@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
return;
}
// Current SDK version and path.
$themeisle_sdk_version = '3.2.20';
$themeisle_sdk_version = '3.2.27';
$themeisle_sdk_path = dirname( __FILE__ );
global $themeisle_sdk_max_version;
@ -24,16 +24,17 @@ global $themeisle_sdk_max_path;
$themeisle_sdk_relative_licenser_path = '/src/Modules/Licenser.php';
global $themeisle_sdk_abs_licenser_path;
if ( ! is_file( $themeisle_sdk_path . $themeisle_sdk_relative_licenser_path ) && is_file( $themeisle_sdk_max_path . $themeisle_sdk_relative_licenser_path ) ) {
if ( ! is_file( $themeisle_sdk_path . $themeisle_sdk_relative_licenser_path ) && ! empty( $themeisle_sdk_max_path ) && is_file( $themeisle_sdk_max_path . $themeisle_sdk_relative_licenser_path ) ) {
$themeisle_sdk_abs_licenser_path = $themeisle_sdk_max_path . $themeisle_sdk_relative_licenser_path;
add_filter( 'themeisle_sdk_required_files', 'themeisle_sdk_load_licenser_if_present' );
}
if ( version_compare( $themeisle_sdk_version, $themeisle_sdk_max_path ) == 0 &&
if ( ( is_null( $themeisle_sdk_max_path ) || version_compare( $themeisle_sdk_version, $themeisle_sdk_max_path ) == 0 ) &&
apply_filters( 'themeisle_sdk_should_overwrite_path', false, $themeisle_sdk_path, $themeisle_sdk_max_path ) ) {
$themeisle_sdk_max_path = $themeisle_sdk_path;
}
if ( version_compare( $themeisle_sdk_version, $themeisle_sdk_max_version ) > 0 ) {
if ( is_null( $themeisle_sdk_max_version ) || version_compare( $themeisle_sdk_version, $themeisle_sdk_max_version ) > 0 ) {
$themeisle_sdk_max_version = $themeisle_sdk_version;
$themeisle_sdk_max_path = $themeisle_sdk_path;
}

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.
*

View File

@ -32,6 +32,7 @@ $files_to_load = [
$themeisle_library_path . '/src/Modules/Translate.php',
$themeisle_library_path . '/src/Modules/Review.php',
$themeisle_library_path . '/src/Modules/Recommendation.php',
$themeisle_library_path . '/src/Modules/Promotions.php',
];
$files_to_load = array_merge( $files_to_load, apply_filters( 'themeisle_sdk_required_files', [] ) );