| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | namespace Elementor; |
| 4 | 3 | |
| 4 | +use Elementor\Container\Container; | |
| 5 | +use ElementorDeps\DI\Container as DIContainer; | |
| 5 | 6 | use Elementor\Core\Admin\Menu\Admin_Menu_Manager; |
| 6 | 7 | use Elementor\Core\Wp_Api; |
| 7 | 8 | use Elementor\Core\Admin\Admin; |
| 8 | 9 | use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| @@ -24,9 +25,12 @@ | ||
| 24 | 25 | use Elementor\Modules\System_Info\Module as System_Info_Module; |
| 25 | 26 | use Elementor\Data\Manager as Data_Manager; |
| 26 | 27 | use Elementor\Data\V2\Manager as Data_Manager_V2; |
| 27 | 28 | use Elementor\Core\Files\Uploads_Manager; |
| 28 | -use WP_REST_Request; | |
| 29 | +use ElementorDeps\DI\{ | |
| 30 | + DependencyException, | |
| 31 | + NotFoundException, | |
| 32 | +}; | |
| 29 | 33 | |
| 30 | 34 | if ( ! defined( 'ABSPATH' ) ) { |
| 31 | 35 | exit; |
| 32 | 36 | } |
| @@ -39,16 +43,10 @@ | ||
| 39 | 43 | * |
| 40 | 44 | * @since 1.0.0 |
| 41 | 45 | */ |
| 42 | 46 | class Plugin { |
| 43 | - | |
| 44 | 47 | const ELEMENTOR_DEFAULT_POST_TYPES = [ 'page', 'post' ]; |
| 45 | 48 | |
| 46 | - private const SANITIZABLE_META_KEYS = [ | |
| 47 | - '_elementor_data', | |
| 48 | - '_elementor_page_settings', | |
| 49 | - ]; | |
| 50 | - | |
| 51 | 49 | /** |
| 52 | 50 | * Instance. |
| 53 | 51 | * |
| 54 | 52 | * Holds the plugin instance. |
| @@ -551,8 +549,16 @@ | ||
| 551 | 549 | */ |
| 552 | 550 | public $assets_loader; |
| 553 | 551 | |
| 554 | 552 | /** |
| 553 | + * Container instance for managing dependencies. | |
| 554 | + * | |
| 555 | + * @since 3.24.0 | |
| 556 | + * @var DIContainer | |
| 557 | + */ | |
| 558 | + private $container; | |
| 559 | + | |
| 560 | + /** | |
| 555 | 561 | * Clone. |
| 556 | 562 | * |
| 557 | 563 | * Disable class cloning and throw an error on object clone. |
| 558 | 564 | * |
| @@ -613,9 +619,34 @@ | ||
| 613 | 619 | |
| 614 | 620 | return self::$instance; |
| 615 | 621 | } |
| 616 | 622 | |
| 623 | + public function initialize_container() { | |
| 624 | + Container::initialize_instance(); | |
| 625 | + | |
| 626 | + $this->container = Container::get_instance(); | |
| 627 | + } | |
| 628 | + | |
| 617 | 629 | /** |
| 630 | + * Get the Elementor container or resolve a dependency. | |
| 631 | + * | |
| 632 | + * @param string|null $dependency The dependency to resolve. If null, returns the container instance. | |
| 633 | + * | |
| 634 | + * @return mixed The container instance or the resolved dependency. | |
| 635 | + * | |
| 636 | + * @throws \InvalidArgumentException The name parameter must be of type string. | |
| 637 | + * @throws DependencyException Error while resolving the entry. | |
| 638 | + * @throws NotFoundException No entry found for the given name. | |
| 639 | + */ | |
| 640 | + public function elementor_container( $dependency = null ) { | |
| 641 | + if ( is_null( $dependency ) ) { | |
| 642 | + return $this->container; | |
| 643 | + } | |
| 644 | + | |
| 645 | + return $this->container->make( $dependency ); | |
| 646 | + } | |
| 647 | + | |
| 648 | + /** | |
| 618 | 649 | * Init. |
| 619 | 650 | * |
| 620 | 651 | * Initialize Elementor Plugin. Register Elementor support for all the |
| 621 | 652 | * supported post types and initialize Elementor components. |
| @@ -830,49 +861,17 @@ | ||
| 830 | 861 | Compatibility::register_actions(); |
| 831 | 862 | |
| 832 | 863 | add_action( 'init', [ $this, 'init' ], 0 ); |
| 833 | 864 | add_action( 'rest_api_init', [ $this, 'on_rest_api_init' ], 9 ); |
| 834 | - add_filter( 'rest_pre_insert_post', [ $this, 'sanitize_post_data' ], 10, 2 ); | |
| 835 | 865 | } |
| 836 | 866 | |
| 837 | 867 | final public static function get_title() { |
| 838 | 868 | return esc_html__( 'Elementor', 'elementor' ); |
| 839 | 869 | } |
| 840 | - | |
| 841 | - public function sanitize_post_data( $post, WP_REST_Request $request ) { | |
| 842 | - if ( current_user_can( 'unfiltered_html' ) ) { | |
| 843 | - return $post; | |
| 844 | - } | |
| 845 | - | |
| 846 | - $meta = $request->get_param( 'meta' ); | |
| 847 | - if ( empty( $meta ) || ! is_array( $meta ) ) { | |
| 848 | - return $post; | |
| 849 | - } | |
| 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 ); | |
| 868 | - } | |
| 869 | - | |
| 870 | - $request->set_param( 'meta', $meta ); | |
| 871 | - return $post; | |
| 872 | - } | |
| 873 | 870 | } |
| 874 | 871 | |
| 875 | 872 | if ( ! defined( 'ELEMENTOR_TESTS' ) ) { |
| 876 | 873 | // In tests we run the instance manually. |
| 877 | - Plugin::instance(); | |
| 874 | + $plugin_instance = Plugin::instance(); | |
| 875 | + | |
| 876 | + $plugin_instance->initialize_container(); | |
| 878 | 877 | } |