PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.2
Elementor Website Builder – more than just a page builder v3.13.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 +28 -183 4.2.0-dev23.13.2 View file →
@@ -2,17 +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 -use Elementor\Modules\NestedAccordion\Widgets\Nested_Accordion;
14 -use Elementor\Modules\NestedElements\Module as NestedElementsModule;
15 8 use Elementor\Modules\NestedTabs\Widgets\NestedTabs;
16 9
17 10 if ( ! defined( 'ABSPATH' ) ) {
18 11 exit; // Exit if accessed directly.
@@ -40,48 +33,19 @@
40 33 */
41 34 private $_widget_types = null;
42 35
43 36 /**
44 - * Promoted widget types.
45 - *
46 - * Holds the list of all the Promoted widget types.
47 - *
48 - * @since 3.15.0
49 - * @access private
50 - *
51 - * @var Widget_Base[]
52 - *
53 - * @return array
54 - */
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 - ],
68 - ];
69 -
70 - /**
71 37 * Init widgets.
72 38 *
73 - * Initialize Elementor widgets manager. Include all the widgets files
39 + * Initialize Elementor widgets manager. Include all the the widgets files
74 40 * and register each Elementor and WordPress widget.
75 41 *
76 42 * @since 2.0.0
77 43 * @access private
78 - */
44 + */
79 45 private function init_widgets() {
80 46 $build_widgets_filename = [
81 - 'common-base',
82 47 'common',
83 - 'common-optimized',
84 48 'inner-section',
85 49 'heading',
86 50 'image',
87 51 'text-editor',
@@ -110,15 +74,12 @@
110 74 'html',
111 75 'menu-anchor',
112 76 'sidebar',
113 77 'read-more',
114 - 'rating',
115 78 ];
116 79
117 80 $this->_widget_types = [];
118 81
119 - $this->register_promoted_widgets();
120 -
121 82 foreach ( $build_widgets_filename as $widget_filename ) {
122 83 include ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php';
123 84
124 85 $class_name = str_replace( '-', '_', $widget_filename );
@@ -127,8 +88,10 @@
127 88
128 89 $this->register( new $class_name() );
129 90 }
130 91
92 + $this->register_promoted_widgets();
93 +
131 94 $this->register_wp_widgets();
132 95
133 96 /**
134 97 * After widgets registered.
@@ -168,9 +131,9 @@
168 131 * plugin authors can filter the black list.
169 132 *
170 133 * @since 2.0.0
171 134 * @access private
172 - */
135 + */
173 136 private function register_wp_widgets() {
174 137 global $wp_widget_factory;
175 138
176 139 // Allow themes/plugins to filter out their widgets.
@@ -209,9 +172,9 @@
209 172 * Require Elementor widget base class.
210 173 *
211 174 * @since 2.0.0
212 175 * @access private
213 - */
176 + */
214 177 private function require_files() {
215 178 require ELEMENTOR_PATH . 'includes/base/widget-base.php';
216 179 }
217 180
@@ -232,19 +195,19 @@
232 195 * Add a new widget type to the list of registered widget types.
233 196 *
234 197 * @since 1.0.0
235 198 * @access public
236 - * @deprecated 3.5.0 Use `register()` method instead.
199 + * @deprecated 3.5.0 Use `$this->register()` instead.
237 200 *
238 201 * @param Widget_Base $widget Elementor widget.
239 202 *
240 203 * @return true True if the widget was registered.
241 - */
204 + */
242 205 public function register_widget_type( Widget_Base $widget ) {
243 206 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
244 207 __METHOD__,
245 208 '3.5.0',
246 - 'register()'
209 + 'register'
247 210 );
248 211
249 212 return $this->register( $widget );
250 213 }
@@ -253,11 +216,12 @@
253 216 * Register a new widget type.
254 217 *
255 218 * @param \Elementor\Widget_Base $widget_instance Elementor Widget.
256 219 *
257 - * @return bool True if the widget was registered.
220 + * @return true True if the widget was registered.
258 221 * @since 3.5.0
259 222 * @access public
223 + *
260 224 */
261 225 public function register( Widget_Base $widget_instance ) {
262 226 if ( is_null( $this->_widget_types ) ) {
263 227 $this->init_widgets();
@@ -262,38 +226,24 @@
262 226 if ( is_null( $this->_widget_types ) ) {
263 227 $this->init_widgets();
264 228 }
265 229
266 - /**
267 - * Should widget be registered.
268 - *
269 - * @since 3.18.0
270 - *
271 - * @param bool $should_register Should widget be registered. Default is `true`.
272 - * @param \Elementor\Widget_Base $widget_instance Widget instance.
273 - */
274 - $should_register = apply_filters( 'elementor/widgets/is_widget_enabled', true, $widget_instance );
275 -
276 - if ( ! $should_register ) {
277 - return false;
278 - }
279 -
280 230 $this->_widget_types[ $widget_instance->get_name() ] = $widget_instance;
281 231
282 232 return true;
283 233 }
284 234
285 - /** Register promoted widgets
235 + /** register promoted widgets
286 236 *
287 237 * Since we cannot allow widgets to place themselves is a specific
288 - * location on our widgets panel we need to use a hard coded solution for this.
238 + * location on our widgets panel we need to use an hard coded solution fort his
289 239 *
290 240 * @return void
291 241 */
292 242 private function register_promoted_widgets() {
293 -
294 - foreach ( $this->promoted_widgets as $experiment_name => $classes ) {
295 - $this->register_promoted_active_widgets( $experiment_name, $classes );
243 + if ( Plugin::$instance->experiments->is_feature_active( 'nested-elements' ) ) {
244 + $nested_tabs = new NestedTabs();
245 + $this->_widget_types = [ $nested_tabs->get_name() => $nested_tabs ] + $this->_widget_types;
296 246 }
297 247 }
298 248
299 249 /**
@@ -302,19 +252,19 @@
302 252 * Removes widget type from the list of registered widget types.
303 253 *
304 254 * @since 1.0.0
305 255 * @access public
306 - * @deprecated 3.5.0 Use `unregister()` method instead.
256 + * @deprecated 3.5.0 Use `$this->unregister()` instead.
307 257 *
308 258 * @param string $name Widget name.
309 259 *
310 260 * @return true True if the widget was unregistered, False otherwise.
311 - */
261 + */
312 262 public function unregister_widget_type( $name ) {
313 263 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
314 264 __METHOD__,
315 265 '3.5.0',
316 - 'unregister()'
266 + 'unregister'
317 267 );
318 268
319 269 return $this->unregister( $name );
320 270 }
@@ -351,9 +301,9 @@
351 301 *
352 302 * @param string $widget_name Optional. Widget name. Default is null.
353 303 *
354 304 * @return Widget_Base|Widget_Base[]|null Registered widget types.
355 - */
305 + */
356 306 public function get_widget_types( $widget_name = null ) {
357 307 if ( is_null( $this->_widget_types ) ) {
358 308 $this->init_widgets();
359 309 }
@@ -373,9 +323,9 @@
373 323 * @since 1.0.0
374 324 * @access public
375 325 *
376 326 * @return array Registered widget types with each widget config.
377 - */
327 + */
378 328 public function get_widget_types_config() {
379 329 $config = [];
380 330
381 331 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
@@ -385,9 +335,9 @@
385 335 return $config;
386 336 }
387 337
388 338 /**
389 - * @throws \Exception If current user don't have permissions to edit the post.
339 + * @throws \Exception
390 340 */
391 341 public function ajax_get_widget_types_controls_config( array $data ) {
392 342 Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
393 343
@@ -408,35 +358,8 @@
408 358
409 359 return $config;
410 360 }
411 361
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 362 public function ajax_get_widgets_default_value_translations( array $data = [] ) {
440 363 $locale = empty( $data['locale'] )
441 364 ? get_locale()
442 365 : $data['locale'];
@@ -520,9 +443,9 @@
520 443 *
521 444 * @param array $request Ajax request.
522 445 *
523 446 * @return bool|string Rendered widget form.
524 - * @throws \Exception If current user don't have permissions to edit the post.
447 + * @throws \Exception
525 448 */
526 449 public function ajax_get_wp_widget_form( $request ) {
527 450 Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );
528 451
@@ -560,9 +483,9 @@
560 483 * template, for all the registered widget types.
561 484 *
562 485 * @since 1.0.0
563 486 * @access public
564 - */
487 + */
565 488 public function render_widgets_content() {
566 489 foreach ( $this->get_widget_types() as $widget ) {
567 490 $widget->print_template();
568 491 }
@@ -577,9 +500,9 @@
577 500 * @since 1.3.0
578 501 * @access public
579 502 *
580 503 * @return array Registered widget types with settings keys for each widget.
581 - */
504 + */
582 505 public function get_widgets_frontend_settings_keys() {
583 506 $keys = [];
584 507
585 508 foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) {
@@ -593,63 +516,8 @@
593 516 return $keys;
594 517 }
595 518
596 519 /**
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 520 * Enqueue widgets scripts.
653 521 *
654 522 * Enqueue all the scripts defined as a dependency for each widget.
655 523 *
@@ -654,9 +522,9 @@
654 522 * Enqueue all the scripts defined as a dependency for each widget.
655 523 *
656 524 * @since 1.3.0
657 525 * @access public
658 - */
526 + */
659 527 public function enqueue_widgets_scripts() {
660 528 foreach ( $this->get_widget_types() as $widget ) {
661 529 $widget->enqueue_scripts();
662 530 }
@@ -661,14 +529,8 @@
661 529 $widget->enqueue_scripts();
662 530 }
663 531 }
664 532
665 - public function register_frontend_handlers() {
666 - foreach ( $this->get_widget_types() as $widget ) {
667 - $widget->register_frontend_handlers();
668 - }
669 - }
670 -
671 533 /**
672 534 * Enqueue widgets styles
673 535 *
674 536 * Enqueue all the styles defined as a dependency for each widget
@@ -743,9 +605,9 @@
743 605 * Initializing Elementor widgets manager.
744 606 *
745 607 * @since 1.0.0
746 608 * @access public
747 - */
609 + */
748 610 public function __construct() {
749 611 $this->require_files();
750 612
751 613 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
@@ -765,26 +627,9 @@
765 627 $ajax_manager->register_ajax_action( 'render_widget', [ $this, 'ajax_render_widget' ] );
766 628 $ajax_manager->register_ajax_action( 'editor_get_wp_widget_form', [ $this, 'ajax_get_wp_widget_form' ] );
767 629 $ajax_manager->register_ajax_action( 'get_widgets_config', [ $this, 'ajax_get_widget_types_controls_config' ] );
768 630
769 - $ajax_manager->register_ajax_action( 'refresh_widgets_config', [ $this, 'ajax_refresh_widgets_config' ] );
770 -
771 631 $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) {
772 632 return $this->ajax_get_widgets_default_value_translations( $data );
773 633 } );
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 634 }
790 635 }