From d84162a04033d43bea37b8d91cb6199a50c291e1 Mon Sep 17 00:00:00 2001 From: Ali-A-Ali Date: Sat, 20 Jul 2024 05:18:35 +0400 Subject: [PATCH] Compatibility for WP 6.6 and refactor the integration with Elementor. --- README.md | 16 +- alpha-price-table-for-elementor.php | 18 +- include/class-alpha-price-table-widget.php | 21 ++- include/class-alpha-price-table.php | 209 +++++++++++---------- index.php | 1 - readme.txt | 16 +- 6 files changed, 149 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index e0d3432..cde843d 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,15 @@ Author: ali7ali Contributors: ali7ali -Tags: price-table, drag-and-drop, elementor, page builder, landing page, premium, price, compare, table, alpha +Tags: price-table, price, elementor, compare, table Requires at least: 6.0 -Tested up to: 6.4 +Tested up to: 6.6 -Requires PHP: 7.3 +Requires PHP: 7.4 -Stable tag: 1.0.4 +Stable tag: 1.0.5 License: GPLv3 @@ -58,12 +58,12 @@ Use the WordPress.org forums for community support. If you spot a bug, you can o = Minimum Requirements = - WordPress 6.0 or greater -- PHP version 7.3 or greater +- PHP version 7.4 or greater - MySQL version 5.0 or greater = We recommend your host supports: = -- PHP version 7.4 or greater +- PHP version 8.1 or greater - MySQL version 5.6 or greater - WordPress Memory limit of 64 MB or greater (128 MB or higher is preferred) @@ -86,5 +86,5 @@ Manual or using sFTP install: == Upgrade Notice == -= 1.0.4 = -Compatibility for WP 6.3. += 1.0.5 = +Compatibility for WP 6.6 and refactor the integration with Elementor. diff --git a/alpha-price-table-for-elementor.php b/alpha-price-table-for-elementor.php index 3590435..45fce9b 100644 --- a/alpha-price-table-for-elementor.php +++ b/alpha-price-table-for-elementor.php @@ -6,13 +6,12 @@ * Description: Premium Price Table for WordPress. * Author: Ali Ali * Author URI: https://github.com/Ali7Ali - * Version: 1.0.4 + * Version: 1.0.5 * Text Domain: alpha-price-table-for-elementor * Domain Path: /languages * License: GPLv3 * * - * @package alpha-price-table-for-elementor */ /* @@ -37,13 +36,22 @@ exit; // Exit if accessed directly. } -define('ALPHAPRICETABLE_VERSION', '1.0.4'); +define('ALPHAPRICETABLE_VERSION', '1.0.5'); define('ALPHAPRICETABLE_ADDONS_PL_ROOT', __FILE__); define('ALPHAPRICETABLE_PL_URL', plugins_url('/', ALPHAPRICETABLE_ADDONS_PL_ROOT)); define('ALPHAPRICETABLE_PL_PATH', plugin_dir_path(ALPHAPRICETABLE_ADDONS_PL_ROOT)); define('ALPHAPRICETABLE_PL_ASSETS', trailingslashit(ALPHAPRICETABLE_PL_URL . 'assets')); define('ALPHAPRICETABLE_PL_INCLUDE', trailingslashit(ALPHAPRICETABLE_PL_PATH . 'include')); +define('ALPHAPRICETABLE_PL_LANGUAGES', trailingslashit(ALPHAPRICETABLE_PL_PATH . 'languages')); define('ALPHAPRICETABLE_PLUGIN_BASE', plugin_basename(ALPHAPRICETABLE_ADDONS_PL_ROOT)); -// Required File -include(ALPHAPRICETABLE_PL_INCLUDE . '/class-alpha-price-table.php'); +function alpha_price_table_addon() +{ + + // Load plugin file + require_once(ALPHAPRICETABLE_PL_INCLUDE . '/class-alpha-price-table.php'); + + // Run the plugin + \Elementor_Alpha_Price_Table_Addon\Alpha_Price_Table_For_Elementor::instance(); +} +add_action('plugins_loaded', 'alpha_price_table_addon'); diff --git a/include/class-alpha-price-table-widget.php b/include/class-alpha-price-table-widget.php index 253541c..736e0d1 100644 --- a/include/class-alpha-price-table-widget.php +++ b/include/class-alpha-price-table-widget.php @@ -1,26 +1,27 @@ is_compatible()) { + add_action('elementor/init', [$this, 'init']); + } } /** @@ -51,53 +81,38 @@ public function __construct() */ public function i18n() { - load_plugin_textdomain('alpha-price-table-for-elementor'); + load_plugin_textdomain('alpha-price-table-for-elementor', false, ALPHAPRICETABLE_PL_LANGUAGES); } /** - * On plugins load check for compatibility. - */ - public function on_plugins_loaded() - { - if ($this->is_compatible()) { - add_action('elementor/init', array($this, 'init')); - } - } - - /** - * Check if is compatible. + * Compatibility Checks + * + * Checks whether the site meets the addon requirement. * - * @return bool + * @since 1.0.0 + * @access public */ public function is_compatible() { - // Check if Elementor installed and activated. + // Check if Elementor installed and activated if (!did_action('elementor/loaded')) { - add_action('admin_notices', array($this, 'admin_notice_missing_main_plugin')); + add_action('admin_notices', [$this, 'admin_notice_missing_main_plugin']); return false; } - // Check for required PHP version. - if (version_compare(PHP_VERSION, self::MINIMUM_PHP_VERSION, '<')) { - add_action('admin_notices', array($this, 'admin_notice_minimum_php_version')); + // Check for required Elementor version + if (!version_compare(ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=')) { + add_action('admin_notices', [$this, 'admin_notice_minimum_elementor_version']); return false; } - $elementor = 'elementor/elementor.php'; - $pathpluginurl = WP_PLUGIN_DIR . '/' . $elementor; - $isinstalled = file_exists($pathpluginurl); - - // Check for required Elementor version. - if (!defined('ELEMENTOR_VERSION') || !version_compare(ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=')) { - add_action('admin_notices', array($this, 'admin_notice_minimum_elementor_version')); - return false; - } elseif ($isinstalled && $this->is_elementor_active()) { - return true; - } else { - add_action('admin_notices', array($this, 'admin_notice_missing_main_plugin')); + // Check for required PHP version + if (version_compare(PHP_VERSION, self::MINIMUM_PHP_VERSION, '<')) { + add_action('admin_notices', [$this, 'admin_notice_minimum_php_version']); return false; } + return true; } @@ -107,52 +122,38 @@ public function is_compatible() public function init() { $this->i18n(); - - // Add Plugin actions. - add_action('elementor/widgets/register', array($this, 'init_widgets')); - } - - /** - * Check if Elementor is active or not. - */ - public function is_elementor_active() - { - if (function_exists('elementor_load_plugin_textdomain')) { - return true; - } else { - return false; - } + add_action('elementor/frontend/after_enqueue_styles', [$this, 'frontend_styles']); + add_action('elementor/widgets/register', [$this, 'register_widgets']); } /** - * Admin notice. - * For missing elementor. + * Admin notice + * + * Warning when the site doesn't have Elementor installed or activated. + * + * @since 1.0.0 + * @access public */ public function admin_notice_missing_main_plugin() { - if (isset($_GET['activate'])) { - unset($_GET['activate']); - } + if (isset($_GET['activate'])) unset($_GET['activate']); + + $message = sprintf( + /* translators: 1: Plugin name 2: Elementor */ + esc_html__('"%1$s" requires "%2$s" to be installed and activated.', 'alpha-price-table-for-elementor'), + '' . esc_html__('Alpha Price Table for Elementor', 'alpha-price-table-for-elementor') . '', + '' . esc_html__('Elementor', 'alpha-price-table-for-elementor') . '' + ); + $elementor = 'elementor/elementor.php'; - $pathpluginurl = WP_PLUGIN_DIR . '/' . $elementor; + $pathpluginurl = \WP_PLUGIN_DIR . '/' . $elementor; $isinstalled = file_exists($pathpluginurl); - if ($isinstalled && $this->is_elementor_active()) { - return; - } elseif ($isinstalled && !$this->is_elementor_active()) { - if (!current_user_can('activate_plugins')) { - return; - } + // If installed but didn't load + if ($isinstalled && !did_action('elementor/loaded')) { $activation_url = wp_nonce_url('plugins.php?action=activate&plugin=' . $elementor . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $elementor); - /* translators: 1: Just text decoration 2: Just text decoration */ - $message = sprintf(__('%1$sAlpha Price Table for Elementor%2$s requires %1$s"Elementor"%2$s plugin to be active. Please activate Elementor to continue.', 'alpha-price-table-for-elementor'), '', ''); $button_text = esc_html__('Activate Elementor', 'alpha-price-table-for-elementor'); } else { - if (!current_user_can('activate_plugins')) { - return; - } $activation_url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=elementor'), 'install-plugin_elementor'); - /* translators: 1: Just text decoration 2: Just text decoration */ - $message = sprintf(__('%1$sAlpha Price Table for Elementor%2$s requires %1$s"Elementor"%2$s plugin to be installed and activated. Please install Elementor to continue.', 'alpha-price-table-for-elementor'), '', ''); $button_text = esc_html__('Install Elementor', 'alpha-price-table-for-elementor'); } $button = '

