class-strong-testimonials-elementor-check.php
1 year ago
class-strong-testimonials-elementor-widget-activation.php
1 year ago
class-strong-testimonials-elementor-widget.php
1 year ago
class-strong-testimonials-elementor-check.php
123 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; // Exit if accessed directly |
| 4 | } |
| 5 | |
| 6 | final class Strong_Testimonials_Elementor_Check { |
| 7 | |
| 8 | /** |
| 9 | * Plugin Version |
| 10 | * |
| 11 | * @since 2.40.5 |
| 12 | * @var string The plugin version. |
| 13 | */ |
| 14 | const VERSION = '2.40.5'; |
| 15 | |
| 16 | /** |
| 17 | * Minimum Elementor Version |
| 18 | * |
| 19 | * @since 2.40.5 |
| 20 | * @var string Minimum Elementor version required to run the elementor block. |
| 21 | */ |
| 22 | const MINIMUM_ELEMENTOR_VERSION = '2.4.5'; |
| 23 | |
| 24 | /** |
| 25 | * Minimum PHP Version |
| 26 | * |
| 27 | * @since 2.40.5 |
| 28 | * @var string Minimum PHP version required to run the elementor block. |
| 29 | */ |
| 30 | const MINIMUM_PHP_VERSION = '7.0'; |
| 31 | |
| 32 | /** |
| 33 | * Constructor |
| 34 | * |
| 35 | * @since 2.40.5 |
| 36 | * @access public |
| 37 | */ |
| 38 | public function __construct() { |
| 39 | |
| 40 | // Init Plugin |
| 41 | add_action( 'plugins_loaded', array( $this, 'init' ) ); |
| 42 | } |
| 43 | |
| 44 | public function init() { |
| 45 | |
| 46 | if ( ! did_action( 'elementor/loaded' ) ) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | // Check for required Elementor version |
| 51 | if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) { |
| 52 | add_action( 'admin_notices', array( $this, 'admin_notice_minimum_elementor_version' ) ); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | // Check for required PHP version |
| 57 | if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) { |
| 58 | add_action( 'admin_notices', array( $this, 'admin_notice_minimum_php_version' ) ); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if ( has_action( 'elementor/widgets/register' ) ) { |
| 63 | add_action( 'elementor/widgets/register', array( $this, 'remove_strong_testimonials_widget' ), 15 ); |
| 64 | } else { |
| 65 | add_action( |
| 66 | 'elementor/widgets/widgets_registered', |
| 67 | array( |
| 68 | $this, |
| 69 | 'remove_strong_testimonials_widget', |
| 70 | ), |
| 71 | 15 |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | // Once we get here, We have passed all validation checks so we can safely include our elementor block activation |
| 76 | require_once WPMTST_INC . 'elementor/class-strong-testimonials-elementor-widget-activation.php'; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | /** |
| 81 | * Admin notice |
| 82 | * |
| 83 | * Warning when the site doesn't have a minimum required Elementor version. |
| 84 | * |
| 85 | * @since 2.40.5 |
| 86 | * @access public |
| 87 | */ |
| 88 | public function admin_notice_minimum_elementor_version() { |
| 89 | if ( isset( $_GET['activate'] ) ) { |
| 90 | unset( $_GET['activate'] ); |
| 91 | } |
| 92 | // translators: %1$s is the message stating that the Elementor widget requires a specific Elementor version. |
| 93 | printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', sprintf( esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'strong-testimonials' ), '<strong>' . esc_html__( 'Strong Testimonials Elementor widget', 'strong-testimonials' ) . '</strong>', '<strong>' . esc_html__( 'Elementor', 'strong-testimonials' ) . '</strong>', self::MINIMUM_ELEMENTOR_VERSION ) ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Admin notice |
| 98 | * |
| 99 | * Warning when the site doesn't have a minimum required PHP version. |
| 100 | * |
| 101 | * @since 1.0.0 |
| 102 | * @access public |
| 103 | */ |
| 104 | public function admin_notice_minimum_php_version() { |
| 105 | if ( isset( $_GET['activate'] ) ) { |
| 106 | unset( $_GET['activate'] ); |
| 107 | } |
| 108 | // translators: %1$s is the message stating that the Elementor widget requires a specific Elementor version. |
| 109 | printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', sprintf( esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'strong-testimonials' ), '<strong>' . esc_html__( 'Strong Testimonials Elementor widget', 'strong-testimonials' ) . '</strong>', '<strong>' . esc_html__( 'PHP', 'strong-testimonials' ) . '</strong>', self::MINIMUM_PHP_VERSION ) ); |
| 110 | } |
| 111 | |
| 112 | /* Remove WordPress widget because we have a dedicated Elementor Widget */ |
| 113 | public function remove_strong_testimonials_widget( $widget_manager ) { |
| 114 | if ( method_exists( $widget_manager, 'unregister' ) ) { |
| 115 | $widget_manager->unregister( 'strong-testimonials-view-widget' ); |
| 116 | } else { |
| 117 | $widget_manager->unregister_widget_type( 'strong-testimonials-view-widget' ); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | new Strong_Testimonials_Elementor_Check(); |
| 123 |