Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // create a folder to plugin directory then crate index.php and a folder name widgets in widgets create a file named slider.php
- // Paste this to index.php file
- <?php
- /**
- * Plugin Name: Elementor Test Extension
- * Description: Custom Elementor extension.
- * Plugin URI: https://elementor.com/
- * Version: 1.0.0
- * Author: Elementor
- * Author URI: https://elementor.com/
- * Text Domain: rrf-commerce
- */
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly.
- }
- /**
- * Main Elementor Test Extension Class
- *
- * The main class that initiates and runs the plugin.
- *
- * @since 1.0.0
- */
- final class RRF_Commerce_Extension {
- /**
- * Plugin Version
- *
- * @since 1.0.0
- *
- * @var string The plugin version.
- */
- const VERSION = '1.0.0';
- /**
- * Minimum Elementor Version
- *
- * @since 1.0.0
- *
- * @var string Minimum Elementor version required to run the plugin.
- */
- const MINIMUM_ELEMENTOR_VERSION = '2.0.0';
- /**
- * Minimum PHP Version
- *
- * @since 1.0.0
- *
- * @var string Minimum PHP version required to run the plugin.
- */
- const MINIMUM_PHP_VERSION = '5.6';
- /**
- * Instance
- *
- * @since 1.0.0
- *
- * @access private
- * @static
- *
- * @var RRF_Commerce_Extension The single instance of the class.
- */
- private static $_instance = null;
- /**
- * Instance
- *
- * Ensures only one instance of the class is loaded or can be loaded.
- *
- * @since 1.0.0
- *
- * @access public
- * @static
- *
- * @return RRF_Commerce_Extension An instance of the class.
- */
- public static function instance() {
- if ( is_null( self::$_instance ) ) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- /**
- * Constructor
- *
- * @since 1.0.0
- *
- * @access public
- */
- public function __construct() {
- add_action( 'init', [ $this, 'i18n' ] );
- add_action( 'plugins_loaded', [ $this, 'init' ] );
- }
- /**
- * Load Textdomain
- *
- * Load plugin localization files.
- *
- * Fired by `init` action hook.
- *
- * @since 1.0.0
- *
- * @access public
- */
- public function i18n() {
- load_plugin_textdomain( 'rrf-commerce' );
- }
- /**
- * Initialize the plugin
- *
- * Load the plugin only after Elementor (and other plugins) are loaded.
- * Checks for basic plugin requirements, if one check fail don't continue,
- * if all check have passed load the files required to run the plugin.
- *
- * Fired by `plugins_loaded` action hook.
- *
- * @since 1.0.0
- *
- * @access public
- */
- public function init() {
- // Check if Elementor installed and activated
- if ( ! did_action( 'elementor/loaded' ) ) {
- add_action( 'admin_notices', [ $this, 'admin_notice_missing_main_plugin' ] );
- return;
- }
- // Check for required Elementor version
- if ( ! version_compare( ELEMENTOR_VERSION, self::MINIMUM_ELEMENTOR_VERSION, '>=' ) ) {
- add_action( 'admin_notices', [ $this, 'admin_notice_minimum_elementor_version' ] );
- return;
- }
- // Check for required PHP version
- if ( version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '<' ) ) {
- add_action( 'admin_notices', [ $this, 'admin_notice_minimum_php_version' ] );
- return;
- }
- // Add Plugin actions
- add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] );
- // activate widget style
- add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'widget_styles' ] );
- }
- /**
- * Admin notice
- *
- * Warning when the site doesn't have Elementor installed or activated.
- *
- * @since 1.0.0
- *
- * @access public
- */
- public function admin_notice_missing_main_plugin() {
- if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
- $message = sprintf(
- /* translators: 1: Plugin name 2: Elementor */
- esc_html__( '"%1$s" requires "%2$s" to be installed and activated.', 'elementor-test-extension' ),
- '<strong>' . esc_html__( 'Elementor Test Extension', 'elementor-test-extension' ) . '</strong>',
- '<strong>' . esc_html__( 'Elementor', 'elementor-test-extension' ) . '</strong>'
- );
- printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
- }
- /**
- * Admin notice
- *
- * Warning when the site doesn't have a minimum required Elementor version.
- *
- * @since 1.0.0
- *
- * @access public
- */
- public function admin_notice_minimum_elementor_version() {
- if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
- $message = sprintf(
- /* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */
- esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'elementor-test-extension' ),
- '<strong>' . esc_html__( 'Elementor Test Extension', 'elementor-test-extension' ) . '</strong>',
- '<strong>' . esc_html__( 'Elementor', 'elementor-test-extension' ) . '</strong>',
- self::MINIMUM_ELEMENTOR_VERSION
- );
- printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
- }
- /**
- * Admin notice
- *
- * Warning when the site doesn't have a minimum required PHP version.
- *
- * @since 1.0.0
- *
- * @access public
- */
- public function admin_notice_minimum_php_version() {
- if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] );
- $message = sprintf(
- /* translators: 1: Plugin name 2: PHP 3: Required PHP version */
- esc_html__( '"%1$s" requires "%2$s" version %3$s or greater.', 'elementor-test-extension' ),
- '<strong>' . esc_html__( 'Elementor Test Extension', 'elementor-test-extension' ) . '</strong>',
- '<strong>' . esc_html__( 'PHP', 'elementor-test-extension' ) . '</strong>',
- self::MINIMUM_PHP_VERSION
- );
- printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message );
- }
- /**
- * Init Widgets
- *
- * Include widgets files and register them
- *
- * @since 1.0.0
- *
- * @access public
- */
- public function init_widgets() {
- // Include Widget files
- require_once( __DIR__ . '/widgets/slider.php' );
- require_once( __DIR__ . '/widgets/content-block.php' );
- // Register widget
- \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \RRFCommerce_Slider_Widget() );
- \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \RRFCommerce_contentBlock_Widget() );
- }
- public function widget_styles() {
- wp_enqueue_style( 'rrfcommerce-slider', plugins_url( '/widgets/assets/css/slider.css', __FILE__ ) );
- wp_enqueue_style( 'rrfcommerce-content-block', plugins_url( '/widgets/assets/css/content-box.css', __FILE__ ) );
- }
- }
- RRF_Commerce_Extension::instance();
- function rrf_commerce_plugin_scripts() {
- wp_enqueue_style( 'slick', plugins_url( 'assets/css/slick.css', __FILE__ ) );
- wp_enqueue_script( 'slick', plugins_url( 'assets/js/slick.min.js',__FILE__ ), array('jquery'), '155454546', true );
- }
- add_action( 'wp_enqueue_scripts', 'rrf_commerce_plugin_scripts' );
- // paste this to slider.php file to widgets/slider.php file
- <?php
- class RRFCommerce_Slider_Widget extends \Elementor\Widget_Base {
- public function get_name() {
- return 'rrfcommerce-slider';
- }
- public function get_title() {
- return __( 'RRFCommerce Slider', 'plugin-name' );
- }
- public function get_icon() {
- return 'fa fa-code';
- }
- public function get_categories() {
- return [ 'general' ];
- }
- protected function _register_controls() {
- $this->start_controls_section(
- 'content_section',
- [
- 'label' => __( 'Content', 'plugin-name' ),
- 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
- ]
- );
- $repeater = new \Elementor\Repeater();
- $repeater->add_control(
- 'slide_title', [
- 'label' => __( 'Title', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::TEXT,
- 'default' => __( 'Slide title' , 'plugin-domain' ),
- 'label_block' => true,
- ]
- );
- $repeater->add_control(
- 'slide_content', [
- 'label' => __( 'Content', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::WYSIWYG,
- 'default' => __( 'Slide Content' , 'plugin-domain' ),
- 'show_label' => true,
- ]
- );
- $repeater->add_control(
- 'slide_desc',
- [
- 'label' => __( 'Slide description', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::TEXT,
- 'show_label' => true,
- ]
- );
- $repeater->add_control(
- 'slide_image',
- [
- 'label' => __( 'Slide image', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::MEDIA,
- 'show_label' => true,
- ]
- );
- $this->add_control(
- 'slides',
- [
- 'label' => __( 'Slides', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::REPEATER,
- 'fields' => $repeater->get_controls(),
- 'default' => [
- [
- 'list_title' => __( 'Slide #1', 'plugin-domain' ),
- 'list_content' => __( 'Slide content', 'plugin-domain' ),
- ],
- ]
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'setting_section',
- [
- 'label' => __( 'Slider Settings', 'plugin-name' ),
- 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
- ]
- );
- $this->add_control(
- 'fade',
- [
- 'label' => __( 'Fade effecct?', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'label_on' => __( 'Yes', 'your-plugin' ),
- 'label_off' => __( 'No', 'your-plugin' ),
- 'return_value' => 'yes',
- 'default' => 'no',
- ]
- );
- $this->add_control(
- 'loop',
- [
- 'label' => __( 'Loop?', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'label_on' => __( 'Yes', 'your-plugin' ),
- 'label_off' => __( 'No', 'your-plugin' ),
- 'return_value' => 'yes',
- 'default' => 'yes',
- ]
- );
- $this->add_control(
- 'arrows',
- [
- 'label' => __( 'Show arrows?', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'label_on' => __( 'Show', 'your-plugin' ),
- 'label_off' => __( 'Hide', 'your-plugin' ),
- 'return_value' => 'yes',
- 'default' => 'yes',
- ]
- );
- $this->add_control(
- 'dots',
- [
- 'label' => __( 'Show dots?', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'label_on' => __( 'Show', 'your-plugin' ),
- 'label_off' => __( 'Hide', 'your-plugin' ),
- 'return_value' => 'yes',
- 'default' => 'yes',
- ]
- );
- $this->add_control(
- 'autoplay',
- [
- 'label' => __( 'Autoplay?', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::SWITCHER,
- 'label_on' => __( 'Yes', 'your-plugin' ),
- 'label_off' => __( 'No', 'your-plugin' ),
- 'return_value' => 'yes',
- 'default' => 'yes',
- ]
- );
- $this->add_control(
- 'autoplay_time',
- [
- 'label' => __( 'Autoplay Time', 'plugin-domain' ),
- 'type' => \Elementor\Controls_Manager::TEXT,
- 'default' => '5000',
- 'condition' => [
- 'autoplay' => 'yes',
- ],
- ]
- );
- $this->end_controls_section();
- }
- protected function render() {
- $settings = $this->get_settings_for_display();
- if($settings['slides']) {
- $dynamic_id = rand(78676, 967698);
- if(count($settings['slides']) > 1) {
- if($settings['fade'] == 'yes') {
- $fade = 'true';
- } else {
- $fade = 'false';
- }
- if($settings['arrows'] == 'yes') {
- $arrows = 'true';
- } else {
- $arrows = 'false';
- }
- if($settings['dots'] == 'yes') {
- $dots = 'true';
- } else {
- $dots = 'false';
- }
- if($settings['autoplay'] == 'yes') {
- $autoplay = 'true';
- } else {
- $autoplay = 'false';
- }
- if($settings['loop'] == 'yes') {
- $loop = 'true';
- } else {
- $loop = 'false';
- }
- echo '<script>
- jQuery(document).ready(function($) {
- $("#slides-'.$dynamic_id.'").slick({
- arrows: '.$arrows.',
- prevArrow: "<i class=\'fa fa-angle-left\'></i>",
- nextArrow: "<i class=\'fa fa-angle-right\'></i>",
- dots: '.$dots.',
- fade: '.$fade.',
- autoplay: '.$autoplay.',
- loop: '.$loop.',';
- if($autoplay == 'true') {
- echo 'autoplaySpeed: '.$settings['autoplay_time'].'';
- }
- echo '
- });
- });
- </script>';
- }
- echo '<div id="slides-'.$dynamic_id.'" class="slides">';
- foreach($settings['slides'] as $slide) {
- echo '<div class="single-slide-item" style="background-image:url('.wp_get_attachment_image_url($slide['slide_image']['id'], 'large').')">
- <div class="row">
- <div class="col my-auto">
- '.wpautop($slide['slide_content']).'
- </div>
- </div>
- <div class="slide-info">
- <h4>'.$slide['slide_title'].'</h4>
- '.$slide['slide_desc'].'
- </div>
- </div>';
- }
- echo '</div>';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment