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

350 lines 7.9 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
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 /**
254 * After elements registered.
255 *
256 * Fires after Elementor elements are registered.
257 *
258 * @since 1.0.0
259 */
260 do_action( 'elementor/elements/elements_registered', $this );
261 }
262
263 /**
264 * Init categories.
265 *
266 * Initialize the element categories.
267 *
268 * @since 1.7.12
269 * @access private
270 */
271 private function init_categories() {
272 $this->categories = [
273 'basic' => [
274 'title' => esc_html__( 'Basic', 'elementor' ),
275 'icon' => 'eicon-font',
276 ],
277 'pro-elements' => [
278 'title' => esc_html__( 'Pro', 'elementor' ),
279 ],
280 'general' => [
281 'title' => esc_html__( 'General', 'elementor' ),
282 'icon' => 'eicon-font',
283 ],
284 'theme-elements' => [
285 'title' => esc_html__( 'Site', 'elementor' ),
286 'active' => false,
287 ],
288 'woocommerce-elements' => [
289 'title' => esc_html__( 'WooCommerce', 'elementor' ),
290 'active' => false,
291 ],
292 ];
293
294 // Not using the `add_category` because it doesn't allow 3rd party to inject a category on top the others.
295 if ( Plugin::instance()->experiments->is_feature_active( 'favorite-widgets' ) ) {
296 $this->categories = array_merge_recursive( [
297 'favorites' => [
298 'title' => esc_html__( 'Favorites', 'elementor' ),
299 'icon' => 'eicon-heart',
300 'sort' => 'a-z',
301 'hideIfEmpty' => false,
302 ],
303 ], $this->categories );
304 }
305
306 /**
307 * When categories are registered.
308 *
309 * Fires after basic categories are registered, before WordPress
310 * category have been registered.
311 *
312 * This is where categories registered by external developers are
313 * added.
314 *
315 * @since 2.0.0
316 *
317 * @param Elements_Manager $this Elements manager instance.
318 */
319 do_action( 'elementor/elements/categories_registered', $this );
320
321 $this->categories['pojo'] = [
322 'title' => esc_html__( 'Pojo Themes', 'elementor' ),
323 'icon' => 'eicon-pojome',
324 ];
325
326 $this->categories['wordpress'] = [
327 'title' => esc_html__( 'WordPress', 'elementor' ),
328 'icon' => 'eicon-wordpress',
329 'active' => false,
330 ];
331 }
332
333 /**
334 * Require files.
335 *
336 * Require Elementor element base class and column, section and repeater
337 * elements.
338 *
339 * @since 1.0.0
340 * @access private
341 */
342 private function require_files() {
343 require_once ELEMENTOR_PATH . 'includes/base/element-base.php';
344
345 require ELEMENTOR_PATH . 'includes/elements/column.php';
346 require ELEMENTOR_PATH . 'includes/elements/section.php';
347 require ELEMENTOR_PATH . 'includes/elements/repeater.php';
348 }
349 }
350