| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\Home; |
| 3 | 3 | |
| 4 | +use Elementor\Core\Admin\Menu\Admin_Menu_Manager; | |
| 4 | 5 | use Elementor\Core\Base\App as BaseApp; |
| 5 | -use Elementor\Includes\EditorAssetsAPI; | |
| 6 | +use Elementor\Core\Experiments\Manager as Experiments_Manager; | |
| 6 | 7 | use Elementor\Settings; |
| 7 | 8 | use Elementor\Plugin; |
| 8 | 9 | use Elementor\Utils; |
| 9 | 10 | |
| @@ -21,8 +22,19 @@ | ||
| 21 | 22 | |
| 22 | 23 | public function __construct() { |
| 23 | 24 | parent::__construct(); |
| 24 | 25 | |
| 26 | + $this->register_layout_experiment(); | |
| 27 | + | |
| 28 | + if ( ! $this->is_experiment_active() ) { | |
| 29 | + return; | |
| 30 | + } | |
| 31 | + | |
| 32 | + add_action( 'elementor/admin/menu/after_register', function ( Admin_Menu_Manager $admin_menu, array $hooks ) { | |
| 33 | + $hook_suffix = 'toplevel_page_elementor'; | |
| 34 | + add_action( "admin_print_scripts-{$hook_suffix}", [ $this, 'enqueue_home_screen_scripts' ] ); | |
| 35 | + }, 10, 2 ); | |
| 36 | + | |
| 25 | 37 | add_filter( 'elementor/document/urls/edit', [ $this, 'add_active_document_to_edit_link' ] ); |
| 26 | 38 | } |
| 27 | 39 | |
| 28 | 40 | public function enqueue_home_screen_scripts(): void { |
| @@ -51,15 +63,12 @@ | ||
| 51 | 63 | 'e-home-screen', |
| 52 | 64 | 'elementorHomeScreenData', |
| 53 | 65 | $this->get_app_js_config() |
| 54 | 66 | ); |
| 67 | + } | |
| 55 | 68 | |
| 56 | - wp_enqueue_style( | |
| 57 | - 'e-home-screen', | |
| 58 | - $this->get_css_assets_url( 'modules/home/e-home-screen' ), | |
| 59 | - [], | |
| 60 | - ELEMENTOR_VERSION | |
| 61 | - ); | |
| 69 | + public function is_experiment_active(): bool { | |
| 70 | + return Plugin::$instance->experiments->is_feature_active( self::PAGE_ID ); | |
| 62 | 71 | } |
| 63 | 72 | |
| 64 | 73 | public function add_active_document_to_edit_link( $edit_link ) { |
| 65 | 74 | $active_document = Utils::get_super_global_value( $_GET, 'active-document' ) ?? null; |
| @@ -75,25 +84,24 @@ | ||
| 75 | 84 | |
| 76 | 85 | return $edit_link; |
| 77 | 86 | } |
| 78 | 87 | |
| 79 | - private function get_app_js_config(): array { | |
| 80 | - $editor_assets_api = new EditorAssetsAPI( $this->get_api_config() ); | |
| 81 | - $api = new API( $editor_assets_api ); | |
| 82 | - | |
| 83 | - $config = $api->get_home_screen_items(); | |
| 84 | - | |
| 85 | - return $config; | |
| 88 | + private function register_layout_experiment(): void { | |
| 89 | + Plugin::$instance->experiments->add_feature( [ | |
| 90 | + 'name' => static::PAGE_ID, | |
| 91 | + 'title' => esc_html__( 'Elementor Home Screen', 'elementor' ), | |
| 92 | + 'description' => esc_html__( 'Default Elementor menu page.', 'elementor' ), | |
| 93 | + 'hidden' => true, | |
| 94 | + 'default' => Experiments_Manager::STATE_ACTIVE, | |
| 95 | + ] ); | |
| 86 | 96 | } |
| 87 | 97 | |
| 88 | - private function get_api_config(): array { | |
| 89 | - return [ | |
| 90 | - EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/home-screen/v1/home-screen.json', | |
| 91 | - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_home_screen_data', | |
| 92 | - EditorAssetsAPI::ASSETS_DATA_KEY => 'home-screen', | |
| 93 | - ]; | |
| 98 | + private function get_app_js_config(): array { | |
| 99 | + return API::get_home_screen_items(); | |
| 94 | 100 | } |
| 95 | 101 | |
| 96 | 102 | public static function get_elementor_settings_page_id(): string { |
| 97 | - return 'elementor-settings'; | |
| 103 | + return Plugin::$instance->experiments->is_feature_active( self::PAGE_ID ) | |
| 104 | + ? 'elementor-settings' | |
| 105 | + : Settings::PAGE_ID; | |
| 98 | 106 | } |
| 99 | 107 | } |