PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.2
Elementor Website Builder – more than just a page builder v3.5.2
4.3.1 4.3.0 4.3.0-beta3 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 All 454 releases
← All changes | includes/managers/widgets.php +63 -259 4.3.0-beta23.5.2 View file →
@@ -1,18 +1,9 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 4 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
5 -use Elementor\Core\Utils\Collection;
6 -use Elementor\Core\Utils\Force_Locale;
7 -use Elementor\Modules\AtomicWidgets\Elements\Atomic_Button\Atomic_Button;
8 -use Elementor\Modules\AtomicWidgets\Elements\Atomic_Divider\Atomic_Divider;
9 -use Elementor\Modules\AtomicWidgets\Elements\Atomic_Heading\Atomic_Heading;
10 -use Elementor\Modules\AtomicWidgets\Elements\Atomic_Image\Atomic_Image;
11 -use Elementor\Modules\AtomicWidgets\Elements\Atomic_Paragraph\Atomic_Paragraph;
12 -use Elementor\Modules\AtomicWidgets\Elements\Atomic_Svg\Atomic_Svg;
13 -use Elementor\Modules\NestedAccordion\Widgets\Nested_Accordion;
14 -use Elementor\Modules\NestedTabs\Widgets\NestedTabs;
5 +use Elementor\Core\Utils\Exceptions;
15 6
16 7 if ( ! defined( 'ABSPATH' ) ) {
17 8 exit; // Exit if accessed directly.
18 9 }
@@ -39,48 +30,19 @@
39 30 */
40 31 private $_widget_types = null;
41 32
42 33 /**
43 - * Promoted widget types.
44 - *
45 - * Holds the list of all the Promoted widget types.
46 - *
47 - * @since 3.15.0
48 - * @access private
49 - *
50 - * @var Widget_Base[]
51 - *
52 - * @return array
53 - */
54 - private array $promoted_widgets = [
55 - 'container' => [
56 - NestedTabs::class,
57 - Nested_Accordion::class,
58 - ],
59 - 'atomic_widgets' => [
60 - Atomic_Heading::class,
61 - Atomic_Image::class,
62 - Atomic_Paragraph::class,
63 - Atomic_Button::class,
64 - Atomic_Svg::class,
65 - Atomic_Divider::class,
66 - ],
67 - ];
68 -
69 - /**
70 34 * Init widgets.
71 35 *
72 - * Initialize Elementor widgets manager. Include all the widgets files
36 + * Initialize Elementor widgets manager. Include all the the widgets files
73 37 * and register each Elementor and WordPress widget.
74 38 *
75 39 * @since 2.0.0
76 40 * @access private
77 - */
41 + */
78 42 private function init_widgets() {
79 43 $build_widgets_filename = [
80 - 'common-base',
81 44 'common',
82 - 'common-optimized',
83 45 'inner-section',
84 46 'heading',
85 47 'image',
86 48 'text-editor',
@@ -109,17 +71,14 @@
109 71 'html',
110 72 'menu-anchor',
111 73 'sidebar',
112 74 'read-more',
113 - 'rating',
114 75 ];
115 76
116 77 $this->_widget_types = [];
117 78
118 - $this->register_promoted_widgets();
119 -
120 79 foreach ( $build_widgets_filename as $widget_filename ) {
121 - include ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php';
80 + include( ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php' );
122 81
123 82 $class_name = str_replace( '-', '_', $widget_filename );
124 83
125 84 $class_name = __NAMESPACE__ . '\Widget_' . $class_name;
@@ -138,15 +97,18 @@
138 97 * @deprecated 3.5.0 Use `elementor/widgets/register` hook instead.
139 98 *
140 99 * @param Widgets_Manager $this The widgets manager.
141 100 */
142 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->do_deprecated_action(
143 - 'elementor/widgets/widgets_registered',
144 - [ $this ],
145 - '3.5.0',
146 - 'elementor/widgets/register'
147 - );
101 + // TODO: Uncomment when Pro uses the new hook.
102 + //Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->do_deprecated_action(
103 + // 'elementor/widgets/widgets_registered',
104 + // [ $this ],
105 + // '3.5.0',
106 + // 'elementor/widgets/register'
107 + //);
148 108
109 + do_action( 'elementor/widgets/widgets_registered', $this );
110 +
149 111 /**
150 112 * After widgets registered.
151 113 *
152 114 * Fires after Elementor widgets are registered.
@@ -167,12 +129,27 @@
167 129 * plugin authors can filter the black list.
168 130 *
169 131 * @since 2.0.0
170 132 * @access private
171 - */
133 + */
172 134 private function register_wp_widgets() {
173 135 global $wp_widget_factory;
174 136
137 + // Skip Pojo widgets.
138 + $pojo_allowed_widgets = [
139 + 'Pojo_Widget_Recent_Posts',
140 + 'Pojo_Widget_Posts_Group',
141 + 'Pojo_Widget_Gallery',
142 + 'Pojo_Widget_Recent_Galleries',
143 + 'Pojo_Slideshow_Widget',
144 + 'Pojo_Forms_Widget',
145 + 'Pojo_Widget_News_Ticker',
146 +
147 + 'Pojo_Widget_WC_Products',
148 + 'Pojo_Widget_WC_Products_Category',
149 + 'Pojo_Widget_WC_Product_Categories',
150 + ];
151 +
175 152 // Allow themes/plugins to filter out their widgets.
176 153 $black_list = [];
177 154
178 155 /**
@@ -191,8 +168,12 @@
191 168 if ( in_array( $widget_class, $black_list ) ) {
192 169 continue;
193 170 }
194 171
172 + if ( $widget_obj instanceof \Pojo_Widget_Base && ! in_array( $widget_class, $pojo_allowed_widgets ) ) {
173 + continue;
174 + }
175 +
195 176 $elementor_widget_class = __NAMESPACE__ . '\Widget_WordPress';
196 177
197 178 $this->register(
198 179 new $elementor_widget_class( [], [
@@ -208,24 +189,13 @@
208 189 * Require Elementor widget base class.
209 190 *
210 191 * @since 2.0.0
211 192 * @access private
212 - */
193 + */
213 194 private function require_files() {
214 195 require ELEMENTOR_PATH . 'includes/base/widget-base.php';
215 196 }
216 197
217 - private function pluck_default_controls( $controls ) {
218 - return ( new Collection( $controls ) )
219 - ->reduce( function ( $controls_defaults, $control, $control_key ) {
220 - if ( ! empty( $control['default'] ) ) {
221 - $controls_defaults[ $control_key ]['default'] = $control['default'];
222 - }
223 -
224 - return $controls_defaults;
225 - }, [] );
226 - }
227 -
228 198 /**
229 199 * Register widget type.
230 200 *
231 201 * Add a new widget type to the list of registered widget types.
@@ -231,20 +201,21 @@
231 201 * Add a new widget type to the list of registered widget types.
232 202 *
233 203 * @since 1.0.0
234 204 * @access public
235 - * @deprecated 3.5.0 Use `register()` method instead.
205 + * @deprecated 3.5.0 Use `$this->register()` instead.
236 206 *
237 207 * @param Widget_Base $widget Elementor widget.
238 208 *
239 209 * @return true True if the widget was registered.
240 - */
210 + */
241 211 public function register_widget_type( Widget_Base $widget ) {
242 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
243 - __METHOD__,
244 - '3.5.0',
245 - 'register()'
246 - );
212 + // TODO: Uncomment when Pro uses the new hook.
213 + //Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
214 + // __METHOD__,
215 + // '3.5.0',
216 + // 'register'
217 + //);
247 218
248 219 return $this->register( $widget );
249 220 }
250 221
@@ -252,11 +223,12 @@
252 223 * Register a new widget type.
253 224 *
254 225 * @param \Elementor\Widget_Base $widget_instance Elementor Widget.
255 226 *
256 - * @return bool True if the widget was registered.
227 + * @return true True if the widget was registered.
257 228 * @since 3.5.0
258 229 * @access public
230 + *
259 231 */
260 232 public function register( Widget_Base $widget_instance ) {
261 233 if ( is_null( $this->_widget_types ) ) {
262 234 $this->init_widgets();
@@ -261,41 +233,13 @@
261 233 if ( is_null( $this->_widget_types ) ) {
262 234 $this->init_widgets();
263 235 }
264 236
265 - /**
266 - * Should widget be registered.
267 - *
268 - * @since 3.18.0
269 - *
270 - * @param bool $should_register Should widget be registered. Default is `true`.
271 - * @param \Elementor\Widget_Base $widget_instance Widget instance.
272 - */
273 - $should_register = apply_filters( 'elementor/widgets/is_widget_enabled', true, $widget_instance );
274 -
275 - if ( ! $should_register ) {
276 - return false;
277 - }
278 -
279 237 $this->_widget_types[ $widget_instance->get_name() ] = $widget_instance;
280 238
281 239 return true;
282 240 }
283 241
284 - /** Register promoted widgets
285 - *
286 - * Since we cannot allow widgets to place themselves is a specific
287 - * location on our widgets panel we need to use a hard coded solution for this.
288 - *
289 - * @return void
290 - */
291 - private function register_promoted_widgets() {
292 -
293 - foreach ( $this->promoted_widgets as $experiment_name => $classes ) {
294 - $this->register_promoted_active_widgets( $experiment_name, $classes );
295 - }
296 - }
297 -
298 242 /**
299 243 * Unregister widget type.
300 244 *
301 245 * Removes widget type from the list of registered widget types.
@@ -301,20 +245,21 @@
301 245 * Removes widget type from the list of registered widget types.
302 246 *
303 247 * @since 1.0.0
304 248 * @access public
305 - * @deprecated 3.5.0 Use `unregister()` method instead.
249 + * @deprecated 3.5.0 Use `$this->unregister()` instead.
306 250 *
307 251 * @param string $name Widget name.
308 252 *
309 253 * @return true True if the widget was unregistered, False otherwise.
310 - */
254 + */
311 255 public function unregister_widget_type( $name ) {
312 - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
313 - __METHOD__,
314 - '3.5.0',
315 - 'unregister()'
316 - );
256 + // TODO: Uncomment when Pro uses the new hook.
257 + //Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
258 + // __METHOD__,
259 + // '3.5.0',
260 + // 'unregister'
261 + //);
317 262
318 263 return $this->unregister( $name );
319 264 }
320 265
@@ -350,9 +295,9 @@
350 295 *
351 296 * @param string $widget_name Optional. Widget name. Default is null.
352 297 *
353 298 * @return Widget_Base|Widget_Base[]|null Registered widget types.
354 - */
299 + */
355 300 public function get_widget_types( $widget_name = null ) {
356 301 if ( is_null( $this->_widget_types ) ) {
357 302 $this->init_widgets();
358 303 }
@@ -372,9 +317,9 @@
372 317 * @since 1.0.0
373 318 * @access public
374 319 *
375 320 * @return array Registered widget types with each widget config.
376 - */
321 + */
377 322 public function get_widget_types_config() {
378 323 $config = [];
379 324
380 325 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
@@ -383,16 +328,9 @@
383 328
384 329 return $config;
385 330 }
386 331
387 - /**
388 - * @throws \Exception If current user don't have permissions to edit the post.
389 - */
390 332 public function ajax_get_widget_types_controls_config( array $data ) {
391 - Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
392 -
393 - wp_raise_memory_limit( 'admin' );
394 -
395 333 $config = [];
396 334
397 335 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
398 336 if ( isset( $data['exclude'][ $widget_key ] ) ) {
@@ -408,61 +346,8 @@
408 346 return $config;
409 347 }
410 348
411 349 /**
412 - * @throws \Exception If current user don't have permissions to edit the post.
413 - */
414 - public function ajax_refresh_widgets_config( array $data ) {
415 - Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
416 -
417 - wp_raise_memory_limit( 'admin' );
418 -
419 - $widgets = [];
420 -
421 - foreach ( $this->get_widget_types() as $widget_key => $widget ) {
422 - $widget_config = $widget->get_config();
423 -
424 - // get_config() omits controls when the stack isn't initialized yet (see Widget_Base::get_initial_config).
425 - // During an AJAX refresh the instances are fresh, so we force-initialize and merge them explicitly.
426 - $widget_config['controls'] = $widget->get_stack( false )['controls'];
427 - $widget_config['tabs_controls'] = $widget->get_tabs_controls();
428 -
429 - $widgets[ $widget_key ] = $widget_config;
430 - }
431 -
432 - return [
433 - 'widgets' => $widgets,
434 - 'categories' => Plugin::$instance->elements_manager->get_categories(),
435 - ];
436 - }
437 -
438 - public function ajax_get_widgets_default_value_translations( array $data = [] ) {
439 - $locale = empty( $data['locale'] )
440 - ? get_locale()
441 - : $data['locale'];
442 -
443 - $force_locale = new Force_Locale( $locale );
444 - $force_locale->force();
445 -
446 - $controls = ( new Collection( $this->get_widget_types() ) )
447 - ->map( function ( Widget_Base $widget ) {
448 - $controls = $widget->get_stack( false )['controls'];
449 -
450 - return [
451 - 'controls' => $this->pluck_default_controls( $controls ),
452 - ];
453 - } )
454 - ->filter( function ( $widget ) {
455 - return ! empty( $widget['controls'] );
456 - } )
457 - ->all();
458 -
459 - $force_locale->restore();
460 -
461 - return $controls;
462 - }
463 -
464 - /**
465 350 * Ajax render widget.
466 351 *
467 352 * Ajax handler for Elementor render_widget.
468 353 *
@@ -481,10 +366,14 @@
481 366 * @type string $render The rendered HTML.
482 367 * }
483 368 */
484 369 public function ajax_render_widget( $request ) {
485 - $document = Plugin::$instance->documents->get_with_permissions( $request['editor_post_id'] );
370 + $document = Plugin::$instance->documents->get( $request['editor_post_id'] );
486 371
372 + if ( ! $document->is_editable_by_current_user() ) {
373 + throw new \Exception( 'Access denied.', Exceptions::FORBIDDEN );
374 + }
375 +
487 376 // Override the global $post for the render.
488 377 query_posts(
489 378 [
490 379 'p' => $request['editor_post_id'],
@@ -519,13 +408,10 @@
519 408 *
520 409 * @param array $request Ajax request.
521 410 *
522 411 * @return bool|string Rendered widget form.
523 - * @throws \Exception If current user don't have permissions to edit the post.
524 412 */
525 413 public function ajax_get_wp_widget_form( $request ) {
526 - Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );
527 -
528 414 if ( empty( $request['widget_type'] ) ) {
529 415 return false;
530 416 }
531 417
@@ -559,9 +445,9 @@
559 445 * template, for all the registered widget types.
560 446 *
561 447 * @since 1.0.0
562 448 * @access public
563 - */
449 + */
564 450 public function render_widgets_content() {
565 451 foreach ( $this->get_widget_types() as $widget ) {
566 452 $widget->print_template();
567 453 }
@@ -576,9 +462,9 @@
576 462 * @since 1.3.0
577 463 * @access public
578 464 *
579 465 * @return array Registered widget types with settings keys for each widget.
580 - */
466 + */
581 467 public function get_widgets_frontend_settings_keys() {
582 468 $keys = [];
583 469
584 470 foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) {
@@ -592,63 +478,8 @@
592 478 return $keys;
593 479 }
594 480
595 481 /**
596 - * Widgets with styles.
597 - *
598 - * This method returns the list of all the widgets in the `/includes/`
599 - * folder that have styles.
600 - *
601 - * @since 3.24.0
602 - * @access public
603 - *
604 - * @return array The names of the widgets that have styles.
605 - */
606 - public function widgets_with_styles(): array {
607 - return [
608 - 'counter',
609 - 'divider',
610 - 'google_maps',
611 - 'heading',
612 - 'image',
613 - 'image-carousel',
614 - 'menu-anchor',
615 - 'rating',
616 - 'social-icons',
617 - 'spacer',
618 - 'testimonial',
619 - 'text-editor',
620 - 'video',
621 - ];
622 - }
623 -
624 - /**
625 - * Widgets with responsive styles.
626 - *
627 - * This method returns the list of all the widgets in the `/includes/`
628 - * folder that have responsive styles.
629 - *
630 - * @since 3.24.0
631 - * @access public
632 - *
633 - * @return array The names of the widgets that have responsive styles.
634 - */
635 - public function widgets_with_responsive_styles(): array {
636 - return [
637 - 'accordion',
638 - 'alert',
639 - 'icon-box',
640 - 'icon-list',
641 - 'image-box',
642 - 'image-gallery',
643 - 'progress',
644 - 'star-rating',
645 - 'tabs',
646 - 'toggle',
647 - ];
648 - }
649 -
650 - /**
651 482 * Enqueue widgets scripts.
652 483 *
653 484 * Enqueue all the scripts defined as a dependency for each widget.
654 485 *
@@ -653,9 +484,9 @@
653 484 * Enqueue all the scripts defined as a dependency for each widget.
654 485 *
655 486 * @since 1.3.0
656 487 * @access public
657 - */
488 + */
658 489 public function enqueue_widgets_scripts() {
659 490 foreach ( $this->get_widget_types() as $widget ) {
660 491 $widget->enqueue_scripts();
661 492 }
@@ -660,14 +491,8 @@
660 491 $widget->enqueue_scripts();
661 492 }
662 493 }
663 494
664 - public function register_frontend_handlers() {
665 - foreach ( $this->get_widget_types() as $widget ) {
666 - $widget->register_frontend_handlers();
667 - }
668 - }
669 -
670 495 /**
671 496 * Enqueue widgets styles
672 497 *
673 498 * Enqueue all the styles defined as a dependency for each widget
@@ -742,9 +567,9 @@
742 567 * Initializing Elementor widgets manager.
743 568 *
744 569 * @since 1.0.0
745 570 * @access public
746 - */
571 + */
747 572 public function __construct() {
748 573 $this->require_files();
749 574
750 575 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
@@ -763,27 +588,6 @@
763 588 public function register_ajax_actions( Ajax $ajax_manager ) {
764 589 $ajax_manager->register_ajax_action( 'render_widget', [ $this, 'ajax_render_widget' ] );
765 590 $ajax_manager->register_ajax_action( 'editor_get_wp_widget_form', [ $this, 'ajax_get_wp_widget_form' ] );
766 591 $ajax_manager->register_ajax_action( 'get_widgets_config', [ $this, 'ajax_get_widget_types_controls_config' ] );
767 -
768 - $ajax_manager->register_ajax_action( 'refresh_widgets_config', [ $this, 'ajax_refresh_widgets_config' ] );
769 -
770 - $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) {
771 - return $this->ajax_get_widgets_default_value_translations( $data );
772 - } );
773 - }
774 -
775 - /**
776 - * @param string $experiment_name
777 - * @param array $classes
778 - * @return void
779 - */
780 - public function register_promoted_active_widgets( string $experiment_name, array $classes ): void {
781 - if ( ! Plugin::$instance->experiments->is_feature_active( $experiment_name ) || empty( $classes ) ) {
782 - return;
783 - }
784 -
785 - foreach ( $classes as $class_name ) {
786 - $this->register( new $class_name() );
787 - }
788 592 }
789 593 }