1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
<?php namespace Elementor\Core\Base;
use Elementor\Plugin;
if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. }
/** * Elementor module. * * An abstract class that provides the needed properties and methods to * manage and handle modules in inheriting classes. * * @since 1.7.0 * @abstract */ abstract class Module extends Base_Object {
/** * Module class reflection. * * Holds the information about a class. * * @since 1.7.0 * @access private * * @var \ReflectionClass */ private $reflection;
/** * Module components. * * Holds the module components. * * @since 1.7.0 * @access private * * @var array */ private $components = [];
/** * Module instance. * * Holds the module instance. * * @since 1.7.0 * @access protected * * @var Module */ protected static $_instances = [];
/** * Get module name. * * Retrieve the module name. * * @since 1.7.0 * @access public * @abstract * * @return string Module name. */ abstract public function get_name();
/** * Instance. * * Ensures only one instance of the module class is loaded or can be loaded. * * @since 1.7.0 * @access public * @static * * @return $this An instance of the class. */ public static function instance() { $class_name = static::class_name();
if ( empty( static::$_instances[ $class_name ] ) ) { static::$_instances[ $class_name ] = new static(); }
return static::$_instances[ $class_name ]; }
/** * @since 2.0.0 * @access public * @static */ public static function is_active() { return true; }
/** * Class name. * * Retrieve the name of the class. * * @since 1.7.0 * @access public * @static */ public static function class_name() { return get_called_class(); }
public static function get_experimental_data() { return []; }
/** * Clone. * * Disable class cloning and throw an error on object clone. * * The whole idea of the singleton design pattern is that there is a single * object. Therefore, we don't want the object to be cloned. * * @since 1.7.0 * @access public */ public function __clone() { _doing_it_wrong( __FUNCTION__, sprintf( 'Cloning instances of the singleton "%s" class is forbidden.', get_class( $this ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped '1.0.0' ); }
/** * Wakeup. * * Disable unserializing of the class. * * @since 1.7.0 * @access public */ public function __wakeup() { _doing_it_wrong( __FUNCTION__, sprintf( 'Unserializing instances of the singleton "%s" class is forbidden.', get_class( $this ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped '1.0.0' ); }
/** * @since 2.0.0 * @access public */ public function get_reflection() { if ( null === $this->reflection ) { $this->reflection = new \ReflectionClass( $this ); }
return $this->reflection; }
/** * Add module component. * * Add new component to the current module. * * @since 1.7.0 * @access public * * @param string $id Component ID. * @param mixed $instance An instance of the component. */ public function add_component( $id, $instance ) { $this->components[ $id ] = $instance; }
/** * @since 2.3.0 * @access public * @return Module[] */ public function get_components() { return $this->components; }
/** * Get module component. * * Retrieve the module component. * * @since 1.7.0 * @access public * * @param string $id Component ID. * * @return mixed An instance of the component, or `false` if the component * doesn't exist. */ public function get_component( $id ) { if ( isset( $this->components[ $id ] ) ) { return $this->components[ $id ]; }
return false; }
/** * Get assets url. * * @since 2.3.0 * @access protected * * @param string $file_name * @param string $file_extension * @param string $relative_url Optional. Default is null. * @param string $add_min_suffix Optional. Default is 'default'. * * @return string */ final protected function get_assets_url( $file_name, $file_extension, $relative_url = null, $add_min_suffix = 'default' ) { static $is_test_mode = null;
if ( null === $is_test_mode ) { $is_test_mode = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'ELEMENTOR_TESTS' ) && ELEMENTOR_TESTS; }
if ( ! $relative_url ) { $relative_url = $this->get_assets_relative_url() . $file_extension . '/'; }
$url = $this->get_assets_base_url() . $relative_url . $file_name;
if ( 'default' === $add_min_suffix ) { $add_min_suffix = ! $is_test_mode; }
if ( $add_min_suffix ) { $url .= '.min'; }
return $url . '.' . $file_extension; }
/** * Get js assets url * * @since 2.3.0 * @access protected * * @param string $file_name * @param string $relative_url Optional. Default is null. * @param string $add_min_suffix Optional. Default is 'default'. * * @return string */ final protected function get_js_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default' ) { return $this->get_assets_url( $file_name, 'js', $relative_url, $add_min_suffix ); }
/** * Get css assets url * * @since 2.3.0 * @access protected * * @param string $file_name * @param string $relative_url Optional. Default is null. * @param string $add_min_suffix Optional. Default is 'default'. * @param bool $add_direction_suffix Optional. Default is `false` * * @return string */ final protected function get_css_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default', $add_direction_suffix = false ) { static $direction_suffix = null;
if ( ! $direction_suffix ) { $direction_suffix = is_rtl() ? '-rtl' : ''; }
if ( $add_direction_suffix ) { $file_name .= $direction_suffix; }
return $this->get_assets_url( $file_name, 'css', $relative_url, $add_min_suffix ); }
/** * Get Frontend File URL * * Returns the URL for the CSS file to be loaded in the front end. If requested via the second parameter, a custom * file is generated based on a passed template file name. Otherwise, the URL for the default CSS file is returned. * * @since 3.24.0 * * @access public * * @param string $file_name * @param boolean $has_custom_breakpoints * * @return string frontend file URL */ public function get_frontend_file_url( $file_name, $has_custom_breakpoints ) { return Plugin::$instance->frontend->get_frontend_file_url( $file_name, $has_custom_breakpoints ); }
/** * Get assets base url * * @since 2.6.0 * @access protected * * @return string */ protected function get_assets_base_url() { return ELEMENTOR_URL; }
/** * Get assets relative url * * @since 2.3.0 * @access protected * * @return string */ protected function get_assets_relative_url() { return 'assets/'; }
/** * Get the module's associated widgets. * * @return string[] */ protected function get_widgets() { return []; }
/** * Initialize the module related widgets. */ public function init_widgets() { $widget_manager = Plugin::instance()->widgets_manager;
foreach ( $this->get_widgets() as $widget ) { $class_name = $this->get_reflection()->getNamespaceName() . '\Widgets\\' . $widget;
$widget_manager->register( new $class_name() ); } }
public function __construct() { add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] ); } }
|