PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.7
Elementor Website Builder – more than just a page builder v3.6.7
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 -217 4.0.83.6.7 View file →
@@ -1,19 +1,9 @@
1 1 <?php
2 2 namespace Elementor;
3 3
4 4 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
5 -use Elementor\Core\Utils\Collection;
6 -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;
5 +use Elementor\Core\Utils\Exceptions;
16 6
17 7 if ( ! defined( 'ABSPATH' ) ) {
18 8 exit; // Exit if accessed directly.
19 9 }
@@ -40,48 +30,19 @@
40 30 */
41 31 private $_widget_types = null;
42 32
43 33 /**
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 34 * Init widgets.
72 35 *
73 - * Initialize Elementor widgets manager. Include all the widgets files
36 + * Initialize Elementor widgets manager. Include all the the widgets files
74 37 * and register each Elementor and WordPress widget.
75 38 *
76 39 * @since 2.0.0
77 40 * @access private
78 - */
41 + */
79 42 private function init_widgets() {
80 43 $build_widgets_filename = [
81 - 'common-base',
82 44 'common',
83 - 'common-optimized',
84 45 'inner-section',
85 46 'heading',
86 47 'image',
87 48 'text-editor',
@@ -110,17 +71,14 @@
110 71 'html',
111 72 'menu-anchor',
112 73 'sidebar',
113 74 'read-more',
114 - 'rating',
115 75 ];
116 76
117 77 $this->_widget_types = [];
118 78
119 - $this->register_promoted_widgets();
120 -
121 79 foreach ( $build_widgets_filename as $widget_filename ) {
122 - include ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php';
80 + include( ELEMENTOR_PATH . 'includes/widgets/' . $widget_filename . '.php' );
123 81
124 82 $class_name = str_replace( '-', '_', $widget_filename );
125 83
126 84 $class_name = __NAMESPACE__ . '\Widget_' . $class_name;
@@ -168,12 +126,27 @@
168 126 * plugin authors can filter the black list.
169 127 *
170 128 * @since 2.0.0
171 129 * @access private
172 - */
130 + */
173 131 private function register_wp_widgets() {
174 132 global $wp_widget_factory;
175 133
134 + // Skip Pojo widgets.
135 + $pojo_allowed_widgets = [
136 + 'Pojo_Widget_Recent_Posts',
137 + 'Pojo_Widget_Posts_Group',
138 + 'Pojo_Widget_Gallery',
139 + 'Pojo_Widget_Recent_Galleries',
140 + 'Pojo_Slideshow_Widget',
141 + 'Pojo_Forms_Widget',
142 + 'Pojo_Widget_News_Ticker',
143 +
144 + 'Pojo_Widget_WC_Products',
145 + 'Pojo_Widget_WC_Products_Category',
146 + 'Pojo_Widget_WC_Product_Categories',
147 + ];
148 +
176 149 // Allow themes/plugins to filter out their widgets.
177 150 $black_list = [];
178 151
179 152 /**
@@ -192,8 +165,12 @@
192 165 if ( in_array( $widget_class, $black_list ) ) {
193 166 continue;
194 167 }
195 168
169 + if ( $widget_obj instanceof \Pojo_Widget_Base && ! in_array( $widget_class, $pojo_allowed_widgets ) ) {
170 + continue;
171 + }
172 +
196 173 $elementor_widget_class = __NAMESPACE__ . '\Widget_WordPress';
197 174
198 175 $this->register(
199 176 new $elementor_widget_class( [], [
@@ -209,24 +186,13 @@
209 186 * Require Elementor widget base class.
210 187 *
211 188 * @since 2.0.0
212 189 * @access private
213 - */
190 + */
214 191 private function require_files() {
215 192 require ELEMENTOR_PATH . 'includes/base/widget-base.php';
216 193 }
217 194
218 - private function pluck_default_controls( $controls ) {
219 - return ( new Collection( $controls ) )
220 - ->reduce( function ( $controls_defaults, $control, $control_key ) {
221 - if ( ! empty( $control['default'] ) ) {
222 - $controls_defaults[ $control_key ]['default'] = $control['default'];
223 - }
224 -
225 - return $controls_defaults;
226 - }, [] );
227 - }
228 -
229 195 /**
230 196 * Register widget type.
231 197 *
232 198 * Add a new widget type to the list of registered widget types.
@@ -232,19 +198,19 @@
232 198 * Add a new widget type to the list of registered widget types.
233 199 *
234 200 * @since 1.0.0
235 201 * @access public
236 - * @deprecated 3.5.0 Use `register()` method instead.
202 + * @deprecated 3.5.0 Use `$this->register()` instead.
237 203 *
238 204 * @param Widget_Base $widget Elementor widget.
239 205 *
240 206 * @return true True if the widget was registered.
241 - */
207 + */
242 208 public function register_widget_type( Widget_Base $widget ) {
243 209 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
244 210 __METHOD__,
245 211 '3.5.0',
246 - 'register()'
212 + 'register'
247 213 );
248 214
249 215 return $this->register( $widget );
250 216 }
@@ -253,11 +219,12 @@
253 219 * Register a new widget type.
254 220 *
255 221 * @param \Elementor\Widget_Base $widget_instance Elementor Widget.
256 222 *
257 - * @return bool True if the widget was registered.
223 + * @return true True if the widget was registered.
258 224 * @since 3.5.0
259 225 * @access public
226 + *
260 227 */
261 228 public function register( Widget_Base $widget_instance ) {
262 229 if ( is_null( $this->_widget_types ) ) {
263 230 $this->init_widgets();
@@ -262,41 +229,13 @@
262 229 if ( is_null( $this->_widget_types ) ) {
263 230 $this->init_widgets();
264 231 }
265 232
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 233 $this->_widget_types[ $widget_instance->get_name() ] = $widget_instance;
281 234
282 235 return true;
283 236 }
284 237
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 238 /**
300 239 * Unregister widget type.
301 240 *
302 241 * Removes widget type from the list of registered widget types.
@@ -302,19 +241,19 @@
302 241 * Removes widget type from the list of registered widget types.
303 242 *
304 243 * @since 1.0.0
305 244 * @access public
306 - * @deprecated 3.5.0 Use `unregister()` method instead.
245 + * @deprecated 3.5.0 Use `$this->unregister()` instead.
307 246 *
308 247 * @param string $name Widget name.
309 248 *
310 249 * @return true True if the widget was unregistered, False otherwise.
311 - */
250 + */
312 251 public function unregister_widget_type( $name ) {
313 252 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function(
314 253 __METHOD__,
315 254 '3.5.0',
316 - 'unregister()'
255 + 'unregister'
317 256 );
318 257
319 258 return $this->unregister( $name );
320 259 }
@@ -351,9 +290,9 @@
351 290 *
352 291 * @param string $widget_name Optional. Widget name. Default is null.
353 292 *
354 293 * @return Widget_Base|Widget_Base[]|null Registered widget types.
355 - */
294 + */
356 295 public function get_widget_types( $widget_name = null ) {
357 296 if ( is_null( $this->_widget_types ) ) {
358 297 $this->init_widgets();
359 298 }
@@ -373,9 +312,9 @@
373 312 * @since 1.0.0
374 313 * @access public
375 314 *
376 315 * @return array Registered widget types with each widget config.
377 - */
316 + */
378 317 public function get_widget_types_config() {
379 318 $config = [];
380 319
381 320 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
@@ -384,16 +323,9 @@
384 323
385 324 return $config;
386 325 }
387 326
388 - /**
389 - * @throws \Exception If current user don't have permissions to edit the post.
390 - */
391 327 public function ajax_get_widget_types_controls_config( array $data ) {
392 - Plugin::$instance->documents->check_permissions( $data['editor_post_id'] );
393 -
394 - wp_raise_memory_limit( 'admin' );
395 -
396 328 $config = [];
397 329
398 330 foreach ( $this->get_widget_types() as $widget_key => $widget ) {
399 331 if ( isset( $data['exclude'][ $widget_key ] ) ) {
@@ -408,34 +340,8 @@
408 340
409 341 return $config;
410 342 }
411 343
412 - public function ajax_get_widgets_default_value_translations( array $data = [] ) {
413 - $locale = empty( $data['locale'] )
414 - ? get_locale()
415 - : $data['locale'];
416 -
417 - $force_locale = new Force_Locale( $locale );
418 - $force_locale->force();
419 -
420 - $controls = ( new Collection( $this->get_widget_types() ) )
421 - ->map( function ( Widget_Base $widget ) {
422 - $controls = $widget->get_stack( false )['controls'];
423 -
424 - return [
425 - 'controls' => $this->pluck_default_controls( $controls ),
426 - ];
427 - } )
428 - ->filter( function ( $widget ) {
429 - return ! empty( $widget['controls'] );
430 - } )
431 - ->all();
432 -
433 - $force_locale->restore();
434 -
435 - return $controls;
436 - }
437 -
438 344 /**
439 345 * Ajax render widget.
440 346 *
441 347 * Ajax handler for Elementor render_widget.
@@ -455,10 +361,14 @@
455 361 * @type string $render The rendered HTML.
456 362 * }
457 363 */
458 364 public function ajax_render_widget( $request ) {
459 - $document = Plugin::$instance->documents->get_with_permissions( $request['editor_post_id'] );
365 + $document = Plugin::$instance->documents->get( $request['editor_post_id'] );
460 366
367 + if ( ! $document->is_editable_by_current_user() ) {
368 + throw new \Exception( 'Access denied.', Exceptions::FORBIDDEN );
369 + }
370 +
461 371 // Override the global $post for the render.
462 372 query_posts(
463 373 [
464 374 'p' => $request['editor_post_id'],
@@ -493,13 +403,10 @@
493 403 *
494 404 * @param array $request Ajax request.
495 405 *
496 406 * @return bool|string Rendered widget form.
497 - * @throws \Exception If current user don't have permissions to edit the post.
498 407 */
499 408 public function ajax_get_wp_widget_form( $request ) {
500 - Plugin::$instance->documents->check_permissions( $request['editor_post_id'] );
501 -
502 409 if ( empty( $request['widget_type'] ) ) {
503 410 return false;
504 411 }
505 412
@@ -533,9 +440,9 @@
533 440 * template, for all the registered widget types.
534 441 *
535 442 * @since 1.0.0
536 443 * @access public
537 - */
444 + */
538 445 public function render_widgets_content() {
539 446 foreach ( $this->get_widget_types() as $widget ) {
540 447 $widget->print_template();
541 448 }
@@ -550,9 +457,9 @@
550 457 * @since 1.3.0
551 458 * @access public
552 459 *
553 460 * @return array Registered widget types with settings keys for each widget.
554 - */
461 + */
555 462 public function get_widgets_frontend_settings_keys() {
556 463 $keys = [];
557 464
558 465 foreach ( $this->get_widget_types() as $widget_type_name => $widget_type ) {
@@ -566,63 +473,8 @@
566 473 return $keys;
567 474 }
568 475
569 476 /**
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 477 * Enqueue widgets scripts.
626 478 *
627 479 * Enqueue all the scripts defined as a dependency for each widget.
628 480 *
@@ -627,9 +479,9 @@
627 479 * Enqueue all the scripts defined as a dependency for each widget.
628 480 *
629 481 * @since 1.3.0
630 482 * @access public
631 - */
483 + */
632 484 public function enqueue_widgets_scripts() {
633 485 foreach ( $this->get_widget_types() as $widget ) {
634 486 $widget->enqueue_scripts();
635 487 }
@@ -634,14 +486,8 @@
634 486 $widget->enqueue_scripts();
635 487 }
636 488 }
637 489
638 - public function register_frontend_handlers() {
639 - foreach ( $this->get_widget_types() as $widget ) {
640 - $widget->register_frontend_handlers();
641 - }
642 - }
643 -
644 490 /**
645 491 * Enqueue widgets styles
646 492 *
647 493 * Enqueue all the styles defined as a dependency for each widget
@@ -716,9 +562,9 @@
716 562 * Initializing Elementor widgets manager.
717 563 *
718 564 * @since 1.0.0
719 565 * @access public
720 - */
566 + */
721 567 public function __construct() {
722 568 $this->require_files();
723 569
724 570 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
@@ -737,25 +583,6 @@
737 583 public function register_ajax_actions( Ajax $ajax_manager ) {
738 584 $ajax_manager->register_ajax_action( 'render_widget', [ $this, 'ajax_render_widget' ] );
739 585 $ajax_manager->register_ajax_action( 'editor_get_wp_widget_form', [ $this, 'ajax_get_wp_widget_form' ] );
740 586 $ajax_manager->register_ajax_action( 'get_widgets_config', [ $this, 'ajax_get_widget_types_controls_config' ] );
741 -
742 - $ajax_manager->register_ajax_action( 'get_widgets_default_value_translations', function ( array $data ) {
743 - return $this->ajax_get_widgets_default_value_translations( $data );
744 - } );
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 587 }
761 588 }