PluginProbe
Elementor Website Builder – more than just a page builder / 4.2.3
Elementor Website Builder – more than just a page builder v4.2.3
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
elementor / modules / content-sanitizer / module.php

module.php in Elementor Website Builder – more than just a page builder 4.2.3, at modules/content-sanitizer/module.php

54 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\ContentSanitizer;
4
5 use Elementor\Core\Base\Module as BaseModule;
6 use Elementor\Plugin;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Module extends BaseModule {
13
14 const WIDGET_TO_SANITIZE = 'heading';
15
16 public function __construct() {
17 parent::__construct();
18
19 add_filter( 'elementor/document/save/data', [ $this, 'sanitize_content' ], 10, 2 );
20 }
21
22 public function get_name() {
23 return 'content-sanitizer';
24 }
25
26 public function sanitize_content( $data, $document ): array {
27 if ( current_user_can( 'manage_options' ) || empty( $data['elements'] ) ) {
28 return $data;
29 }
30
31 if ( ! $this->is_widget_present( $data ) ) {
32 return $data;
33 }
34
35 return Plugin::$instance->db->iterate_data( $data, function ( $element ) {
36 if ( $this->is_target_widget( $element ) ) {
37 $element['settings']['title'] = Plugin::$instance->widgets_manager->get_widget_types( self::WIDGET_TO_SANITIZE )->sanitize( $element['settings']['title'] );
38 }
39
40 return $element;
41 });
42 }
43
44 private function is_target_widget( $element ) {
45 return self::WIDGET_TO_SANITIZE === $element['widgetType'];
46 }
47
48 private function is_widget_present( array $elements ): bool {
49 $json = wp_json_encode( $elements );
50
51 return false !== strpos( $json, '"widgetType":"' . self::WIDGET_TO_SANITIZE . '"' );
52 }
53 }
54