| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | namespace Elementor; |
| 4 | 3 | |
| 5 | 4 | use Elementor\Core\Admin\Menu\Admin_Menu_Manager; |
| 6 | 5 | use Elementor\Core\Wp_Api; |
| @@ -24,8 +23,9 @@ | ||
| 24 | 23 | use Elementor\Modules\System_Info\Module as System_Info_Module; |
| 25 | 24 | use Elementor\Data\Manager as Data_Manager; |
| 26 | 25 | use Elementor\Data\V2\Manager as Data_Manager_V2; |
| 27 | 26 | use Elementor\Core\Files\Uploads_Manager; |
| 27 | +use WP_REST_Request; | |
| 28 | 28 | |
| 29 | 29 | if ( ! defined( 'ABSPATH' ) ) { |
| 30 | 30 | exit; |
| 31 | 31 | } |
| @@ -38,9 +38,8 @@ | ||
| 38 | 38 | * |
| 39 | 39 | * @since 1.0.0 |
| 40 | 40 | */ |
| 41 | 41 | class Plugin { |
| 42 | - | |
| 43 | 42 | const ELEMENTOR_DEFAULT_POST_TYPES = [ 'page', 'post' ]; |
| 44 | 43 | |
| 45 | 44 | /** |
| 46 | 45 | * Instance. |
| @@ -824,12 +823,38 @@ | ||
| 824 | 823 | Compatibility::register_actions(); |
| 825 | 824 | |
| 826 | 825 | add_action( 'init', [ $this, 'init' ], 0 ); |
| 827 | 826 | add_action( 'rest_api_init', [ $this, 'on_rest_api_init' ], 9 ); |
| 827 | + add_filter( 'rest_pre_insert_post', [ $this, 'sanitize_post_data' ], 10, 2 ); | |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | final public static function get_title() { |
| 831 | 831 | return esc_html__( 'Elementor', 'elementor' ); |
| 832 | + } | |
| 833 | + | |
| 834 | + public function sanitize_post_data( $post, WP_REST_Request $request ) { | |
| 835 | + if ( current_user_can( 'unfiltered_html' ) ) { | |
| 836 | + return $post; | |
| 837 | + } | |
| 838 | + $request_body = json_decode( $request->get_body(), true ); | |
| 839 | + $meta = $request_body['meta']; | |
| 840 | + if ( is_null( $meta ) ) { | |
| 841 | + return $post; | |
| 842 | + } | |
| 843 | + $elementor_data = $meta['_elementor_data'] ?? []; | |
| 844 | + if ( is_string( $elementor_data ) ) { | |
| 845 | + $elementor_data = json_decode( $elementor_data ); | |
| 846 | + } | |
| 847 | + if ( is_null( $elementor_data ) ) { | |
| 848 | + return $post; | |
| 849 | + } | |
| 850 | + | |
| 851 | + $elementor_data = map_deep( $elementor_data, function ( $value ) { | |
| 852 | + return is_bool( $value ) || is_null( $value ) ? $value : wp_kses_post( $value ); | |
| 853 | + } ); | |
| 854 | + $request_body['meta']['_elementor_data'] = json_encode( $elementor_data ); | |
| 855 | + $request->set_body( json_encode( $request_body ) ); | |
| 856 | + return $post; | |
| 832 | 857 | } |
| 833 | 858 | } |
| 834 | 859 | |
| 835 | 860 | if ( ! defined( 'ELEMENTOR_TESTS' ) ) { |