Elementor Plugin Generator

Home » WordPress Generators » Elementor Plugin Generator
The name of the plugin
The description of the plugin
The URL of the plugin
The text domain of the plugin
The version of your plugin
The name of the author
The URL of the author
The minimum PHP version required to run this plugin
The minimum Elementor version required to run this plugin
                    /**
* Plugin Name: My Awesome Plugin
* Plugin URI: https://wpturbo.dev
* Description: My custom plugin for Elementor.
* Version: 1.0.0
* Author: WPTurbo
* Author URI: https://wpturbo.dev
* Text Domain: wpturbo
*/
final class My_Custom_Elementor_Plugin {
	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( 'plugins_loaded', array($this, 'plugins_loaded') );
	}

	public function plugins_loaded() {
		if ( $this->check_compatibility() ) {
			add_action( 'elementor/init', array($this, 'init') );
		}
	}

	public function check_compatibility() {
		// Don't load this plugin if Elementor isn't installed or if hasn't been activated
		if ( ! did_action( 'elementor/loaded' ) ) {
			add_action( 'admin_notices', array($this, 'create_admin_notice_elementor_missing') );
			return false;
		}
		// Check Elementor version
		if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
			add_action( 'admin_notices', array($this, 'create_admin_notice_elementor_wrong_version') );
			return false;
		}
		// Check PHP version
		if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
			add_action( 'admin_notices', array($this, 'create_admin_notice_wrong_php_version') );
			return false;
		}
		return true;
	}

	public function create_admin_notice_elementor_missing() {
		$message = '<div class="notice notice-warning is-dismissible">';
			$message .= "<p><strong>My Awesome Plugin</strong> requires <strong>Elementor</strong> plugin to work. Please install and activate the Elementor plugin.</p>";
		$message .= '</div>';
		echo $message;
	}

	public function create_admin_notice_elementor_wrong_version() {
		$message = '<div class="notice notice-warning is-dismissible">';
			$message .= "<p><strong>My Awesome Plugin</strong> requires <strong>Elementor</strong> version 2.0 or higher.</p>";
		$message .= '</div>';
		echo $message;
	}

	public function create_admin_notice_wrong_php_version() {
		$message = '<div class="notice notice-warning is-dismissible">';
			$message .= "<p><strong>My Awesome Plugin</strong> requires <strong>PHP</strong> version 7.0 or higher.</p>";
		$message .= '</div>';
		echo $message;
	}

	public function init() {
		$this->i18n();
		add_action( 'elementor/widgets/widgets_registered', array($this, 'init_widgets') );
		add_action( 'elementor/controls/controls_registered', array($this, 'init_controls') );
	}

	public function i18n() {
		load_plugin_textdomain('wpturbo');
	}

	public function init_widgets() {
		// This is wheere you can include your widget files.
		// require_once( __DIR__ . '/widgets/my-widget.php' );
		// Register your widget after including it.
		// ElementorPlugin::instance()->widgets_manager->register_widget_type( new Your_Elementor_Widget_Class_Name() );
	}

	public function init_controls() {
		// This is where you can include your control files.
		// require_once( __DIR__ . '/controls/my-controls.php' );
		// Register your control after including it.
		// ElementorPlugin::$instance->controls_manager->register_control( 'control-type-', new Your_Control_Class_Name() );
	}

}