' . $button_text . '

'; @@ -160,14 +161,17 @@ public function admin_notice_missing_main_plugin() } /** - * Admin notice. - * For minimum Elementor version required. + * Admin notice + * + * Warning when the site doesn't have a minimum required Elementor version. + * + * @since 1.0.0 + * @access public */ public function admin_notice_minimum_elementor_version() { - if (isset($_GET['activate'])) { - unset($_GET['activate']); - } + + if (isset($_GET['activate'])) unset($_GET['activate']); $message = sprintf( /* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */ @@ -181,19 +185,23 @@ public function admin_notice_minimum_elementor_version() } /** - * Admin notice. - * For minimum PHP version required. + * Admin notice + * + * Warning when the site doesn't have a minimum required PHP version. + * + * @since 1.0.0 + * @access public */ public function admin_notice_minimum_php_version() { - if (isset($_GET['activate'])) { - unset($_GET['activate']); - } + + if (isset($_GET['activate'])) unset($_GET['activate']); $message = sprintf( - /* translators: 1: Plugin name 2: Required PHP version */ - esc_html__('"%1$s" requires PHP version %2$s or greater.', 'alpha-price-table-for-elementor'), - '' . esc_html__('Alpha Price Table', 'alpha-price-table-for-elementor') . '', + /* translators: 1: Plugin name 2: PHP 3: Required PHP version */ + esc_html__('"%1$s" requires "%2$s" version %3$s or greater.', 'alpha-price-table-for-elementor'), + '' . esc_html__('Alpha Price Table for Elementor', 'alpha-price-table-for-elementor') . '', + '' . esc_html__('PHP', 'alpha-price-table-for-elementor') . '', self::MINIMUM_PHP_VERSION ); @@ -204,24 +212,25 @@ public function admin_notice_minimum_php_version() /** * Loading plugin css. */ - public function plugin_css() + public function frontend_styles() { wp_enqueue_style('alpha-pricetable-widget', ALPHAPRICETABLE_PL_ASSETS . 'css/alpha-pricetable-widget.css', '', ALPHAPRICETABLE_VERSION); } /** - * Register the plugin widget. + * Register Widgets + * + * Load widgets files and register new Elementor widgets. * - * @param object $widgets_manager Elementor widgets object. + * Fired by `elementor/widgets/register` action hook. * - * @throws Exception File. + * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager. */ - public function init_widgets($widgets_manager) + public function register_widgets($widgets_manager) { // Include Widget files - include(ALPHAPRICETABLE_PL_INCLUDE . '/class-alpha-price-table-widget.php'); + require_once ALPHAPRICETABLE_PL_INCLUDE . '/class-alpha-price-table-widget.php'; // Register widget - $widgets_manager->register(new \Elementor\Alpha_Price_Table_Widget()); + $widgets_manager->register(new \Elementor_Alpha_Price_Table_Addon\Alpha_Price_Table_Widget()); } } -Alpha_Price_Table_For_Elementor::instance(); diff --git a/index.php b/index.php index 478e568..44d6e4b 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,6 @@ /** * Direct access security. * - * @package alpha-price-table-for-elementor * */ wp_die(); diff --git a/readme.txt b/readme.txt index d4f21e5..501cc0b 100644 --- a/readme.txt +++ b/readme.txt @@ -1,11 +1,11 @@ === Alpha Price Table For Elementor === Author: ali7ali Contributors: ali7ali -Tags: price-table, drag-and-drop, elementor, page builder, landing page, premium, price, compare, table, alpha +Tags: price-table, price, elementor, compare, table Requires at least: 6.0 -Tested up to: 6.4 -Requires PHP: 7.3 -Stable tag: 1.0.4 +Tested up to: 6.6 +Requires PHP: 7.4 +Stable tag: 1.0.5 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -37,12 +37,12 @@ Use the WordPress.org forums for community support. If you spot a bug, you can o = Minimum Requirements = * WordPress 6.0 or greater -* PHP version 7.3 or greater +* PHP version 7.4 or greater * MySQL version 5.0 or greater = We recommend your host supports: = -* PHP version 7.4 or greater +* PHP version 8.1 or greater * MySQL version 5.6 or greater * WordPress Memory limit of 64 MB or greater (128 MB or higher is preferred) @@ -64,5 +64,5 @@ Manual or using sFTP install: == Upgrade Notice == -= 1.0.4 = -Compatibility for WP 6.3. \ No newline at end of file += 1.0.5 = +Compatibility for WP 6.6 and refactor the integration with Elementor. \ No newline at end of file