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