kalponikoronno

elementor-activator.php

Mar 11th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.32 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {
  4.     exit; // Exit if accessed directly.
  5. }
  6. final class Elementor_Test_Extension {
  7.     const VERSION = '1.0.0';
  8.     const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
  9.     const MINIMUM_PHP_VERSION = '7.0';
  10.     private static $_instance = null;
  11.    
  12.     public static function instance() {
  13.        
  14.         if ( is_null( self::$_instance ) ) {
  15.             self::$_instance = new self();
  16.         }
  17.         return self::$_instance;
  18.        
  19.     }
  20.    
  21.     public function __construct() {
  22.         add_action( 'after_setup_theme', [ $this, 'init' ] );
  23.     }
  24.    
  25.     public function init() {
  26.         if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
  27.             add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] );
  28.             return;
  29.         }
  30.         if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
  31.             add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
  32.             return;
  33.         }
  34.         add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] );
  35.     }
  36.    
  37.     public function admin_notice_minimum_elementor_version() {
  38.        
  39.         if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
  40.        
  41.         $message = sprintf(
  42.             esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'theme-textdomain' ),
  43.             '<strong>' . esc_html__( 'Elementor Test Extension', 'theme-textdomain' ) . '</strong>',
  44.             '<strong>' . esc_html__( 'Elementor', 'theme-textdomain' ) . '</strong>',
  45.             self::MINIMUM_ELEMENTOR_VERSION
  46.         );
  47.        
  48.         printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
  49.        
  50.     }
  51.    
  52.     public function admin_notice_minimum_php_version() {
  53.        
  54.         if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
  55.        
  56.         $message = sprintf(
  57.             esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'theme-textdomain' ),
  58.             '<strong>' . esc_html__( 'Elementor Test Extension', 'theme-textdomain' ) . '</strong>',
  59.             '<strong>' . esc_html__( 'PHP', 'theme-textdomain' ) . '</strong>',
  60.             self::MINIMUM_PHP_VERSION
  61.         );
  62.        
  63.         printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
  64.        
  65.     }
  66.    
  67.     public function init_widgets() {
  68.         require_once( __DIR__ . '/widgets/test-widget.php' );
  69.         \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \testWidget() );
  70.        
  71.     }
  72.  
  73.    
  74. }
  75.  
  76. Elementor_Test_Extension::instance();
Advertisement
Add Comment
Please, Sign In to add comment