updated plugin Menu Icons version 0.13.15

This commit is contained in:
2024-07-19 19:46:10 +00:00
committed by Gitium
parent 3b4e169a1e
commit 311bc308f5
32 changed files with 439 additions and 599 deletions

View File

@ -37,7 +37,7 @@ final class Loader {
/**
* Holds registered products.
*
* @var array The products which use the SDK.
* @var array<Product> The products which use the SDK.
*/
private static $products = [];
/**
@ -62,6 +62,7 @@ final class Loader {
'about_us',
'announcements',
'featured_plugins',
'float_widget',
];
/**
* Holds the labels for the modules.
@ -276,6 +277,22 @@ final class Loader {
],
],
],
'float_widget' => [
'button' => 'Toggle Help Widget for %s',
'panel' => [
'greeting' => 'Thank you for using %s',
'title' => 'How can we help you?',
'close' => 'Close Toggle Help Widget',
],
'links' => [
'documentation' => 'Documentation',
'support' => 'Get Support',
'wizard' => 'Run Setup Wizard',
'upgrade' => 'Upgrade to Pro',
'feature_request' => 'Suggest a Feature',
'rate' => 'Rate Us',
],
],
];
/**
@ -353,7 +370,7 @@ final class Loader {
/**
* Get all products using the SDK.
*
* @return array Products available.
* @return array<Product> Products available.
*/
public static function get_products() {
return self::$products;

View File

@ -124,12 +124,33 @@ class About_Us extends Abstract_Module {
add_submenu_page(
$this->about_data['location'],
$this->about_data['upgrade_text'],
$this->about_data['upgrade_text'],
'<span class="tsdk-upg-menu-item">' . $this->about_data['upgrade_text'] . '</span>',
'manage_options',
$this->about_data['upgrade_link'],
'',
101
);
add_action(
'admin_footer',
function () {
?>
<style>
.tsdk-upg-menu-item {
color: #009528;
}
.tsdk-upg-menu-item:hover {
color: #008a20;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('.tsdk-upg-menu-item').parent().attr('target', '_blank');
});
</script>
<?php
}
);
}
/**
@ -237,9 +258,9 @@ class About_Us extends Abstract_Module {
'heading' => Loader::$labels['about_us']['otter-page']['heading'],
'text' => Loader::$labels['about_us']['otter-page']['text'],
'buttons' => [
'install_otter_free' => Loader::$labels['about_us']['otter-page']['install_otter_free'],
'install_now' => Loader::$labels['about_us']['otter-page']['install_now'],
'learn_more' => Loader::$labels['about_us']['otter-page']['learn_more'],
'install_otter_free' => Loader::$labels['about_us']['otter-page']['buttons']['install_otter_free'],
'install_now' => Loader::$labels['about_us']['otter-page']['buttons']['install_now'],
'learn_more' => Loader::$labels['about_us']['otter-page']['buttons']['learn_more'],
'learn_more_link' => tsdk_utmify( 'https://themeisle.com/plugins/otter-blocks/', 'otter-page', 'about-us' ),
],
'features' => [

View File

@ -293,10 +293,11 @@ class Announcements extends Abstract_Module {
<style>
.themeisle-sale {
display: flex;
align-items: center;
}
</style>
<div class="themeisle-sale notice notice-info is-dismissible" data-announcement="black_friday">
<img src="<?php echo esc_url_raw( $this->get_sdk_uri() . 'assets/images/themeisle-logo.svg' ); ?>"/>
<img width="24" src="<?php echo esc_url_raw( $this->get_sdk_uri() . 'assets/images/themeisle-logo.png' ); ?>"/>
<p>
<strong><?php echo esc_html( Loader::$labels['announcements']['sale_live'] ); ?> ></strong>
- <?php echo sprintf( esc_html( Loader::$labels['announcements']['max_savings'] ), esc_html( implode( ', ', $product_names ) ) ); ?>

View File

@ -44,9 +44,7 @@ class Featured_Plugins extends Abstract_Module {
return false;
}
$slug = $product->get_slug();
// only load for products that contain "pro" in the slug.
if ( strpos( $slug, 'pro' ) === false ) {
if ( $product->is_wordpress_available() ) {
return false;
}

View File

@ -0,0 +1,274 @@
<?php
/**
* The float widget model class for ThemeIsle SDK
*
* Here's how to hook it in your plugin:
*
* add_filter( <product_slug>_float_widget_metadata', 'add_float_widget_meta' );
*
* function add_float_widget_meta($data) {
* return [
* 'logo' => <logo url>,
* 'nice_name' => <nice name>, // optional, will default to product name
* 'primary_color' => <hex_color_value>, // optional
* 'pages' => [ 'page-slugs' ], //pages where the float widget should be displayed
* 'has_upgrade_menu' => <condition>,
* 'upgrade_link' => <url>,
* 'documentation_link' => <url>,
* 'premium_support_link' => <url>, // optional, provide from pro version
* 'feature_request_link' => <url>, // optional, provide from pro version
* 'wizard_link' => <url>, // optional, provide if a user is available
* ]
* }
*
* @package ThemeIsleSDK
* @subpackage Modules
* @copyright Copyright (c) 2024, Bogdan Preda
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 3.2.42
*/
namespace ThemeisleSDK\Modules;
use ThemeisleSDK\Common\Abstract_Module;
use ThemeisleSDK\Loader;
use ThemeisleSDK\Product;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Float widget module for ThemeIsle SDK.
*/
class Float_Widget extends Abstract_Module {
/**
* Float widget data.
*
* @var array $float_widget_data Float widget data, received from the filter.
*
* Shape of the $about_data property array:
* [
* 'logo' => <logo url>,
* 'nice_name' => <nice name>, // optional, will default to product name
* 'primary_color' => <hex_color_value>, // optional
* 'pages' => [ 'page-slugs' ], //pages where the float widget should be displayed
* 'has_upgrade_menu' => <condition>,
* 'upgrade_link' => <url>,
* 'documentation_link' => <url>,
* 'premium_support_link' => <url>, // optional, provide from pro version
* 'feature_request_link' => <url>, // optional, provide from pro version
* 'wizard_link' => <url>, // optional, provide if a user is available
* ]
*/
private $float_widget_data = 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->float_widget_data = apply_filters( $product->get_key() . '_float_widget_metadata', array() );
$can_load = ! empty( $this->float_widget_data );
$this->float_widget_data = array_merge(
[
'logo' => '',
'primary_color' => '#2271b1', // Default color.
'nice_name' => $product->get_name(),
'documentation_link' => '',
'premium_support_link' => '',
'feature_request_link' => '',
'wizard_link' => '',
],
$this->float_widget_data
);
return $can_load;
}
/**
* Registers the hooks.
*
* @param Product $product Product to load.
*/
public function load( $product ) {
$this->product = $product;
add_action( 'in_admin_footer', [ $this, 'render_float_placeholder' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_float_widget_script' ] );
}
/**
* Returns the allowed pages for the float widget.
*
* @return array
*/
private function get_allowed_pages() {
if ( ! isset( $this->float_widget_data['pages'] ) || ! is_array( $this->float_widget_data['pages'] ) ) {
return [];
}
return $this->float_widget_data['pages'];
}
/**
* Checks if the current screen is allowed for the float widget.
*
* @return bool
*/
private function is_current_screen_allowed() {
$current_screen = get_current_screen();
if ( ! isset( $current_screen->id ) ) {
return false;
}
if ( ! in_array( $current_screen->id, $this->get_allowed_pages(), true ) ) {
return false;
}
return true;
}
/**
* Renders the float widget placeholder.
*
* @return void
*/
public function render_float_placeholder() {
if ( ! $this->is_current_screen_allowed() ) {
return;
}
echo '<div id="ti-sdk-float-widget" style="--ti-float-primary-color: ' . esc_attr( $this->float_widget_data['primary_color'] ) . '"></div>';
}
/**
* Enqueue scripts & styles.
*
* @return void
*/
public function enqueue_float_widget_script() {
if ( ! $this->is_current_screen_allowed() ) {
return;
}
global $themeisle_sdk_max_path;
$handle = 'ti-sdk-float-' . $this->product->get_key();
$asset_file = require $themeisle_sdk_max_path . '/assets/js/build/float_widget/float.asset.php';
$deps = array_merge( $asset_file['dependencies'], [ 'updates' ] );
wp_register_script( $handle, $this->get_sdk_uri() . 'assets/js/build/float_widget/float.js', $deps, $asset_file['version'], true );
wp_localize_script( $handle, 'tiSDKFloatData', $this->get_float_localization_data() );
wp_enqueue_script( $handle );
wp_enqueue_style( $handle, $this->get_sdk_uri() . 'assets/js/build/float_widget/float.css', [ 'wp-components' ], $asset_file['version'] );
}
/**
* Get the float widget localization data.
*
* @return array
*/
private function get_float_localization_data() {
return [
'logoUrl' => $this->float_widget_data['logo'],
'primaryColor' => esc_attr( $this->float_widget_data['primary_color'] ),
'strings' => [
'toggleButton' => sprintf( Loader::$labels['float_widget']['button'], $this->float_widget_data['nice_name'] ),
'panelGreet' => sprintf( Loader::$labels['float_widget']['panel']['greeting'], $this->float_widget_data['nice_name'] ),
'panelTitle' => Loader::$labels['float_widget']['panel']['title'],
'closeToggle' => Loader::$labels['float_widget']['panel']['close'],
],
'links' => $this->get_links(),
];
}
/**
* Generates the links for the float widget.
*
* For Free:
* - Documentation (redirects to Themeisle doc page)
* - Get Support (redirects to WP free support forum)
* - Run Setup Wizard (this will trigger the setup wizard) if available
* - Upgrade to Pro (redirects to Themeisle upgrade page)
* - Rate Us (redirects to WP rating page)
*
* For Pro:
* - Documentation (redirects to Themeisle doc page)
* - Get Support (redirects to Themeisle support page to open a ticket)
* - Run Setup Wizard (this will trigger the setup wizard) if available
* - Feature Request (if available redirect to collect feedback requests)
* - Rate Us (redirects to WP rating page)
*
* @return array
*/
private function get_links() {
$links = [];
if ( ! empty( $this->float_widget_data['documentation_link'] ) ) {
$links[] = [
'icon' => 'dashicons-book-alt',
'title' => Loader::$labels['float_widget']['links']['documentation'],
'link' => $this->float_widget_data['documentation_link'],
];
}
$support_link = [
'icon' => 'dashicons-format-status',
'title' => Loader::$labels['float_widget']['links']['support'],
'link' => 'https://wordpress.org/support/' . $this->product->get_type() . '/' . $this->product->get_slug() . '/',
];
if ( ! $this->float_widget_data['has_upgrade_menu'] && ! empty( $this->float_widget_data['premium_support_link'] ) ) {
$support_link['link'] = $this->float_widget_data['premium_support_link'];
}
$links[] = $support_link;
if ( ! empty( $this->float_widget_data['wizard_link'] ) ) {
$links[] = [
'icon' => 'dashicons-admin-tools',
'title' => Loader::$labels['float_widget']['links']['wizard'],
'link' => $this->float_widget_data['wizard_link'],
'internal' => true,
];
}
$pro = [
'icon' => 'dashicons-superhero-alt',
'title' => Loader::$labels['float_widget']['links']['upgrade'],
'link' => $this->float_widget_data['upgrade_link'],
];
$featured_or_pro = $pro;
if ( ! $this->float_widget_data['has_upgrade_menu'] ) {
$featured_or_pro = []; // we remove the upgrade link
$featured = $pro;
$featured['title'] = Loader::$labels['float_widget']['links']['feature_request'];
$featured['link'] = $this->float_widget_data['feature_request_link'];
if ( ! empty( $featured['link'] ) ) {
$featured_or_pro = $featured;
}
}
if ( ! empty( $featured_or_pro ) ) {
$links[] = $featured_or_pro;
}
$links[] = [
'icon' => 'dashicons-star-filled',
'title' => Loader::$labels['float_widget']['links']['rate'],
'link' => 'https://wordpress.org/support/' . $this->product->get_type() . '/' . $this->product->get_slug() . '/reviews/#new-post',
];
return $links;
}
}

View File

@ -139,7 +139,7 @@ class Licenser extends Abstract_Module {
$value = $this->license_key;
$activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', Loader::$labels['licenser']['activate'] );
$deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', Loader::$labels['licenser']['deactivateactivate'] );
$deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', Loader::$labels['licenser']['deactivate'] );
$valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', Loader::$labels['licenser']['valid'] );
$invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', Loader::$labels['licenser']['invalid'] );
$license_message = apply_filters( $this->product->get_key() . '_lc_license_message', Loader::$labels['licenser']['notice'] );

View File

@ -188,7 +188,7 @@ class Logger extends Abstract_Module {
/**
* Load telemetry.
*
*
* @return void
*/
public function load_telemetry() {
@ -198,35 +198,35 @@ class Logger extends Abstract_Module {
$all_products = Loader::get_products();
$all_products[ $this->product->get_slug() ] = $this->product; // Add current product to the list of products to check for telemetry.
// Register telemetry params for eligible products.
foreach ( $all_products as $product_slug => $product ) {
// Ignore pro products.
// Ignore PRO products.
if ( false !== strstr( $product_slug, 'pro' ) ) {
continue;
}
$default = 'no';
$pro_slug = $product->get_pro_slug();
$logger_key = $product->get_key() . '_logger_flag';
if ( ! $product->is_wordpress_available() ) {
$default = 'yes';
} else {
$pro_slug = $product->get_pro_slug();
// If the product is not available in the WordPress store, or it's PRO version is installed, activate the logger if it was not initialized -- Pro users are opted in by default.
if ( ! $product->is_wordpress_available() || ( ! empty( $pro_slug ) && isset( $all_products[ $pro_slug ] ) ) ) {
$logger_flag = get_option( $logger_key );
if ( ! empty( $pro_slug ) && isset( $all_products[ $pro_slug ] ) ) {
$default = 'yes';
if ( false === $logger_flag ) {
update_option( $logger_key, 'yes' );
}
}
if ( 'yes' === get_option( $product->get_key() . '_logger_flag', $default ) ) {
if ( 'yes' === get_option( $product->get_key() . '_logger_flag', 'no' ) ) {
$main_slug = explode( '-', $product_slug );
$main_slug = $main_slug[0];
$pro_slug = $product->get_pro_slug();
$track_hash = Licenser::create_license_hash( str_replace( '-', '_', ! empty( $pro_slug ) ? $pro_slug : $product_slug ) );
// Check if product was already tracked.
$active_telemetry = false;
foreach ( $products_with_telemetry as &$product_with_telemetry ) {
foreach ( $products_with_telemetry as $product_with_telemetry ) {
if ( $product_with_telemetry['slug'] === $main_slug ) {
$active_telemetry = true;
break;
@ -236,7 +236,7 @@ class Logger extends Abstract_Module {
if ( $active_telemetry ) {
continue;
}
$products_with_telemetry[] = array(
'slug' => $main_slug,
'trackHash' => $track_hash ? $track_hash : 'free',
@ -251,7 +251,6 @@ class Logger extends Abstract_Module {
return;
}
$tracking_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'tracking' );
if ( ! empty( $tracking_handler ) ) {
do_action( 'themeisle_sdk_dependency_enqueue_script', 'tracking' );
@ -268,10 +267,6 @@ class Logger extends Abstract_Module {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( $e->getMessage() ); // phpcs:ignore
}
} catch ( \Error $e ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( $e->getMessage() ); // phpcs:ignore
}
} finally {
return;
}

View File

@ -121,8 +121,8 @@ class Rollback extends Abstract_Module {
if ( empty( $url ) ) {
return [];
}
$response = function_exists( 'wp_remote_get_wp_remote_get' )
? wp_remote_get_wp_remote_get( $url )
$response = function_exists( 'vip_safe_wp_remote_get' )
? vip_safe_wp_remote_get( $url )
: wp_remote_get( $url ); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
if ( is_wp_error( $response ) ) {
return array();