PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.2
Elementor Website Builder – more than just a page builder v3.19.2
4.3.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 All 455 releases
← All changes | includes/managers/widgets.php +26 -146 4.3.1 → 3.19.2 View file →
@@ -2,15 +2,10 @@
2 2 namespace Elementor;
3 3
4 4 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
5 5 use Elementor\Core\Utils\Collection;
6 +use Elementor\Core\Utils\Exceptions;
6 7 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 8 use Elementor\Modules\NestedAccordion\Widgets\Nested_Accordion;
14 9 use Elementor\Modules\NestedTabs\Widgets\NestedTabs;
15 10
16 11 if ( ! defined( 'ABSPATH' ) ) {
@@ -47,40 +42,26 @@
47 42 * @since 3.15.0
48 43 * @access private
49 44 *
50 45 * @var Widget_Base[]
51 - *
52 - * @return array
53 46 */
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 - ],
47 + private $_promoted_widgets = [
48 + 'nested-elements' => NestedTabs::class,
49 + 'nested-accordion' => Nested_Accordion::class,
67 50 ];
68 51
69 52 /**
70 53 * Init widgets.
71 54 *
72 - * Initialize Elementor widgets manager. Include all the widgets files
55 + * Initialize Elementor widgets manager. Include all the the widgets files
73 56 * and register each Elementor and WordPress widget.
74 57 *
75 58 * @since 2.0.0
76 59 * @access private
77 - */
60 + */
78 61 private function init_widgets() {
79 62 $build_widgets_filename = [
80 - 'common-base',
81 63 'common',
82 - 'common-optimized',
83 64 'inner-section',
84 65 'heading',
85 66 'image',
86 67 'text-editor',
@@ -114,10 +95,8 @@
114 95 ];
115 96
116 97 $this->_widget_types = [];
117 98
118 - $this->register_promoted_widgets();
119 -
120 99 foreach ( $build_widgets_filename as $widget_filename ) {
121 100 include ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php';
122 101
123 102 $class_name = str_replace( '-', '_', $widget_filename );
@@ -126,8 +105,10 @@
126 105
127 106 $this->register( new $class_name() );
128 107 }
129 108
109 + $this->register_promoted_widgets();
110 +
130 111 $this->register_wp_widgets();
131 112
132 113 /**
133 114 * After widgets registered.
@@ -167,9 +148,9 @@
167 148 * plugin authors can filter the black list.
168 149 *
169 150 * @since 2.0.0
170 151 * @access private
171 - */
152 + */
172 153 private function register_wp_widgets() {
173 154 global $wp_widget_factory;
174 155
175 156 // Allow themes/plugins to filter out their widgets.
@@ -208,9 +189,9 @@
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
@@ -236,9 +217,9 @@
236 217 *
237 218 * @param Widget_Base $widget Elementor widget.
238 219 *
239 220 * @return true True if the widget was registered.
240 - */
221 + */
241 222 public function register_widget_type( Widget_Base $widget ) {
242 223 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
243 224 __METHOD__,
244 225 '3.5.0',
@@ -289,10 +270,14 @@
289 270 * @return void
290 271 */
291 272 private function register_promoted_widgets() {
292 273
293 - foreach ( $this->promoted_widgets as $experiment_name => $classes ) {
294 - $this->register_promoted_active_widgets( $experiment_name, $classes );
274 + foreach ( $this->_promoted_widgets as $module_name => $class_name ) {
275 +
276 + if ( Plugin::$instance->experiments->is_feature_active( $module_name ) ) {
277 + $instance = new $class_name();
278 + $this->_widget_types[ $instance->get_name() ] = $instance;
279 + }
295 280 }
296 281 }
297 282
298 283 /**
@@ -306,9 +291,9 @@
306 291 *
307 292 * @param string $name Widget name.
308 293 *
309 294 * @return true True if the widget was unregistered, False otherwise.
310 - */
295 + */
311 296 public function unregister_widget_type( $name ) {
312 297 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
313 298 __METHOD__,
314 299 '3.5.0',
@@ -350,9 +335,9 @@
350 335 *
351 336 * @param string $widget_name Optional. Widget name. Default is null.
352 337 *
353 338 * @return Widget_Base|Widget_Base[]|null Registered widget types.
354 - */
339 + */
355 340 public function get_widget_types( $widget_name = null ) {
356 341 if ( is_null( $this->_widget_types ) ) {
357 342 $this->init_widgets();
358 343 }
@@ -372,9 +357,9 @@
372 357 * @since 1.0.0
373 358 * @access public
374 359 *
375 360 * @return array Registered widget types with each widget config.
376 - */
361 + */
377 362 public function get_widget_types_config() {
378 363 $config = [];
379 364
380 365 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
@@ -384,9 +369,9 @@
384 369 return $config;
385 370 }
386 371
387 372 /**
388 - * @throws \Exception If current user don't have permissions to edit the post.
373 + * @throws \Exception
389 374 */
390 375 public function ajax_get_widget_types_controls_config( array $data ) {
391 376 Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
392 377
@@ -407,35 +392,8 @@
407 392
408 393 return $config;
409 394 }
410 395
411 - /**
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 396 public function ajax_get_widgets_default_value_translations( array $data = [] ) {
439 397 $locale = empty( $data['locale'] )
440 398 ? get_locale()
441 399 : $data['locale'];
@@ -519,9 +477,9 @@
519 477 *
520 478 * @param array $request Ajax request.
521 479 *
522 480 * @return bool|string Rendered widget form.
523 - * @throws \Exception If current user don't have permissions to edit the post.
481 + * @throws \Exception
524 482 */
525 483 public function ajax_get_wp_widget_form( $request ) {
526 484 Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );
527 485
@@ -559,9 +517,9 @@
559 517 * template, for all the registered widget types.
560 518 *
561 519 * @since 1.0.0
562 520 * @access public
563 - */
521 + */
564 522 public function render_widgets_content() {
565 523 foreach ( $this->get_widget_types() as $widget ) {
566 524 $widget->print_template();
567 525 }
@@ -576,9 +534,9 @@
576 534 * @since 1.3.0
577 535 * @access public
578 536 *
579 537 * @return array Registered widget types with settings keys for each widget.
580 - */
538 + */
581 539 public function get_widgets_frontend_settings_keys() {
582 540 $keys = [];
583 541
584 542 foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) {
@@ -592,63 +550,8 @@
592 550 return $keys;
593 551 }
594 552
595 553 /**
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 554 * Enqueue widgets scripts.
652 555 *
653 556 * Enqueue all the scripts defined as a dependency for each widget.
654 557 *
@@ -653,9 +556,9 @@
653 556 * Enqueue all the scripts defined as a dependency for each widget.
654 557 *
655 558 * @since 1.3.0
656 559 * @access public
657 - */
560 + */
658 561 public function enqueue_widgets_scripts() {
659 562 foreach ( $this->get_widget_types() as $widget ) {
660 563 $widget->enqueue_scripts();
661 564 }
@@ -660,14 +563,8 @@
660 563 $widget->enqueue_scripts();
661 564 }
662 565 }
663 566
664 - public function register_frontend_handlers() {
665 - foreach ( $this->get_widget_types() as $widget ) {
666 - $widget->register_frontend_handlers();
667 - }
668 - }
669 -
670 567 /**
671 568 * Enqueue widgets styles
672 569 *
673 570 * Enqueue all the styles defined as a dependency for each widget
@@ -742,9 +639,9 @@
742 639 * Initializing Elementor widgets manager.
743 640 *
744 641 * @since 1.0.0
745 642 * @access public
746 - */
643 + */
747 644 public function __construct() {
748 645 $this->require_files();
749 646
750 647 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
@@ -764,26 +661,9 @@
764 661 $ajax_manager->register_ajax_action( 'render_widget', [ $this, 'ajax_render_widget' ] );
765 662 $ajax_manager->register_ajax_action( 'editor_get_wp_widget_form', [ $this, 'ajax_get_wp_widget_form' ] );
766 663 $ajax_manager->register_ajax_action( 'get_widgets_config', [ $this, 'ajax_get_widget_types_controls_config' ] );
767 664
768 - $ajax_manager->register_ajax_action( 'refresh_widgets_config', [ $this, 'ajax_refresh_widgets_config' ] );
769 -
770 665 $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) {
771 666 return $this->ajax_get_widgets_default_value_translations( $data );
772 667 } );
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 668 }
789 669 }