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.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
← All changes | includes/managers/widgets.php +26 -147 4.1.43.19.2 View file →
@@ -2,17 +2,11 @@
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 -use Elementor\Modules\NestedElements\Module as NestedElementsModule;
15 9 use Elementor\Modules\NestedTabs\Widgets\NestedTabs;
16 10
17 11 if ( ! defined( 'ABSPATH' ) ) {
18 12 exit; // Exit if accessed directly.
@@ -48,40 +42,26 @@
48 42 * @since 3.15.0
49 43 * @access private
50 44 *
51 45 * @var Widget_Base[]
52 - *
53 - * @return array
54 46 */
55 - private array $promoted_widgets = [
56 - NestedElementsModule::EXPERIMENT_NAME => [
57 - NestedTabs::class,
58 - Nested_Accordion::class,
59 - ],
60 - 'atomic_widgets' => [
61 - Atomic_Heading::class,
62 - Atomic_Image::class,
63 - Atomic_Paragraph::class,
64 - Atomic_Button::class,
65 - Atomic_Svg::class,
66 - Atomic_Divider::class,
67 - ],
47 + private $_promoted_widgets = [
48 + 'nested-elements' => NestedTabs::class,
49 + 'nested-accordion' => Nested_Accordion::class,
68 50 ];
69 51
70 52 /**
71 53 * Init widgets.
72 54 *
73 - * Initialize Elementor widgets manager. Include all the widgets files
55 + * Initialize Elementor widgets manager. Include all the the widgets files
74 56 * and register each Elementor and WordPress widget.
75 57 *
76 58 * @since 2.0.0
77 59 * @access private
78 - */
60 + */
79 61 private function init_widgets() {
80 62 $build_widgets_filename = [
81 - 'common-base',
82 63 'common',
83 - 'common-optimized',
84 64 'inner-section',
85 65 'heading',
86 66 'image',
87 67 'text-editor',
@@ -115,10 +95,8 @@
115 95 ];
116 96
117 97 $this->_widget_types = [];
118 98
119 - $this->register_promoted_widgets();
120 -
121 99 foreach ( $build_widgets_filename as $widget_filename ) {
122 100 include ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php';
123 101
124 102 $class_name = str_replace( '-', '_', $widget_filename );
@@ -127,8 +105,10 @@
127 105
128 106 $this->register( new $class_name() );
129 107 }
130 108
109 + $this->register_promoted_widgets();
110 +
131 111 $this->register_wp_widgets();
132 112
133 113 /**
134 114 * After widgets registered.
@@ -168,9 +148,9 @@
168 148 * plugin authors can filter the black list.
169 149 *
170 150 * @since 2.0.0
171 151 * @access private
172 - */
152 + */
173 153 private function register_wp_widgets() {
174 154 global $wp_widget_factory;
175 155
176 156 // Allow themes/plugins to filter out their widgets.
@@ -209,9 +189,9 @@
209 189 * Require Elementor widget base class.
210 190 *
211 191 * @since 2.0.0
212 192 * @access private
213 - */
193 + */
214 194 private function require_files() {
215 195 require ELEMENTOR_PATH . 'includes/base/widget-base.php';
216 196 }
217 197
@@ -237,9 +217,9 @@
237 217 *
238 218 * @param Widget_Base $widget Elementor widget.
239 219 *
240 220 * @return true True if the widget was registered.
241 - */
221 + */
242 222 public function register_widget_type( Widget_Base $widget ) {
243 223 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
244 224 __METHOD__,
245 225 '3.5.0',
@@ -290,10 +270,14 @@
290 270 * @return void
291 271 */
292 272 private function register_promoted_widgets() {
293 273
294 - foreach ( $this->promoted_widgets as $experiment_name => $classes ) {
295 - $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 + }
296 280 }
297 281 }
298 282
299 283 /**
@@ -307,9 +291,9 @@
307 291 *
308 292 * @param string $name Widget name.
309 293 *
310 294 * @return true True if the widget was unregistered, False otherwise.
311 - */
295 + */
312 296 public function unregister_widget_type( $name ) {
313 297 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
314 298 __METHOD__,
315 299 '3.5.0',
@@ -351,9 +335,9 @@
351 335 *
352 336 * @param string $widget_name Optional. Widget name. Default is null.
353 337 *
354 338 * @return Widget_Base|Widget_Base[]|null Registered widget types.
355 - */
339 + */
356 340 public function get_widget_types( $widget_name = null ) {
357 341 if ( is_null( $this->_widget_types ) ) {
358 342 $this->init_widgets();
359 343 }
@@ -373,9 +357,9 @@
373 357 * @since 1.0.0
374 358 * @access public
375 359 *
376 360 * @return array Registered widget types with each widget config.
377 - */
361 + */
378 362 public function get_widget_types_config() {
379 363 $config = [];
380 364
381 365 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
@@ -385,9 +369,9 @@
385 369 return $config;
386 370 }
387 371
388 372 /**
389 - * @throws \Exception If current user don't have permissions to edit the post.
373 + * @throws \Exception
390 374 */
391 375 public function ajax_get_widget_types_controls_config( array $data ) {
392 376 Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
393 377
@@ -408,35 +392,8 @@
408 392
409 393 return $config;
410 394 }
411 395
412 - /**
413 - * @throws \Exception If current user don't have permissions to edit the post.
414 - */
415 - public function ajax_refresh_widgets_config( array $data ) {
416 - Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
417 -
418 - wp_raise_memory_limit( 'admin' );
419 -
420 - $widgets = [];
421 -
422 - foreach ( $this->get_widget_types() as $widget_key => $widget ) {
423 - $widget_config = $widget->get_config();
424 -
425 - // get_config() omits controls when the stack isn't initialized yet (see Widget_Base::get_initial_config).
426 - // During an AJAX refresh the instances are fresh, so we force-initialize and merge them explicitly.
427 - $widget_config['controls'] = $widget->get_stack( false )['controls'];
428 - $widget_config['tabs_controls'] = $widget->get_tabs_controls();
429 -
430 - $widgets[ $widget_key ] = $widget_config;
431 - }
432 -
433 - return [
434 - 'widgets' => $widgets,
435 - 'categories' => Plugin::$instance->elements_manager->get_categories(),
436 - ];
437 - }
438 -
439 396 public function ajax_get_widgets_default_value_translations( array $data = [] ) {
440 397 $locale = empty( $data['locale'] )
441 398 ? get_locale()
442 399 : $data['locale'];
@@ -520,9 +477,9 @@
520 477 *
521 478 * @param array $request Ajax request.
522 479 *
523 480 * @return bool|string Rendered widget form.
524 - * @throws \Exception If current user don't have permissions to edit the post.
481 + * @throws \Exception
525 482 */
526 483 public function ajax_get_wp_widget_form( $request ) {
527 484 Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );
528 485
@@ -560,9 +517,9 @@
560 517 * template, for all the registered widget types.
561 518 *
562 519 * @since 1.0.0
563 520 * @access public
564 - */
521 + */
565 522 public function render_widgets_content() {
566 523 foreach ( $this->get_widget_types() as $widget ) {
567 524 $widget->print_template();
568 525 }
@@ -577,9 +534,9 @@
577 534 * @since 1.3.0
578 535 * @access public
579 536 *
580 537 * @return array Registered widget types with settings keys for each widget.
581 - */
538 + */
582 539 public function get_widgets_frontend_settings_keys() {
583 540 $keys = [];
584 541
585 542 foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) {
@@ -593,63 +550,8 @@
593 550 return $keys;
594 551 }
595 552
596 553 /**
597 - * Widgets with styles.
598 - *
599 - * This method returns the list of all the widgets in the `/includes/`
600 - * folder that have styles.
601 - *
602 - * @since 3.24.0
603 - * @access public
604 - *
605 - * @return array The names of the widgets that have styles.
606 - */
607 - public function widgets_with_styles(): array {
608 - return [
609 - 'counter',
610 - 'divider',
611 - 'google_maps',
612 - 'heading',
613 - 'image',
614 - 'image-carousel',
615 - 'menu-anchor',
616 - 'rating',
617 - 'social-icons',
618 - 'spacer',
619 - 'testimonial',
620 - 'text-editor',
621 - 'video',
622 - ];
623 - }
624 -
625 - /**
626 - * Widgets with responsive styles.
627 - *
628 - * This method returns the list of all the widgets in the `/includes/`
629 - * folder that have responsive styles.
630 - *
631 - * @since 3.24.0
632 - * @access public
633 - *
634 - * @return array The names of the widgets that have responsive styles.
635 - */
636 - public function widgets_with_responsive_styles(): array {
637 - return [
638 - 'accordion',
639 - 'alert',
640 - 'icon-box',
641 - 'icon-list',
642 - 'image-box',
643 - 'image-gallery',
644 - 'progress',
645 - 'star-rating',
646 - 'tabs',
647 - 'toggle',
648 - ];
649 - }
650 -
651 - /**
652 554 * Enqueue widgets scripts.
653 555 *
654 556 * Enqueue all the scripts defined as a dependency for each widget.
655 557 *
@@ -654,9 +556,9 @@
654 556 * Enqueue all the scripts defined as a dependency for each widget.
655 557 *
656 558 * @since 1.3.0
657 559 * @access public
658 - */
560 + */
659 561 public function enqueue_widgets_scripts() {
660 562 foreach ( $this->get_widget_types() as $widget ) {
661 563 $widget->enqueue_scripts();
662 564 }
@@ -661,14 +563,8 @@
661 563 $widget->enqueue_scripts();
662 564 }
663 565 }
664 566
665 - public function register_frontend_handlers() {
666 - foreach ( $this->get_widget_types() as $widget ) {
667 - $widget->register_frontend_handlers();
668 - }
669 - }
670 -
671 567 /**
672 568 * Enqueue widgets styles
673 569 *
674 570 * Enqueue all the styles defined as a dependency for each widget
@@ -743,9 +639,9 @@
743 639 * Initializing Elementor widgets manager.
744 640 *
745 641 * @since 1.0.0
746 642 * @access public
747 - */
643 + */
748 644 public function __construct() {
749 645 $this->require_files();
750 646
751 647 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
@@ -765,26 +661,9 @@
765 661 $ajax_manager->register_ajax_action( 'render_widget', [ $this, 'ajax_render_widget' ] );
766 662 $ajax_manager->register_ajax_action( 'editor_get_wp_widget_form', [ $this, 'ajax_get_wp_widget_form' ] );
767 663 $ajax_manager->register_ajax_action( 'get_widgets_config', [ $this, 'ajax_get_widget_types_controls_config' ] );
768 664
769 - $ajax_manager->register_ajax_action( 'refresh_widgets_config', [ $this, 'ajax_refresh_widgets_config' ] );
770 -
771 665 $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) {
772 666 return $this->ajax_get_widgets_default_value_translations( $data );
773 667 } );
774 - }
775 -
776 - /**
777 - * @param string $experiment_name
778 - * @param array $classes
779 - * @return void
780 - */
781 - public function register_promoted_active_widgets( string $experiment_name, array $classes ): void {
782 - if ( ! Plugin::$instance->experiments->is_feature_active( $experiment_name ) || empty( $classes ) ) {
783 - return;
784 - }
785 -
786 - foreach ( $classes as $class_name ) {
787 - $this->register( new $class_name() );
788 - }
789 668 }
790 669 }