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

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