PluginProbe
Elementor Website Builder – more than just a page builder / 3.26.0-dev5
Elementor Website Builder – more than just a page builder v3.26.0-dev5
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.26.0-dev5, at includes/managers/elements.php

366 lines 8.5 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
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 if ( 'widget' === $element_data['elType'] ) {
73 $element_type = Plugin::$instance->widgets_manager->get_widget_types( $element_data['widgetType'] );
74 } else {
75 $element_type = $this->get_element_types( $element_data['elType'] );
76 }
77 }
78
79 if ( ! $element_type ) {
80 return null;
81 }
82
83 $args = array_merge( $element_type->get_default_args(), $element_args );
84
85 $element_class = $element_type->get_class_name();
86
87 try {
88 $element = new $element_class( $element_data, $args );
89 } catch ( \Exception $e ) {
90 return null;
91 }
92
93 return $element;
94 }
95
96 /**
97 * Get element categories.
98 *
99 * Retrieve the list of categories the element belongs to.
100 *
101 * @since 1.0.0
102 * @access public
103 *
104 * @return array Element categories.
105 */
106 public function get_categories() {
107 if ( null === $this->categories ) {
108 $this->init_categories();
109 }
110
111 return $this->categories;
112 }
113
114 /**
115 * Add element category.
116 *
117 * Register new category for the element.
118 *
119 * @since 1.7.12
120 * @access public
121 *
122 * @param string $category_name Category name.
123 * @param array $category_properties Category properties.
124 */
125 public function add_category( $category_name, $category_properties ) {
126 if ( null === $this->categories ) {
127 $this->get_categories();
128 }
129
130 if ( ! isset( $this->categories[ $category_name ] ) ) {
131 $this->categories[ $category_name ] = $category_properties;
132 }
133 }
134
135 /**
136 * Register element type.
137 *
138 * Add new type to the list of registered types.
139 *
140 * @since 1.0.0
141 * @access public
142 *
143 * @param Element_Base $element Element instance.
144 *
145 * @return bool Whether the element type was registered.
146 */
147 public function register_element_type( Element_Base $element ) {
148 $this->_element_types[ $element->get_name() ] = $element;
149
150 return true;
151 }
152
153 /**
154 * Unregister element type.
155 *
156 * Remove element type from the list of registered types.
157 *
158 * @since 1.0.0
159 * @access public
160 *
161 * @param string $name Element name.
162 *
163 * @return bool Whether the element type was unregister, or not.
164 */
165 public function unregister_element_type( $name ) {
166 if ( ! isset( $this->_element_types[ $name ] ) ) {
167 return false;
168 }
169
170 unset( $this->_element_types[ $name ] );
171
172 return true;
173 }
174
175 /**
176 * Get element types.
177 *
178 * Retrieve the list of all the element types, or if a specific element name
179 * was provided retrieve his element types.
180 *
181 * @since 1.0.0
182 * @access public
183 *
184 * @param string $element_name Optional. Element name. Default is null.
185 *
186 * @return null|Element_Base|Element_Base[] Element types, or a list of all the element
187 * types, or null if element does not exist.
188 */
189 public function get_element_types( $element_name = null ) {
190 if ( is_null( $this->_element_types ) ) {
191 $this->init_elements();
192 }
193
194 if ( null !== $element_name ) {
195 return isset( $this->_element_types[ $element_name ] ) ? $this->_element_types[ $element_name ] : null;
196 }
197
198 return $this->_element_types;
199 }
200
201 /**
202 * Get element types config.
203 *
204 * Retrieve the config of all the element types.
205 *
206 * @since 1.0.0
207 * @access public
208 *
209 * @return array Element types config.
210 */
211 public function get_element_types_config() {
212 $config = [];
213
214 foreach ( $this->get_element_types() as $element ) {
215 $config[ $element->get_name() ] = $element->get_config();
216 }
217
218 return $config;
219 }
220
221 /**
222 * Render elements content.
223 *
224 * Used to generate the elements templates on the editor.
225 *
226 * @since 1.0.0
227 * @access public
228 */
229 public function render_elements_content() {
230 foreach ( $this->get_element_types() as $element_type ) {
231 $element_type->print_template();
232 }
233 }
234
235 /**
236 * Init elements.
237 *
238 * Initialize Elementor elements by registering the supported elements.
239 * Elementor supports by default `section` element and `column` element.
240 *
241 * @since 2.0.0
242 * @access private
243 */
244 private function init_elements() {
245 $this->_element_types = [];
246
247 foreach ( [ 'section', 'column' ] as $element_name ) {
248 $class_name = __NAMESPACE__ . '\Element_' . $element_name;
249
250 $this->register_element_type( new $class_name() );
251 }
252
253 $experiments_manager = Plugin::$instance->experiments;
254
255 if ( $experiments_manager->is_feature_active( 'container' ) ) {
256 $this->register_element_type( new Container() );
257 }
258
259 /**
260 * After elements registered.
261 *
262 * Fires after Elementor elements are registered.
263 *
264 * @since 1.0.0
265 */
266 do_action( 'elementor/elements/elements_registered', $this );
267 }
268
269 /**
270 * Init categories.
271 *
272 * Initialize the element categories.
273 *
274 * @since 1.7.12
275 * @access private
276 */
277 private function init_categories() {
278 $this->categories = [
279 'layout' => [
280 'title' => esc_html__( 'Layout', 'elementor' ),
281 'hideIfEmpty' => true,
282 ],
283 'basic' => [
284 'title' => esc_html__( 'Basic', 'elementor' ),
285 'icon' => 'eicon-font',
286 ],
287 'pro-elements' => [
288 'title' => esc_html__( 'Pro', 'elementor' ),
289 'promotion' => [
290 'url' => esc_url( 'https://go.elementor.com/go-pro-section-pro-widget-panel/' ),
291 ],
292 ],
293 'general' => [
294 'title' => esc_html__( 'General', 'elementor' ),
295 'icon' => 'eicon-font',
296 ],
297 'link-in-bio' => [
298 'title' => esc_html__( 'Link In Bio', 'elementor' ),
299 'hideIfEmpty' => true,
300 ],
301 'theme-elements' => [
302 'title' => esc_html__( 'Site', 'elementor' ),
303 'active' => false,
304 'promotion' => [
305 'url' => esc_url( 'https://go.elementor.com/go-pro-section-site-widget-panel/' ),
306 ],
307 ],
308 'woocommerce-elements' => [
309 'title' => esc_html__( 'WooCommerce', 'elementor' ),
310 'active' => false,
311 'promotion' => [
312 'url' => esc_url( 'https://go.elementor.com/go-pro-section-woocommerce-widget-panel/' ),
313 ],
314 ],
315 ];
316
317 // Not using the `add_category` because it doesn't allow 3rd party to inject a category on top the others.
318 $this->categories = array_merge_recursive( [
319 'favorites' => [
320 'title' => esc_html__( 'Favorites', 'elementor' ),
321 'icon' => 'eicon-heart',
322 'sort' => 'a-z',
323 'hideIfEmpty' => false,
324 ],
325 ], $this->categories );
326
327 /**
328 * When categories are registered.
329 *
330 * Fires after basic categories are registered, before WordPress
331 * category have been registered.
332 *
333 * This is where categories registered by external developers are
334 * added.
335 *
336 * @since 2.0.0
337 *
338 * @param Elements_Manager $this Elements manager instance.
339 */
340 do_action( 'elementor/elements/categories_registered', $this );
341
342 $this->categories['wordpress'] = [
343 'title' => esc_html__( 'WordPress', 'elementor' ),
344 'icon' => 'eicon-wordpress',
345 'active' => false,
346 ];
347 }
348
349 /**
350 * Require files.
351 *
352 * Require Elementor element base class and column, section and repeater
353 * elements.
354 *
355 * @since 1.0.0
356 * @access private
357 */
358 private function require_files() {
359 require_once ELEMENTOR_PATH . 'includes/base/element-base.php';
360
361 require ELEMENTOR_PATH . 'includes/elements/column.php';
362 require ELEMENTOR_PATH . 'includes/elements/section.php';
363 require ELEMENTOR_PATH . 'includes/elements/repeater.php';
364 }
365 }
366