PluginProbe
Elementor Website Builder – more than just a page builder / 3.11.2
Elementor Website Builder – more than just a page builder v3.11.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 +50 -161 4.0.73.11.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,12 +131,27 @@
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
139 + // Skip Pojo widgets.
140 + $pojo_allowed_widgets = [
141 + 'Pojo_Widget_Recent_Posts',
142 + 'Pojo_Widget_Posts_Group',
143 + 'Pojo_Widget_Gallery',
144 + 'Pojo_Widget_Recent_Galleries',
145 + 'Pojo_Slideshow_Widget',
146 + 'Pojo_Forms_Widget',
147 + 'Pojo_Widget_News_Ticker',
148 +
149 + 'Pojo_Widget_WC_Products',
150 + 'Pojo_Widget_WC_Products_Category',
151 + 'Pojo_Widget_WC_Product_Categories',
152 + ];
153 +
176 154 // Allow themes/plugins to filter out their widgets.
177 155 $black_list = [];
178 156
179 157 /**
@@ -192,8 +170,12 @@
192 170 if ( in_array( $widget_class, $black_list ) ) {
193 171 continue;
194 172 }
195 173
174 + if ( $widget_obj instanceof \Pojo_Widget_Base && ! in_array( $widget_class, $pojo_allowed_widgets ) ) {
175 + continue;
176 + }
177 +
196 178 $elementor_widget_class = __NAMESPACE__ . '\Widget_WordPress';
197 179
198 180 $this->register(
199 181 new $elementor_widget_class( [], [
@@ -209,9 +191,9 @@
209 191 * Require Elementor widget base class.
210 192 *
211 193 * @since 2.0.0
212 194 * @access private
213 - */
195 + */
214 196 private function require_files() {
215 197 require ELEMENTOR_PATH . 'includes/base/widget-base.php';
216 198 }
217 199
@@ -232,19 +214,19 @@
232 214 * Add a new widget type to the list of registered widget types.
233 215 *
234 216 * @since 1.0.0
235 217 * @access public
236 - * @deprecated 3.5.0 Use `register()` method instead.
218 + * @deprecated 3.5.0 Use `$this->register()` instead.
237 219 *
238 220 * @param Widget_Base $widget Elementor widget.
239 221 *
240 222 * @return true True if the widget was registered.
241 - */
223 + */
242 224 public function register_widget_type( Widget_Base $widget ) {
243 225 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
244 226 __METHOD__,
245 227 '3.5.0',
246 - 'register()'
228 + 'register'
247 229 );
248 230
249 231 return $this->register( $widget );
250 232 }
@@ -253,11 +235,12 @@
253 235 * Register a new widget type.
254 236 *
255 237 * @param \Elementor\Widget_Base $widget_instance Elementor Widget.
256 238 *
257 - * @return bool True if the widget was registered.
239 + * @return true True if the widget was registered.
258 240 * @since 3.5.0
259 241 * @access public
242 + *
260 243 */
261 244 public function register( Widget_Base $widget_instance ) {
262 245 if ( is_null( $this->_widget_types ) ) {
263 246 $this->init_widgets();
@@ -262,38 +245,24 @@
262 245 if ( is_null( $this->_widget_types ) ) {
263 246 $this->init_widgets();
264 247 }
265 248
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 249 $this->_widget_types[ $widget_instance->get_name() ] = $widget_instance;
281 250
282 251 return true;
283 252 }
284 253
285 - /** Register promoted widgets
254 + /** register promoted widgets
286 255 *
287 256 * 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.
257 + * location on our widgets panel we need to use an hard coded solution fort his
289 258 *
290 259 * @return void
291 260 */
292 261 private function register_promoted_widgets() {
293 -
294 - foreach ( $this->promoted_widgets as $experiment_name => $classes ) {
295 - $this->register_promoted_active_widgets( $experiment_name, $classes );
262 + if ( Plugin::$instance->experiments->is_feature_active( 'nested-elements' ) ) {
263 + $nested_tabs = new NestedTabs();
264 + $this->_widget_types = [ $nested_tabs->get_name() => $nested_tabs ] + $this->_widget_types;
296 265 }
297 266 }
298 267
299 268 /**
@@ -302,19 +271,19 @@
302 271 * Removes widget type from the list of registered widget types.
303 272 *
304 273 * @since 1.0.0
305 274 * @access public
306 - * @deprecated 3.5.0 Use `unregister()` method instead.
275 + * @deprecated 3.5.0 Use `$this->unregister()` instead.
307 276 *
308 277 * @param string $name Widget name.
309 278 *
310 279 * @return true True if the widget was unregistered, False otherwise.
311 - */
280 + */
312 281 public function unregister_widget_type( $name ) {
313 282 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
314 283 __METHOD__,
315 284 '3.5.0',
316 - 'unregister()'
285 + 'unregister'
317 286 );
318 287
319 288 return $this->unregister( $name );
320 289 }
@@ -351,9 +320,9 @@
351 320 *
352 321 * @param string $widget_name Optional. Widget name. Default is null.
353 322 *
354 323 * @return Widget_Base|Widget_Base[]|null Registered widget types.
355 - */
324 + */
356 325 public function get_widget_types( $widget_name = null ) {
357 326 if ( is_null( $this->_widget_types ) ) {
358 327 $this->init_widgets();
359 328 }
@@ -373,9 +342,9 @@
373 342 * @since 1.0.0
374 343 * @access public
375 344 *
376 345 * @return array Registered widget types with each widget config.
377 - */
346 + */
378 347 public function get_widget_types_config() {
379 348 $config = [];
380 349
381 350 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
@@ -384,14 +353,9 @@
384 353
385 354 return $config;
386 355 }
387 356
388 - /**
389 - * @throws \Exception If current user don't have permissions to edit the post.
390 - */
391 357 public function ajax_get_widget_types_controls_config( array $data ) {
392 - Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
393 -
394 358 wp_raise_memory_limit( 'admin' );
395 359
396 360 $config = [];
397 361
@@ -455,10 +419,14 @@
455 419 * @type string $render The rendered HTML.
456 420 * }
457 421 */
458 422 public function ajax_render_widget( $request ) {
459 - $document = Plugin::$instance->documents->get_with_permissions( $request['editor_post_id'] );
423 + $document = Plugin::$instance->documents->get( $request['editor_post_id'] );
460 424
425 + if ( ! $document->is_editable_by_current_user() ) {
426 + throw new \Exception( 'Access denied.', Exceptions::FORBIDDEN );
427 + }
428 +
461 429 // Override the global $post for the render.
462 430 query_posts(
463 431 [
464 432 'p' => $request['editor_post_id'],
@@ -493,13 +461,10 @@
493 461 *
494 462 * @param array $request Ajax request.
495 463 *
496 464 * @return bool|string Rendered widget form.
497 - * @throws \Exception If current user don't have permissions to edit the post.
498 465 */
499 466 public function ajax_get_wp_widget_form( $request ) {
500 - Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );
501 -
502 467 if ( empty( $request['widget_type'] ) ) {
503 468 return false;
504 469 }
505 470
@@ -533,9 +498,9 @@
533 498 * template, for all the registered widget types.
534 499 *
535 500 * @since 1.0.0
536 501 * @access public
537 - */
502 + */
538 503 public function render_widgets_content() {
539 504 foreach ( $this->get_widget_types() as $widget ) {
540 505 $widget->print_template();
541 506 }
@@ -550,9 +515,9 @@
550 515 * @since 1.3.0
551 516 * @access public
552 517 *
553 518 * @return array Registered widget types with settings keys for each widget.
554 - */
519 + */
555 520 public function get_widgets_frontend_settings_keys() {
556 521 $keys = [];
557 522
558 523 foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) {
@@ -566,63 +531,8 @@
566 531 return $keys;
567 532 }
568 533
569 534 /**
570 - * Widgets with styles.
571 - *
572 - * This method returns the list of all the widgets in the `/includes/`
573 - * folder that have styles.
574 - *
575 - * @since 3.24.0
576 - * @access public
577 - *
578 - * @return array The names of the widgets that have styles.
579 - */
580 - public function widgets_with_styles(): array {
581 - return [
582 - 'counter',
583 - 'divider',
584 - 'google_maps',
585 - 'heading',
586 - 'image',
587 - 'image-carousel',
588 - 'menu-anchor',
589 - 'rating',
590 - 'social-icons',
591 - 'spacer',
592 - 'testimonial',
593 - 'text-editor',
594 - 'video',
595 - ];
596 - }
597 -
598 - /**
599 - * Widgets with responsive styles.
600 - *
601 - * This method returns the list of all the widgets in the `/includes/`
602 - * folder that have responsive styles.
603 - *
604 - * @since 3.24.0
605 - * @access public
606 - *
607 - * @return array The names of the widgets that have responsive styles.
608 - */
609 - public function widgets_with_responsive_styles(): array {
610 - return [
611 - 'accordion',
612 - 'alert',
613 - 'icon-box',
614 - 'icon-list',
615 - 'image-box',
616 - 'image-gallery',
617 - 'progress',
618 - 'star-rating',
619 - 'tabs',
620 - 'toggle',
621 - ];
622 - }
623 -
624 - /**
625 535 * Enqueue widgets scripts.
626 536 *
627 537 * Enqueue all the scripts defined as a dependency for each widget.
628 538 *
@@ -627,9 +537,9 @@
627 537 * Enqueue all the scripts defined as a dependency for each widget.
628 538 *
629 539 * @since 1.3.0
630 540 * @access public
631 - */
541 + */
632 542 public function enqueue_widgets_scripts() {
633 543 foreach ( $this->get_widget_types() as $widget ) {
634 544 $widget->enqueue_scripts();
635 545 }
@@ -634,14 +544,8 @@
634 544 $widget->enqueue_scripts();
635 545 }
636 546 }
637 547
638 - public function register_frontend_handlers() {
639 - foreach ( $this->get_widget_types() as $widget ) {
640 - $widget->register_frontend_handlers();
641 - }
642 - }
643 -
644 548 /**
645 549 * Enqueue widgets styles
646 550 *
647 551 * Enqueue all the styles defined as a dependency for each widget
@@ -716,9 +620,9 @@
716 620 * Initializing Elementor widgets manager.
717 621 *
718 622 * @since 1.0.0
719 623 * @access public
720 - */
624 + */
721 625 public function __construct() {
722 626 $this->require_files();
723 627
724 628 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
@@ -741,21 +645,6 @@
741 645
742 646 $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) {
743 647 return $this->ajax_get_widgets_default_value_translations( $data );
744 648 } );
745 - }
746 -
747 - /**
748 - * @param string $experiment_name
749 - * @param array $classes
750 - * @return void
751 - */
752 - public function register_promoted_active_widgets( string $experiment_name, array $classes ): void {
753 - if ( ! Plugin::$instance->experiments->is_feature_active( $experiment_name ) || empty( $classes ) ) {
754 - return;
755 - }
756 -
757 - foreach ( $classes as $class_name ) {
758 - $this->register( new $class_name() );
759 - }
760 649 }
761 650 }