Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly.
- }
- final class Elementor_Test_Extension {
- const VERSION = '1.0.0';
- const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
- const MINIMUM_PHP_VERSION = '7.0';
- private static $_instance = null;
- public static function instance() {
- if ( is_null( self::$_instance ) ) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- public function __construct() {
- add_action( 'after_setup_theme', [ $this, 'init' ] );
- }
- public function init() {
- if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
- add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] );
- return;
- }
- if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
- add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
- return;
- }
- add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] );
- }
- public function admin_notice_minimum_elementor_version() {
- if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
- $message = sprintf(
- esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'theme-textdomain' ),
- '<strong>' . esc_html__( 'Elementor Test Extension', 'theme-textdomain' ) . '</strong>',
- '<strong>' . esc_html__( 'Elementor', 'theme-textdomain' ) . '</strong>',
- self::MINIMUM_ELEMENTOR_VERSION
- );
- printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
- }
- public function admin_notice_minimum_php_version() {
- if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
- $message = sprintf(
- esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'theme-textdomain' ),
- '<strong>' . esc_html__( 'Elementor Test Extension', 'theme-textdomain' ) . '</strong>',
- '<strong>' . esc_html__( 'PHP', 'theme-textdomain' ) . '</strong>',
- self::MINIMUM_PHP_VERSION
- );
- printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
- }
- public function init_widgets() {
- require_once( __DIR__ . '/widgets/test-widget.php' );
- \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \testWidget() );
- }
- }
- Elementor_Test_Extension::instance();
Advertisement
Add Comment
Please, Sign In to add comment