Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/elementor/includes/managers/elements.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
namespace Elementor;
3
+
4
+
use Elementor\Includes\Elements\Container;
5
+
6
+
if ( ! defined( 'ABSPATH' ) ) {
7
+
exit; // Exit if accessed directly.
8
+
}
9
+
10
+
/**
11
+
* Elementor elements manager.
12
+
*
13
+
* Elementor elements manager handler class is responsible for registering and
14
+
* initializing all the supported elements.
15
+
*
16
+
* @since 1.0.0
17
+
*/
18
+
class Elements_Manager {
19
+
20
+
/**
21
+
* Element types.
22
+
*
23
+
* Holds the list of all the element types.
24
+
*
25
+
* @access private
26
+
*
27
+
* @var Element_Base[]
28
+
*/
29
+
private $_element_types;
30
+
31
+
/**
32
+
* Element categories.
33
+
*
34
+
* Holds the list of all the element categories.
35
+
*
36
+
* @access private
37
+
*
38
+
* @var $categories
39
+
*/
40
+
private $categories;
41
+
42
+
/**
43
+
* Elements constructor.
44
+
*
45
+
* Initializing Elementor elements manager.
46
+
*
47
+
* @since 1.0.0
48
+
* @access public
49
+
*/
50
+
public function __construct() {
51
+
$this->require_files();
52
+
}
53
+
54
+
/**
55
+
* Create element instance.
56
+
*
57
+
* This method creates a new element instance for any given element.
58
+
*
59
+
* @since 1.0.0
60
+
* @access public
61
+
*
62
+
* @param array $element_data Element data.
63
+
* @param array $element_args Optional. Element arguments. Default is
64
+
* an empty array.
65
+
* @param Element_Base $element_type Optional. Element type. Default is null.
66
+
*
67
+
* @return Element_Base|null Element instance if element created, or null
68
+
* otherwise.
69
+
*/
70
+
public function create_element_instance( array $element_data, array $element_args = [], ?Element_Base $element_type = null ) {
71
+
if ( null === $element_type ) {
72
+
$element_type = $this->get_element( $element_data['elType'], isset( $element_data['widgetType'] ) ? $element_data['widgetType'] : null );
73
+
}
74
+
75
+
if ( ! $element_type ) {
76
+
return null;
77
+
}
78
+
79
+
$args = array_merge( $element_type->get_default_args(), $element_args );
80
+
81
+
$element_class = $element_type->get_class_name();
82
+
83
+
try {
84
+
$element = new $element_class( $element_data, $args );
85
+
} catch ( \Exception $e ) {
86
+
return null;
87
+
}
88
+
89
+
return $element;
90
+
}
91
+
92
+
public function get_element( string $el_type, ?string $widget_type = null ) {
93
+
$element = null;
94
+
95
+
if ( 'widget' === $el_type ) {
96
+
$element = Plugin::$instance->widgets_manager->get_widget_types( $widget_type );
97
+
} else {
98
+
$element = $this->get_element_types( $el_type );
99
+
}
100
+
101
+
return $element;
102
+
}
103
+
104
+
/**
105
+
* Get element categories.
106
+
*
107
+
* Retrieve the list of categories the element belongs to.
108
+
*
109
+
* @since 1.0.0
110
+
* @access public
111
+
*
112
+
* @return array Element categories.
113
+
*/
114
+
public function get_categories() {
115
+
if ( null === $this->categories ) {
116
+
$this->init_categories();
117
+
}
118
+
119
+
return $this->categories;
120
+
}
121
+
122
+
/**
123
+
* Add element category.
124
+
*
125
+
* Register new category for the element.
126
+
*
127
+
* @since 1.7.12
128
+
* @access public
129
+
*
130
+
* @param string $category_name Category name.
131
+
* @param array $category_properties Category properties.
132
+
*/
133
+
public function add_category( $category_name, $category_properties ) {
134
+
if ( null === $this->categories ) {
135
+
$this->get_categories();
136
+
}
137
+
138
+
if ( ! isset( $this->categories[ $category_name ] ) ) {
139
+
$this->categories[ $category_name ] = $category_properties;
140
+
}
141
+
}
142
+
143
+
/**
144
+
* Register element type.
145
+
*
146
+
* Add new type to the list of registered types.
147
+
*
148
+
* @since 1.0.0
149
+
* @access public
150
+
*
151
+
* @param Element_Base $element Element instance.
152
+
*
153
+
* @return bool Whether the element type was registered.
154
+
*/
155
+
public function register_element_type( Element_Base $element ) {
156
+
$this->_element_types[ $element->get_name() ] = $element;
157
+
158
+
return true;
159
+
}
160
+
161
+
/**
162
+
* Unregister element type.
163
+
*
164
+
* Remove element type from the list of registered types.
165
+
*
166
+
* @since 1.0.0
167
+
* @access public
168
+
*
169
+
* @param string $name Element name.
170
+
*
171
+
* @return bool Whether the element type was unregister, or not.
172
+
*/
173
+
public function unregister_element_type( $name ) {
174
+
if ( ! isset( $this->_element_types[ $name ] ) ) {
175
+
return false;
176
+
}
177
+
178
+
unset( $this->_element_types[ $name ] );
179
+
180
+
return true;
181
+
}
182
+
183
+
/**
184
+
* Get element types.
185
+
*
186
+
* Retrieve the list of all the element types, or if a specific element name
187
+
* was provided retrieve his element types.
188
+
*
189
+
* @since 1.0.0
190
+
* @access public
191
+
*
192
+
* @param string $element_name Optional. Element name. Default is null.
193
+
*
194
+
* @return null|Element_Base|Element_Base[] Element types, or a list of all the element
195
+
* types, or null if element does not exist.
196
+
*/
197
+
public function get_element_types( $element_name = null ) {
198
+
if ( is_null( $this->_element_types ) ) {
199
+
$this->init_elements();
200
+
}
201
+
202
+
if ( null !== $element_name ) {
203
+
return isset( $this->_element_types[ $element_name ] ) ? $this->_element_types[ $element_name ] : null;
204
+
}
205
+
206
+
return $this->_element_types;
207
+
}
208
+
209
+
/**
210
+
* Get element types config.
211
+
*
212
+
* Retrieve the config of all the element types.
213
+
*
214
+
* @since 1.0.0
215
+
* @access public
216
+
*
217
+
* @return array Element types config.
218
+
*/
219
+
public function get_element_types_config() {
220
+
$config = [];
221
+
222
+
foreach ( $this->get_element_types() as $element ) {
223
+
$config[ $element->get_name() ] = $element->get_config();
224
+
}
225
+
226
+
return $config;
227
+
}
228
+
229
+
/**
230
+
* Render elements content.
231
+
*
232
+
* Used to generate the elements templates on the editor.
233
+
*
234
+
* @since 1.0.0
235
+
* @access public
236
+
*/
237
+
public function render_elements_content() {
238
+
foreach ( $this->get_element_types() as $element_type ) {
239
+
$element_type->print_template();
240
+
}
241
+
}
242
+
243
+
/**
244
+
* Init elements.
245
+
*
246
+
* Initialize Elementor elements by registering the supported elements.
247
+
* Elementor supports by default `section` element and `column` element.
248
+
*
249
+
* @since 2.0.0
250
+
* @access private
251
+
*/
252
+
private function init_elements() {
253
+
$this->_element_types = [];
254
+
255
+
foreach ( [ 'section', 'column' ] as $element_name ) {
256
+
$class_name = __NAMESPACE__ . '\Element_' . $element_name;
257
+
258
+
$this->register_element_type( new $class_name() );
259
+
}
260
+
261
+
$experiments_manager = Plugin::$instance->experiments;
262
+
263
+
if ( $experiments_manager->is_feature_active( 'container' ) ) {
264
+
$this->register_element_type( new Container() );
265
+
}
266
+
267
+
/**
268
+
* After elements registered.
269
+
*
270
+
* Fires after Elementor elements are registered.
271
+
*
272
+
* @since 1.0.0
273
+
*/
274
+
do_action( 'elementor/elements/elements_registered', $this );
275
+
}
276
+
277
+
/**
278
+
* Init categories.
279
+
*
280
+
* Initialize the element categories.
281
+
*
282
+
* @since 1.7.12
283
+
* @access private
284
+
*/
285
+
private function init_categories() {
286
+
$this->categories = [
287
+
'v4-elements' => [
288
+
'title' => esc_html__( 'Atomic Elements', 'elementor' ),
289
+
'hideIfEmpty' => true,
290
+
],
291
+
'layout' => [
292
+
'title' => esc_html__( 'Layout', 'elementor' ),
293
+
'hideIfEmpty' => true,
294
+
],
295
+
'basic' => [
296
+
'title' => esc_html__( 'Basic', 'elementor' ),
297
+
'icon' => 'eicon-font',
298
+
],
299
+
'pro-elements' => [
300
+
'title' => esc_html__( 'Pro', 'elementor' ),
301
+
'promotion' => [
302
+
'url' => esc_url( 'https://go.elementor.com/go-pro-section-pro-widget-panel/' ),
303
+
],
304
+
],
305
+
'helloplus' => [
306
+
'title' => esc_html__( 'Hello+', 'elementor' ),
307
+
'hideIfEmpty' => true,
308
+
],
309
+
'general' => [
310
+
'title' => esc_html__( 'General', 'elementor' ),
311
+
'icon' => 'eicon-font',
312
+
],
313
+
'link-in-bio' => [
314
+
'title' => esc_html__( 'Link In Bio', 'elementor' ),
315
+
'hideIfEmpty' => true,
316
+
],
317
+
'theme-elements' => [
318
+
'title' => esc_html__( 'Site', 'elementor' ),
319
+
'active' => false,
320
+
'promotion' => [
321
+
'url' => esc_url( 'https://go.elementor.com/go-pro-section-site-widget-panel/' ),
322
+
],
323
+
],
324
+
'woocommerce-elements' => [
325
+
'title' => esc_html__( 'WooCommerce', 'elementor' ),
326
+
'active' => false,
327
+
'promotion' => [
328
+
'url' => esc_url( 'https://go.elementor.com/go-pro-section-woocommerce-widget-panel/' ),
329
+
],
330
+
],
331
+
];
332
+
333
+
// Not using the `add_category` because it doesn't allow 3rd party to inject a category on top the others.
334
+
$this->categories = array_merge_recursive( [
335
+
'favorites' => [
336
+
'title' => esc_html__( 'Favorites', 'elementor' ),
337
+
'icon' => 'eicon-heart',
338
+
'sort' => 'a-z',
339
+
'hideIfEmpty' => false,
340
+
],
341
+
], $this->categories );
342
+
343
+
/**
344
+
* When categories are registered.
345
+
*
346
+
* Fires after basic categories are registered, before WordPress
347
+
* category have been registered.
348
+
*
349
+
* This is where categories registered by external developers are
350
+
* added.
351
+
*
352
+
* @since 2.0.0
353
+
*
354
+
* @param Elements_Manager $this Elements manager instance.
355
+
*/
356
+
do_action( 'elementor/elements/categories_registered', $this );
357
+
358
+
$this->categories['wordpress'] = [
359
+
'title' => esc_html__( 'WordPress', 'elementor' ),
360
+
'icon' => 'eicon-wordpress',
361
+
'active' => false,
362
+
];
363
+
}
364
+
365
+
public function enqueue_elements_styles() {
366
+
foreach ( $this->get_element_types() as $element ) {
367
+
$element->enqueue_styles();
368
+
}
369
+
}
370
+
371
+
public function enqueue_elements_scripts() {
372
+
foreach ( $this->get_element_types() as $element ) {
373
+
$element->enqueue_scripts();
374
+
}
375
+
}
376
+
377
+
public function register_frontend_handlers() {
378
+
foreach ( $this->get_element_types() as $element ) {
379
+
$element->register_frontend_handlers();
380
+
}
381
+
}
382
+
383
+
/**
384
+
* Require files.
385
+
*
386
+
* Require Elementor element base class and column, section and repeater
387
+
* elements.
388
+
*
389
+
* @since 1.0.0
390
+
* @access private
391
+
*/
392
+
private function require_files() {
393
+
require_once ELEMENTOR_PATH . 'includes/base/element-base.php';
394
+
395
+
require ELEMENTOR_PATH . 'includes/elements/column.php';
396
+
require ELEMENTOR_PATH . 'includes/elements/section.php';
397
+
require ELEMENTOR_PATH . 'includes/elements/repeater.php';
398
+
}
399
+
}
400
+