| @@ -1,9 +1,11 @@ | ||
| 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; | |
| 7 | +use Elementor\Plugin; | |
| 6 | 8 | use Elementor\Utils; |
| 7 | 9 | |
| 8 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | 11 | exit; // Exit if accessed directly. |
| @@ -19,27 +21,27 @@ | ||
| 19 | 21 | |
| 20 | 22 | public function __construct() { |
| 21 | 23 | parent::__construct(); |
| 22 | 24 | |
| 25 | + $this->register_layout_experiment(); | |
| 26 | + | |
| 27 | + if ( ! $this->is_experiment_active() ) { | |
| 28 | + return; | |
| 29 | + } | |
| 30 | + | |
| 31 | + add_action( 'elementor/admin/menu/after_register', function ( Admin_Menu_Manager $admin_menu, array $hooks ) { | |
| 32 | + $hook_suffix = 'toplevel_page_elementor'; | |
| 33 | + add_action( "admin_print_scripts-{$hook_suffix}", [ $this, 'enqueue_home_screen_scripts' ] ); | |
| 34 | + }, 10, 2 ); | |
| 35 | + | |
| 23 | 36 | add_filter( 'elementor/document/urls/edit', [ $this, 'add_active_document_to_edit_link' ] ); |
| 24 | 37 | } |
| 25 | 38 | |
| 26 | - public function enqueue_fonts(): void { | |
| 27 | - wp_enqueue_style( | |
| 28 | - 'elementor-home-screen-fonts', | |
| 29 | - 'https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap', | |
| 30 | - [], | |
| 31 | - ELEMENTOR_VERSION | |
| 32 | - ); | |
| 33 | - } | |
| 34 | - | |
| 35 | 39 | public function enqueue_home_screen_scripts(): void { |
| 36 | 40 | if ( ! current_user_can( 'manage_options' ) ) { |
| 37 | 41 | return; |
| 38 | 42 | } |
| 39 | 43 | |
| 40 | - $this->enqueue_fonts(); | |
| 41 | - | |
| 42 | 44 | $min_suffix = Utils::is_script_debug() ? '' : '.min'; |
| 43 | 45 | |
| 44 | 46 | wp_enqueue_script( |
| 45 | 47 | 'e-home-screen', |
| @@ -60,51 +62,34 @@ | ||
| 60 | 62 | 'e-home-screen', |
| 61 | 63 | 'elementorHomeScreenData', |
| 62 | 64 | $this->get_app_js_config() |
| 63 | 65 | ); |
| 66 | + } | |
| 64 | 67 | |
| 65 | - wp_enqueue_style( | |
| 66 | - 'e-home-screen', | |
| 67 | - $this->get_css_assets_url( 'modules/home/e-home-screen' ), | |
| 68 | - [], | |
| 69 | - ELEMENTOR_VERSION | |
| 70 | - ); | |
| 68 | + public function is_experiment_active(): bool { | |
| 69 | + return Plugin::$instance->experiments->is_feature_active( self::PAGE_ID ); | |
| 71 | 70 | } |
| 72 | 71 | |
| 73 | 72 | public function add_active_document_to_edit_link( $edit_link ) { |
| 74 | 73 | $active_document = Utils::get_super_global_value( $_GET, 'active-document' ) ?? null; |
| 75 | - $active_tab = Utils::get_super_global_value( $_GET, 'active-tab' ) ?? null; | |
| 76 | 74 | |
| 77 | 75 | if ( $active_document ) { |
| 78 | - $edit_link = add_query_arg( 'active-document', $active_document, $edit_link ); | |
| 76 | + return add_query_arg( 'active-document', $active_document, $edit_link ); | |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | - if ( $active_tab ) { | |
| 82 | - $edit_link = add_query_arg( 'active-tab', $active_tab, $edit_link ); | |
| 83 | - } | |
| 84 | - | |
| 85 | 79 | return $edit_link; |
| 86 | 80 | } |
| 87 | 81 | |
| 88 | - private function get_app_js_config(): array { | |
| 89 | - $editor_assets_api = new EditorAssetsAPI( $this->get_api_config() ); | |
| 90 | - $api = new API( $editor_assets_api ); | |
| 91 | - | |
| 92 | - $config = $api->get_home_screen_items(); | |
| 93 | - | |
| 94 | - $config['wpRestNonce'] = wp_create_nonce( 'wp_rest' ); | |
| 95 | - | |
| 96 | - return $config; | |
| 82 | + private function register_layout_experiment(): void { | |
| 83 | + Plugin::$instance->experiments->add_feature( [ | |
| 84 | + 'name' => static::PAGE_ID, | |
| 85 | + 'title' => esc_html__( 'Elementor Home Screen', 'elementor' ), | |
| 86 | + 'description' => esc_html__( 'Default Elementor menu page.', 'elementor' ), | |
| 87 | + 'hidden' => true, | |
| 88 | + 'default' => Experiments_Manager::STATE_INACTIVE, | |
| 89 | + ] ); | |
| 97 | 90 | } |
| 98 | 91 | |
| 99 | - private function get_api_config(): array { | |
| 100 | - return [ | |
| 101 | - EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/home-screen/v1/home-screen.json', | |
| 102 | - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_home_screen_data', | |
| 103 | - EditorAssetsAPI::ASSETS_DATA_KEY => 'home-screen', | |
| 104 | - ]; | |
| 105 | - } | |
| 106 | - | |
| 107 | - public static function get_elementor_settings_page_id(): string { | |
| 108 | - return 'elementor-settings'; | |
| 92 | + private function get_app_js_config(): array { | |
| 93 | + return API::get_home_screen_items(); | |
| 109 | 94 | } |
| 110 | 95 | } |