PluginProbe
Elementor Website Builder – more than just a page builder / 3.13.0-beta1
Elementor Website Builder – more than just a page builder v3.13.0-beta1
4.3.4 4.3.3 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 All 457 releases
← All changes | includes/managers/widgets.php +31 -189 4.3.0-beta3 → 3.13.0-beta1 View file →
@@ -2,16 +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 8 use Elementor\Modules\NestedTabs\Widgets\NestedTabs;
15 9
16 10 if ( ! defined( 'ABSPATH' ) ) {
17 11 exit; // Exit if accessed directly.
@@ -39,48 +33,19 @@
39 33 */
40 34 private $_widget_types = null;
41 35
42 36 /**
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 37 * Init widgets.
71 38 *
72 - * Initialize Elementor widgets manager. Include all the widgets files
39 + * Initialize Elementor widgets manager. Include all the the widgets files
73 40 * and register each Elementor and WordPress widget.
74 41 *
75 42 * @since 2.0.0
76 43 * @access private
77 - */
44 + */
78 45 private function init_widgets() {
79 46 $build_widgets_filename = [
80 - 'common-base',
81 47 'common',
82 - 'common-optimized',
83 48 'inner-section',
84 49 'heading',
85 50 'image',
86 51 'text-editor',
@@ -109,15 +74,12 @@
109 74 'html',
110 75 'menu-anchor',
111 76 'sidebar',
112 77 'read-more',
113 - 'rating',
114 78 ];
115 79
116 80 $this->_widget_types = [];
117 81
118 - $this->register_promoted_widgets();
119 -
120 82 foreach ( $build_widgets_filename as $widget_filename ) {
121 83 include ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php';
122 84
123 85 $class_name = str_replace( '-', '_', $widget_filename );
@@ -126,8 +88,10 @@
126 88
127 89 $this->register( new $class_name() );
128 90 }
129 91
92 + $this->register_promoted_widgets();
93 +
130 94 $this->register_wp_widgets();
131 95
132 96 /**
133 97 * After widgets registered.
@@ -167,9 +131,9 @@
167 131 * plugin authors can filter the black list.
168 132 *
169 133 * @since 2.0.0
170 134 * @access private
171 - */
135 + */
172 136 private function register_wp_widgets() {
173 137 global $wp_widget_factory;
174 138
175 139 // Allow themes/plugins to filter out their widgets.
@@ -208,9 +172,9 @@
208 172 * Require Elementor widget base class.
209 173 *
210 174 * @since 2.0.0
211 175 * @access private
212 - */
176 + */
213 177 private function require_files() {
214 178 require ELEMENTOR_PATH . 'includes/base/widget-base.php';
215 179 }
216 180
@@ -231,19 +195,19 @@
231 195 * Add a new widget type to the list of registered widget types.
232 196 *
233 197 * @since 1.0.0
234 198 * @access public
235 - * @deprecated 3.5.0 Use `register()` method instead.
199 + * @deprecated 3.5.0 Use `$this->register()` instead.
236 200 *
237 201 * @param Widget_Base $widget Elementor widget.
238 202 *
239 203 * @return true True if the widget was registered.
240 - */
204 + */
241 205 public function register_widget_type( Widget_Base $widget ) {
242 206 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
243 207 __METHOD__,
244 208 '3.5.0',
245 - 'register()'
209 + 'register'
246 210 );
247 211
248 212 return $this->register( $widget );
249 213 }
@@ -252,11 +216,12 @@
252 216 * Register a new widget type.
253 217 *
254 218 * @param \Elementor\Widget_Base $widget_instance Elementor Widget.
255 219 *
256 - * @return bool True if the widget was registered.
220 + * @return true True if the widget was registered.
257 221 * @since 3.5.0
258 222 * @access public
223 + *
259 224 */
260 225 public function register( Widget_Base $widget_instance ) {
261 226 if ( is_null( $this->_widget_types ) ) {
262 227 $this->init_widgets();
@@ -261,38 +226,24 @@
261 226 if ( is_null( $this->_widget_types ) ) {
262 227 $this->init_widgets();
263 228 }
264 229
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 230 $this->_widget_types[ $widget_instance->get_name() ] = $widget_instance;
280 231
281 232 return true;
282 233 }
283 234
284 - /** Register promoted widgets
235 + /** register promoted widgets
285 236 *
286 237 * 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.
238 + * location on our widgets panel we need to use an hard coded solution fort his
288 239 *
289 240 * @return void
290 241 */
291 242 private function register_promoted_widgets() {
292 -
293 - foreach ( $this->promoted_widgets as $experiment_name => $classes ) {
294 - $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;
295 246 }
296 247 }
297 248
298 249 /**
@@ -301,19 +252,19 @@
301 252 * Removes widget type from the list of registered widget types.
302 253 *
303 254 * @since 1.0.0
304 255 * @access public
305 - * @deprecated 3.5.0 Use `unregister()` method instead.
256 + * @deprecated 3.5.0 Use `$this->unregister()` instead.
306 257 *
307 258 * @param string $name Widget name.
308 259 *
309 260 * @return true True if the widget was unregistered, False otherwise.
310 - */
261 + */
311 262 public function unregister_widget_type( $name ) {
312 263 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
313 264 __METHOD__,
314 265 '3.5.0',
315 - 'unregister()'
266 + 'unregister'
316 267 );
317 268
318 269 return $this->unregister( $name );
319 270 }
@@ -350,9 +301,9 @@
350 301 *
351 302 * @param string $widget_name Optional. Widget name. Default is null.
352 303 *
353 304 * @return Widget_Base|Widget_Base[]|null Registered widget types.
354 - */
305 + */
355 306 public function get_widget_types( $widget_name = null ) {
356 307 if ( is_null( $this->_widget_types ) ) {
357 308 $this->init_widgets();
358 309 }
@@ -372,9 +323,9 @@
372 323 * @since 1.0.0
373 324 * @access public
374 325 *
375 326 * @return array Registered widget types with each widget config.
376 - */
327 + */
377 328 public function get_widget_types_config() {
378 329 $config = [];
379 330
380 331 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
@@ -383,14 +334,9 @@
383 334
384 335 return $config;
385 336 }
386 337
387 - /**
388 - * @throws \Exception If current user don't have permissions to edit the post.
389 - */
390 338 public function ajax_get_widget_types_controls_config( array $data ) {
391 - Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
392 -
393 339 wp_raise_memory_limit( 'admin' );
394 340
395 341 $config = [];
396 342
@@ -407,35 +353,8 @@
407 353
408 354 return $config;
409 355 }
410 356
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 357 public function ajax_get_widgets_default_value_translations( array $data = [] ) {
439 358 $locale = empty( $data['locale'] )
440 359 ? get_locale()
441 360 : $data['locale'];
@@ -481,10 +400,14 @@
481 400 * @type string $render The rendered HTML.
482 401 * }
483 402 */
484 403 public function ajax_render_widget( $request ) {
485 - $document = Plugin::$instance->documents->get_with_permissions( $request['editor_post_id'] );
404 + $document = Plugin::$instance->documents->get( $request['editor_post_id'] );
486 405
406 + if ( ! $document->is_editable_by_current_user() ) {
407 + throw new \Exception( 'Access denied.', Exceptions::FORBIDDEN );
408 + }
409 +
487 410 // Override the global $post for the render.
488 411 query_posts(
489 412 [
490 413 'p' => $request['editor_post_id'],
@@ -519,13 +442,10 @@
519 442 *
520 443 * @param array $request Ajax request.
521 444 *
522 445 * @return bool|string Rendered widget form.
523 - * @throws \Exception If current user don't have permissions to edit the post.
524 446 */
525 447 public function ajax_get_wp_widget_form( $request ) {
526 - Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );
527 -
528 448 if ( empty( $request['widget_type'] ) ) {
529 449 return false;
530 450 }
531 451
@@ -559,9 +479,9 @@
559 479 * template, for all the registered widget types.
560 480 *
561 481 * @since 1.0.0
562 482 * @access public
563 - */
483 + */
564 484 public function render_widgets_content() {
565 485 foreach ( $this->get_widget_types() as $widget ) {
566 486 $widget->print_template();
567 487 }
@@ -576,9 +496,9 @@
576 496 * @since 1.3.0
577 497 * @access public
578 498 *
579 499 * @return array Registered widget types with settings keys for each widget.
580 - */
500 + */
581 501 public function get_widgets_frontend_settings_keys() {
582 502 $keys = [];
583 503
584 504 foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) {
@@ -592,63 +512,8 @@
592 512 return $keys;
593 513 }
594 514
595 515 /**
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 516 * Enqueue widgets scripts.
652 517 *
653 518 * Enqueue all the scripts defined as a dependency for each widget.
654 519 *
@@ -653,9 +518,9 @@
653 518 * Enqueue all the scripts defined as a dependency for each widget.
654 519 *
655 520 * @since 1.3.0
656 521 * @access public
657 - */
522 + */
658 523 public function enqueue_widgets_scripts() {
659 524 foreach ( $this->get_widget_types() as $widget ) {
660 525 $widget->enqueue_scripts();
661 526 }
@@ -660,14 +525,8 @@
660 525 $widget->enqueue_scripts();
661 526 }
662 527 }
663 528
664 - public function register_frontend_handlers() {
665 - foreach ( $this->get_widget_types() as $widget ) {
666 - $widget->register_frontend_handlers();
667 - }
668 - }
669 -
670 529 /**
671 530 * Enqueue widgets styles
672 531 *
673 532 * Enqueue all the styles defined as a dependency for each widget
@@ -742,9 +601,9 @@
742 601 * Initializing Elementor widgets manager.
743 602 *
744 603 * @since 1.0.0
745 604 * @access public
746 - */
605 + */
747 606 public function __construct() {
748 607 $this->require_files();
749 608
750 609 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
@@ -764,26 +623,9 @@
764 623 $ajax_manager->register_ajax_action( 'render_widget', [ $this, 'ajax_render_widget' ] );
765 624 $ajax_manager->register_ajax_action( 'editor_get_wp_widget_form', [ $this, 'ajax_get_wp_widget_form' ] );
766 625 $ajax_manager->register_ajax_action( 'get_widgets_config', [ $this, 'ajax_get_widget_types_controls_config' ] );
767 626
768 - $ajax_manager->register_ajax_action( 'refresh_widgets_config', [ $this, 'ajax_refresh_widgets_config' ] );
769 -
770 627 $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) {
771 628 return $this->ajax_get_widgets_default_value_translations( $data );
772 629 } );
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 630 }
789 631 }