PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev2
Elementor Website Builder – more than just a page builder v3.35.0-dev2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / managers / elements.php

elements.php in Elementor Website Builder – more than just a page builder 3.35.0-dev2, at includes/managers/elements.php

404 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 'atomic-form' => [
292 'title' => esc_html__( 'Atomic Form', 'elementor' ),
293 'hideIfEmpty' => true,
294 ],
295 'layout' => [
296 'title' => esc_html__( 'Layout', 'elementor' ),
297 'hideIfEmpty' => true,
298 ],
299 'basic' => [
300 'title' => esc_html__( 'Basic', 'elementor' ),
301 'icon' => 'eicon-font',
302 ],
303 'pro-elements' => [
304 'title' => esc_html__( 'Pro', 'elementor' ),
305 'promotion' => [
306 'url' => esc_url( 'https://go.elementor.com/go-pro-section-pro-widget-panel/' ),
307 ],
308 ],
309 'helloplus' => [
310 'title' => esc_html__( 'Hello+', 'elementor' ),
311 'hideIfEmpty' => true,
312 ],
313 'general' => [
314 'title' => esc_html__( 'General', 'elementor' ),
315 'icon' => 'eicon-font',
316 ],
317 'link-in-bio' => [
318 'title' => esc_html__( 'Link In Bio', 'elementor' ),
319 'hideIfEmpty' => true,
320 ],
321 'theme-elements' => [
322 'title' => esc_html__( 'Site', 'elementor' ),
323 'active' => false,
324 'promotion' => [
325 'url' => esc_url( 'https://go.elementor.com/go-pro-section-site-widget-panel/' ),
326 ],
327 ],
328 'woocommerce-elements' => [
329 'title' => esc_html__( 'WooCommerce', 'elementor' ),
330 'active' => false,
331 'promotion' => [
332 'url' => esc_url( 'https://go.elementor.com/go-pro-section-woocommerce-widget-panel/' ),
333 ],
334 ],
335 ];
336
337 // Not using the `add_category` because it doesn't allow 3rd party to inject a category on top the others.
338 $this->categories = array_merge_recursive( [
339 'favorites' => [
340 'title' => esc_html__( 'Favorites', 'elementor' ),
341 'icon' => 'eicon-heart',
342 'sort' => 'a-z',
343 'hideIfEmpty' => false,
344 ],
345 ], $this->categories );
346
347 /**
348 * When categories are registered.
349 *
350 * Fires after basic categories are registered, before WordPress
351 * category have been registered.
352 *
353 * This is where categories registered by external developers are
354 * added.
355 *
356 * @since 2.0.0
357 *
358 * @param Elements_Manager $this Elements manager instance.
359 */
360 do_action( 'elementor/elements/categories_registered', $this );
361
362 $this->categories['wordpress'] = [
363 'title' => esc_html__( 'WordPress', 'elementor' ),
364 'icon' => 'eicon-wordpress',
365 'active' => false,
366 ];
367 }
368
369 public function enqueue_elements_styles() {
370 foreach ( $this->get_element_types() as $element ) {
371 $element->enqueue_styles();
372 }
373 }
374
375 public function enqueue_elements_scripts() {
376 foreach ( $this->get_element_types() as $element ) {
377 $element->enqueue_scripts();
378 }
379 }
380
381 public function register_frontend_handlers() {
382 foreach ( $this->get_element_types() as $element ) {
383 $element->register_frontend_handlers();
384 }
385 }
386
387 /**
388 * Require files.
389 *
390 * Require Elementor element base class and column, section and repeater
391 * elements.
392 *
393 * @since 1.0.0
394 * @access private
395 */
396 private function require_files() {
397 require_once ELEMENTOR_PATH . 'includes/base/element-base.php';
398
399 require ELEMENTOR_PATH . 'includes/elements/column.php';
400 require ELEMENTOR_PATH . 'includes/elements/section.php';
401 require ELEMENTOR_PATH . 'includes/elements/repeater.php';
402 }
403 }
404