PluginProbe
Selection Lite / 1.12
Selection Lite v1.12
trunk 1.0 1.1 1.10 1.11 1.12 1.14 1.15 1.16 1.17 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
selection-lite / src / Merkulove / Unity / Elementor.php

Elementor.php in Selection Lite 1.12, at src/Merkulove/Unity/Elementor.php

168 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Selection Lite
4 * Carefully selected Elementor addons bundle, for building the most awesome websites
5 *
6 * @encoding UTF-8
7 * @version 1.12
8 * @copyright (C) 2018-2024 Merkulove ( https://merkulov.design/ ). All rights reserved.
9 * @license GPLv3
10 * @contributors merkulove, vladcherviakov, phoenixmkua, podolianochka, viktorialev01
11 * @support help@merkulov.design
12 **/
13
14 namespace Merkulove\SelectionLite\Unity;
15
16 use RecursiveDirectoryIterator;
17 use RecursiveIteratorIterator;
18
19 /** Exit if accessed directly. */
20 if ( ! defined( 'ABSPATH' ) ) {
21 header( 'Status: 403 Forbidden' );
22 header( 'HTTP/1.1 403 Forbidden' );
23 exit;
24 }
25
26 /**
27 * Class to implement Elementor Widget.
28 *
29 * @since 1.0
30 *
31 **/
32 final class Elementor {
33
34 /**
35 * The one true Elementor.
36 *
37 * @var Elementor
38 **/
39 private static $instance;
40
41 /**
42 * Setup the Unity.
43 *
44 * @since 1.0
45 * @access public
46 *
47 * @return void
48 **/
49 public function setup() {
50
51 /** Check if Elementor installed and activated. */
52 if ( ! did_action( 'elementor/loaded' ) ) { return; }
53
54 /** Register custom widgets. */
55 add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_widgets' ] );
56 }
57
58 /**
59 * Register new Elementor widgets.
60 *
61 * @access public
62 * @since 1.0
63 *
64 * @return void
65 **/
66 public function register_widgets() {
67
68 /** Load and register Elementor widgets. */
69 $path = Plugin::get_path() . 'src/Merkulove/SelectionLite/Elementor/widgets/';
70
71 foreach ( new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $path ) ) as $filename ) {
72
73 if ( substr( $filename, -4 ) === '.php' ) {
74
75 /** @noinspection PhpIncludeInspection */
76 require_once $filename;
77
78 /** Prepare class name from file. */
79 $widget_class = $filename->getBasename( '.php' );
80 $widget_class = str_replace( '.', '_', $widget_class );
81
82 /** Add Namespace. */
83 $widget_class = 'Merkulove\SelectionLite\\' . $widget_class;
84
85 /** Instantiate widget and register it in Elementor. */
86 \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new $widget_class() );
87
88 }
89
90 }
91
92 /** Sort our widgets inside Category. */
93 $this->sort_widgets();
94
95 }
96
97 /**
98 * Sort our widgets inside Category.
99 *
100 * @access public
101 * @since 1.0
102 *
103 * @return void
104 **/
105 private function sort_widgets() {
106
107 /** Get Widget Manager. */
108 $widgets_manager = \Elementor\Plugin::instance()->widgets_manager;
109
110 /** Retrieve all registered widgets. */
111 $widget_types = $widgets_manager->get_widget_types();
112
113 /** Collection of widget classes and initialisation order. */
114 $new_order = [];
115
116 foreach ( $widget_types as $key => $widget_type ) {
117
118 /** Get widget class name. */
119 $widget_class = get_class( $widget_type );
120
121 /** Skip this widget, it cause warning on reinitialisation */
122 if ( 'Elementor\Widget_WordPress' === $widget_class ) { continue; }
123
124 /** Get widget order. */
125 /** @noinspection PhpPossiblePolymorphicInvocationInspection */
126 $order = property_exists( $widget_type, 'mdp_order' ) ? $widget_type->mdp_order : 0;
127
128 /** Remember class and order. */
129 $new_order[$widget_class] = $order;
130
131 /** Unregister all widgets. */
132 $widgets_manager->unregister_widget_type( $key );
133
134 }
135
136 /** Sort widgets by mdp_order. */
137 asort( $new_order );
138
139 /** Instantiate widgets in correct order. */
140 foreach ( $new_order as $class => $o ) {
141 $widgets_manager->register_widget_type( new $class );
142 }
143
144 }
145
146 /**
147 * Main Elementor Instance.
148 *
149 * Insures that only one instance of Elementor exists in memory at any one time.
150 *
151 * @static
152 *
153 * @return Elementor
154 **/
155 public static function get_instance() {
156
157 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
158
159 self::$instance = new self;
160
161 }
162
163 return self::$instance;
164
165 }
166
167 }
168