Advertisement
raselahmed7

ElementorWoo Class # 5 | Plugin index.php

Feb 26th, 2019
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.22 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: RRF Commerce Elementor
  4.  * Description: Custom Elementor extension for RRF Commerce Theme.
  5.  * Plugin URI:  https://anything.com/
  6.  * Version:     1.0.0
  7.  * Author:      Rasel Ahmed
  8.  * Author URI:  https://anythingauthor.com/
  9.  * Text Domain: rrfcommerce-elementor
  10.  */
  11.  
  12. if ( ! defined( 'ABSPATH' ) ) {
  13.     exit;
  14. }
  15.  
  16. final class RRF_Commerce_Extension {
  17.  
  18.     const VERSION = '1.0.0';
  19.     const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
  20.     const MINIMUM_PHP_VERSION = '5.6';
  21.     private static $_instance = null;
  22.     public static function instance() {
  23.  
  24.         if ( is_null( self::$_instance ) ) {
  25.             self::$_instance = new self();
  26.         }
  27.         return self::$_instance;
  28.  
  29.     }
  30.  
  31.     public function __construct() {
  32.         add_action( 'init', [ $this, 'i18n' ] );
  33.         add_action( 'plugins_loaded', [ $this, 'init' ] );
  34.     }
  35.  
  36.     public function i18n() {
  37.         load_plugin_textdomain( 'rrfcommerce-elementor' );
  38.     }
  39.  
  40.     public function init() {
  41.         if ( ! did_action( 'elementor/loaded' ) ) {
  42.             add_action( 'admin_notices', [ $this, 'admin_notice_missing_main_plugin' ] );
  43.             return;
  44.         }
  45.  
  46.         if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
  47.             add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] );
  48.             return;
  49.         }
  50.  
  51.         if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
  52.             add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
  53.             return;
  54.         }
  55.  
  56.         add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] );
  57.         add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'widget_styles' ] );
  58.     }
  59.  
  60.  
  61.     public function admin_notice_missing_main_plugin() {
  62.  
  63.         if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
  64.  
  65.         $message = sprintf(
  66.             esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'rrfcommerce-elementor' ),
  67.             '<strong>' . esc_html__( 'Elementor Test Extension', 'rrfcommerce-elementor' ) . '</strong>',
  68.             '<strong>' . esc_html__( 'Elementor', 'rrfcommerce-elementor' ) . '</strong>'
  69.         );
  70.  
  71.         printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
  72.  
  73.     }
  74.  
  75.     public function admin_notice_minimum_elementor_version() {
  76.  
  77.         if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
  78.  
  79.         $message = sprintf(
  80.             esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'rrfcommerce-elementor' ),
  81.             '<strong>' . esc_html__( 'Elementor Test Extension', 'rrfcommerce-elementor' ) . '</strong>',
  82.             '<strong>' . esc_html__( 'Elementor', 'rrfcommerce-elementor' ) . '</strong>',
  83.              self::MINIMUM_ELEMENTOR_VERSION
  84.         );
  85.  
  86.         printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
  87.  
  88.     }
  89.  
  90.     public function admin_notice_minimum_php_version() {
  91.  
  92.         if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
  93.  
  94.         $message = sprintf(
  95.             esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'rrfcommerce-elementor' ),
  96.             '<strong>' . esc_html__( 'Elementor Test Extension', 'rrfcommerce-elementor' ) . '</strong>',
  97.             '<strong>' . esc_html__( 'PHP', 'rrfcommerce-elementor' ) . '</strong>',
  98.              self::MINIMUM_PHP_VERSION
  99.         );
  100.  
  101.         printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
  102.  
  103.     }
  104.  
  105.     public function init_widgets() {
  106.  
  107.         require_once( __DIR__ . '/widgets/slider.php' );
  108.         require_once( __DIR__ . '/widgets/content-block.php' );
  109.        
  110.         \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \RRFCommerce_Slider_Widget() );
  111.         \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \RRFCommerce_ContentBlock_Widget() );
  112.  
  113.     }
  114.  
  115.     public function widget_styles() {
  116.  
  117.         wp_enqueue_style( 'rrfcommerce-slider', plugins_url( 'widgets/css/slider.css', __FILE__ ) );
  118.         wp_enqueue_style( 'rrfcommerce-content-block', plugins_url( 'widgets/css/content-box.css', __FILE__ ) );
  119.  
  120.     }
  121.  
  122. }
  123.  
  124. RRF_Commerce_Extension::instance();
  125.  
  126. function rrf_commerce_plugin_scripts() {
  127.     wp_enqueue_style( 'slick', plugins_url( 'assets/css/slick.css', __FILE__ ) );
  128.    
  129.     wp_enqueue_script( 'slick', plugins_url( 'assets/js/slick.min.js', __FILE__ ), array('jquery'), '20151215', true );
  130. }
  131. add_action( 'wp_enqueue_scripts', 'rrf_commerce_plugin_scripts' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement