PluginProbe
Elementor Website Builder – more than just a page builder / 3.9.2
Elementor Website Builder – more than just a page builder v3.9.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 +44 -201 4.2.13.9.2 View file →
@@ -2,18 +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 -use Elementor\Modules\NestedTabs\Widgets\NestedTabs;
16 8
17 9 if ( ! defined( 'ABSPATH' ) ) {
18 10 exit; // Exit if accessed directly.
19 11 }
@@ -40,48 +32,19 @@
40 32 */
41 33 private $_widget_types = null;
42 34
43 35 /**
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 36 * Init widgets.
72 37 *
73 - * Initialize Elementor widgets manager. Include all the widgets files
38 + * Initialize Elementor widgets manager. Include all the the widgets files
74 39 * and register each Elementor and WordPress widget.
75 40 *
76 41 * @since 2.0.0
77 42 * @access private
78 - */
43 + */
79 44 private function init_widgets() {
80 45 $build_widgets_filename = [
81 - 'common-base',
82 46 'common',
83 - 'common-optimized',
84 47 'inner-section',
85 48 'heading',
86 49 'image',
87 50 'text-editor',
@@ -110,17 +73,14 @@
110 73 'html',
111 74 'menu-anchor',
112 75 'sidebar',
113 76 'read-more',
114 - 'rating',
115 77 ];
116 78
117 79 $this->_widget_types = [];
118 80
119 - $this->register_promoted_widgets();
120 -
121 81 foreach ( $build_widgets_filename as $widget_filename ) {
122 - include ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php';
82 + include( ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php' );
123 83
124 84 $class_name = str_replace( '-', '_', $widget_filename );
125 85
126 86 $class_name = __NAMESPACE__ . '\Widget_' . $class_name;
@@ -168,12 +128,27 @@
168 128 * plugin authors can filter the black list.
169 129 *
170 130 * @since 2.0.0
171 131 * @access private
172 - */
132 + */
173 133 private function register_wp_widgets() {
174 134 global $wp_widget_factory;
175 135
136 + // Skip Pojo widgets.
137 + $pojo_allowed_widgets = [
138 + 'Pojo_Widget_Recent_Posts',
139 + 'Pojo_Widget_Posts_Group',
140 + 'Pojo_Widget_Gallery',
141 + 'Pojo_Widget_Recent_Galleries',
142 + 'Pojo_Slideshow_Widget',
143 + 'Pojo_Forms_Widget',
144 + 'Pojo_Widget_News_Ticker',
145 +
146 + 'Pojo_Widget_WC_Products',
147 + 'Pojo_Widget_WC_Products_Category',
148 + 'Pojo_Widget_WC_Product_Categories',
149 + ];
150 +
176 151 // Allow themes/plugins to filter out their widgets.
177 152 $black_list = [];
178 153
179 154 /**
@@ -192,8 +167,12 @@
192 167 if ( in_array( $widget_class, $black_list ) ) {
193 168 continue;
194 169 }
195 170
171 + if ( $widget_obj instanceof \Pojo_Widget_Base && ! in_array( $widget_class, $pojo_allowed_widgets ) ) {
172 + continue;
173 + }
174 +
196 175 $elementor_widget_class = __NAMESPACE__ . '\Widget_WordPress';
197 176
198 177 $this->register(
199 178 new $elementor_widget_class( [], [
@@ -209,9 +188,9 @@
209 188 * Require Elementor widget base class.
210 189 *
211 190 * @since 2.0.0
212 191 * @access private
213 - */
192 + */
214 193 private function require_files() {
215 194 require ELEMENTOR_PATH . 'includes/base/widget-base.php';
216 195 }
217 196
@@ -232,19 +211,19 @@
232 211 * Add a new widget type to the list of registered widget types.
233 212 *
234 213 * @since 1.0.0
235 214 * @access public
236 - * @deprecated 3.5.0 Use `register()` method instead.
215 + * @deprecated 3.5.0 Use `$this->register()` instead.
237 216 *
238 217 * @param Widget_Base $widget Elementor widget.
239 218 *
240 219 * @return true True if the widget was registered.
241 - */
220 + */
242 221 public function register_widget_type( Widget_Base $widget ) {
243 222 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
244 223 __METHOD__,
245 224 '3.5.0',
246 - 'register()'
225 + 'register'
247 226 );
248 227
249 228 return $this->register( $widget );
250 229 }
@@ -253,11 +232,12 @@
253 232 * Register a new widget type.
254 233 *
255 234 * @param \Elementor\Widget_Base $widget_instance Elementor Widget.
256 235 *
257 - * @return bool True if the widget was registered.
236 + * @return true True if the widget was registered.
258 237 * @since 3.5.0
259 238 * @access public
239 + *
260 240 */
261 241 public function register( Widget_Base $widget_instance ) {
262 242 if ( is_null( $this->_widget_types ) ) {
263 243 $this->init_widgets();
@@ -262,41 +242,13 @@
262 242 if ( is_null( $this->_widget_types ) ) {
263 243 $this->init_widgets();
264 244 }
265 245
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 246 $this->_widget_types[ $widget_instance->get_name() ] = $widget_instance;
281 247
282 248 return true;
283 249 }
284 250
285 - /** Register promoted widgets
286 - *
287 - * 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.
289 - *
290 - * @return void
291 - */
292 - private function register_promoted_widgets() {
293 -
294 - foreach ( $this->promoted_widgets as $experiment_name => $classes ) {
295 - $this->register_promoted_active_widgets( $experiment_name, $classes );
296 - }
297 - }
298 -
299 251 /**
300 252 * Unregister widget type.
301 253 *
302 254 * Removes widget type from the list of registered widget types.
@@ -302,19 +254,19 @@
302 254 * Removes widget type from the list of registered widget types.
303 255 *
304 256 * @since 1.0.0
305 257 * @access public
306 - * @deprecated 3.5.0 Use `unregister()` method instead.
258 + * @deprecated 3.5.0 Use `$this->unregister()` instead.
307 259 *
308 260 * @param string $name Widget name.
309 261 *
310 262 * @return true True if the widget was unregistered, False otherwise.
311 - */
263 + */
312 264 public function unregister_widget_type( $name ) {
313 265 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
314 266 __METHOD__,
315 267 '3.5.0',
316 - 'unregister()'
268 + 'unregister'
317 269 );
318 270
319 271 return $this->unregister( $name );
320 272 }
@@ -351,9 +303,9 @@
351 303 *
352 304 * @param string $widget_name Optional. Widget name. Default is null.
353 305 *
354 306 * @return Widget_Base|Widget_Base[]|null Registered widget types.
355 - */
307 + */
356 308 public function get_widget_types( $widget_name = null ) {
357 309 if ( is_null( $this->_widget_types ) ) {
358 310 $this->init_widgets();
359 311 }
@@ -373,9 +325,9 @@
373 325 * @since 1.0.0
374 326 * @access public
375 327 *
376 328 * @return array Registered widget types with each widget config.
377 - */
329 + */
378 330 public function get_widget_types_config() {
379 331 $config = [];
380 332
381 333 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
@@ -384,14 +336,9 @@
384 336
385 337 return $config;
386 338 }
387 339
388 - /**
389 - * @throws \Exception If current user don't have permissions to edit the post.
390 - */
391 340 public function ajax_get_widget_types_controls_config( array $data ) {
392 - Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
393 -
394 341 wp_raise_memory_limit( 'admin' );
395 342
396 343 $config = [];
397 344
@@ -408,35 +355,8 @@
408 355
409 356 return $config;
410 357 }
411 358
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 359 public function ajax_get_widgets_default_value_translations( array $data = [] ) {
440 360 $locale = empty( $data['locale'] )
441 361 ? get_locale()
442 362 : $data['locale'];
@@ -482,10 +402,14 @@
482 402 * @type string $render The rendered HTML.
483 403 * }
484 404 */
485 405 public function ajax_render_widget( $request ) {
486 - $document = Plugin::$instance->documents->get_with_permissions( $request['editor_post_id'] );
406 + $document = Plugin::$instance->documents->get( $request['editor_post_id'] );
487 407
408 + if ( ! $document->is_editable_by_current_user() ) {
409 + throw new \Exception( 'Access denied.', Exceptions::FORBIDDEN );
410 + }
411 +
488 412 // Override the global $post for the render.
489 413 query_posts(
490 414 [
491 415 'p' => $request['editor_post_id'],
@@ -520,13 +444,10 @@
520 444 *
521 445 * @param array $request Ajax request.
522 446 *
523 447 * @return bool|string Rendered widget form.
524 - * @throws \Exception If current user don't have permissions to edit the post.
525 448 */
526 449 public function ajax_get_wp_widget_form( $request ) {
527 - Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );
528 -
529 450 if ( empty( $request['widget_type'] ) ) {
530 451 return false;
531 452 }
532 453
@@ -560,9 +481,9 @@
560 481 * template, for all the registered widget types.
561 482 *
562 483 * @since 1.0.0
563 484 * @access public
564 - */
485 + */
565 486 public function render_widgets_content() {
566 487 foreach ( $this->get_widget_types() as $widget ) {
567 488 $widget->print_template();
568 489 }
@@ -577,9 +498,9 @@
577 498 * @since 1.3.0
578 499 * @access public
579 500 *
580 501 * @return array Registered widget types with settings keys for each widget.
581 - */
502 + */
582 503 public function get_widgets_frontend_settings_keys() {
583 504 $keys = [];
584 505
585 506 foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) {
@@ -593,63 +514,8 @@
593 514 return $keys;
594 515 }
595 516
596 517 /**
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 518 * Enqueue widgets scripts.
653 519 *
654 520 * Enqueue all the scripts defined as a dependency for each widget.
655 521 *
@@ -654,9 +520,9 @@
654 520 * Enqueue all the scripts defined as a dependency for each widget.
655 521 *
656 522 * @since 1.3.0
657 523 * @access public
658 - */
524 + */
659 525 public function enqueue_widgets_scripts() {
660 526 foreach ( $this->get_widget_types() as $widget ) {
661 527 $widget->enqueue_scripts();
662 528 }
@@ -661,14 +527,8 @@
661 527 $widget->enqueue_scripts();
662 528 }
663 529 }
664 530
665 - public function register_frontend_handlers() {
666 - foreach ( $this->get_widget_types() as $widget ) {
667 - $widget->register_frontend_handlers();
668 - }
669 - }
670 -
671 531 /**
672 532 * Enqueue widgets styles
673 533 *
674 534 * Enqueue all the styles defined as a dependency for each widget
@@ -743,9 +603,9 @@
743 603 * Initializing Elementor widgets manager.
744 604 *
745 605 * @since 1.0.0
746 606 * @access public
747 - */
607 + */
748 608 public function __construct() {
749 609 $this->require_files();
750 610
751 611 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
@@ -765,26 +625,9 @@
765 625 $ajax_manager->register_ajax_action( 'render_widget', [ $this, 'ajax_render_widget' ] );
766 626 $ajax_manager->register_ajax_action( 'editor_get_wp_widget_form', [ $this, 'ajax_get_wp_widget_form' ] );
767 627 $ajax_manager->register_ajax_action( 'get_widgets_config', [ $this, 'ajax_get_widget_types_controls_config' ] );
768 628
769 - $ajax_manager->register_ajax_action( 'refresh_widgets_config', [ $this, 'ajax_refresh_widgets_config' ] );
770 -
771 629 $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) {
772 630 return $this->ajax_get_widgets_default_value_translations( $data );
773 631 } );
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 632 }
790 633 }