| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | namespace Elementor; |
| 3 | 4 | |
| 4 | 5 | use Elementor\Core\Admin\Menu\Admin_Menu_Manager; |
| 5 | 6 | use Elementor\Core\Wp_Api; |
| @@ -38,10 +39,16 @@ | ||
| 38 | 39 | * |
| 39 | 40 | * @since 1.0.0 |
| 40 | 41 | */ |
| 41 | 42 | class Plugin { |
| 43 | + | |
| 42 | 44 | const ELEMENTOR_DEFAULT_POST_TYPES = [ 'page', 'post' ]; |
| 43 | 45 | |
| 46 | + private const SANITIZABLE_META_KEYS = [ | |
| 47 | + '_elementor_data', | |
| 48 | + '_elementor_page_settings', | |
| 49 | + ]; | |
| 50 | + | |
| 44 | 51 | /** |
| 45 | 52 | * Instance. |
| 46 | 53 | * |
| 47 | 54 | * Holds the plugin instance. |
| @@ -834,26 +841,34 @@ | ||
| 834 | 841 | public function sanitize_post_data( $post, WP_REST_Request $request ) { |
| 835 | 842 | if ( current_user_can( 'unfiltered_html' ) ) { |
| 836 | 843 | return $post; |
| 837 | 844 | } |
| 838 | - $request_body = json_decode( $request->get_body(), true ); | |
| 839 | - $meta = $request_body['meta']; | |
| 840 | - if ( is_null( $meta ) ) { | |
| 845 | + | |
| 846 | + $meta = $request->get_param( 'meta' ); | |
| 847 | + if ( empty( $meta ) || ! is_array( $meta ) ) { | |
| 841 | 848 | return $post; |
| 842 | 849 | } |
| 843 | - $elementor_data = $meta['_elementor_data'] ?? []; | |
| 844 | - if ( is_string( $elementor_data ) ) { | |
| 845 | - $elementor_data = json_decode( $elementor_data ); | |
| 850 | + | |
| 851 | + foreach ( self::SANITIZABLE_META_KEYS as $meta_key ) { | |
| 852 | + $elementor_data = $meta[ $meta_key ] ?? null; | |
| 853 | + if ( is_null( $elementor_data ) ) { | |
| 854 | + continue; | |
| 855 | + } | |
| 856 | + if ( is_string( $elementor_data ) ) { | |
| 857 | + $elementor_data = json_decode( $elementor_data, true ); | |
| 858 | + } | |
| 859 | + if ( empty( $elementor_data ) ) { | |
| 860 | + continue; | |
| 861 | + } | |
| 862 | + | |
| 863 | + $elementor_data = map_deep($elementor_data, function ( $value ) { | |
| 864 | + return is_bool( $value ) || is_null( $value ) ? $value : wp_kses_post( $value ); | |
| 865 | + }); | |
| 866 | + | |
| 867 | + $meta[ $meta_key ] = wp_json_encode( $elementor_data ); | |
| 846 | 868 | } |
| 847 | - if ( is_null( $elementor_data ) ) { | |
| 848 | - return $post; | |
| 849 | - } | |
| 850 | 869 | |
| 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 ) ); | |
| 870 | + $request->set_param( 'meta', $meta ); | |
| 856 | 871 | return $post; |
| 857 | 872 | } |
| 858 | 873 | } |
| 859 | 874 | |