| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Home; |
| 3 |
|
| 4 |
use Elementor\Core\Admin\Menu\Admin_Menu_Manager; |
| 5 |
use Elementor\Core\Base\App as BaseApp; |
| 6 |
use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 7 |
use Elementor\Includes\EditorAssetsAPI; |
| 8 |
use Elementor\Settings; |
| 9 |
use Elementor\Plugin; |
| 10 |
use Elementor\Utils; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly. |
| 14 |
} |
| 15 |
|
| 16 |
class Module extends BaseApp { |
| 17 |
|
| 18 |
const PAGE_ID = 'home_screen'; |
| 19 |
|
| 20 |
public function get_name(): string { |
| 21 |
return 'home'; |
| 22 |
} |
| 23 |
|
| 24 |
public function __construct() { |
| 25 |
parent::__construct(); |
| 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 |
|
| 36 |
add_filter( 'elementor/document/urls/edit', [ $this, 'add_active_document_to_edit_link' ] ); |
| 37 |
} |
| 38 |
|
| 39 |
public function enqueue_home_screen_scripts(): void { |
| 40 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
$min_suffix = Utils::is_script_debug() ? '' : '.min'; |
| 45 |
|
| 46 |
wp_enqueue_script( |
| 47 |
'e-home-screen', |
| 48 |
ELEMENTOR_ASSETS_URL . 'js/e-home-screen' . $min_suffix . '.js', |
| 49 |
[ |
| 50 |
'react', |
| 51 |
'react-dom', |
| 52 |
'elementor-common', |
| 53 |
'elementor-v2-ui', |
| 54 |
], |
| 55 |
ELEMENTOR_VERSION, |
| 56 |
true |
| 57 |
); |
| 58 |
|
| 59 |
wp_set_script_translations( 'e-home-screen', 'elementor' ); |
| 60 |
|
| 61 |
wp_localize_script( |
| 62 |
'e-home-screen', |
| 63 |
'elementorHomeScreenData', |
| 64 |
$this->get_app_js_config() |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
public function is_experiment_active(): bool { |
| 69 |
return Plugin::$instance->experiments->is_feature_active( self::PAGE_ID ); |
| 70 |
} |
| 71 |
|
| 72 |
public function add_active_document_to_edit_link( $edit_link ) { |
| 73 |
$active_document = Utils::get_super_global_value( $_GET, 'active-document' ) ?? null; |
| 74 |
$active_tab = Utils::get_super_global_value( $_GET, 'active-tab' ) ?? null; |
| 75 |
|
| 76 |
if ( $active_document ) { |
| 77 |
$edit_link = add_query_arg( 'active-document', $active_document, $edit_link ); |
| 78 |
} |
| 79 |
|
| 80 |
if ( $active_tab ) { |
| 81 |
$edit_link = add_query_arg( 'active-tab', $active_tab, $edit_link ); |
| 82 |
} |
| 83 |
|
| 84 |
return $edit_link; |
| 85 |
} |
| 86 |
|
| 87 |
public static function get_experimental_data(): array { |
| 88 |
return [ |
| 89 |
'name' => static::PAGE_ID, |
| 90 |
'title' => esc_html__( 'Elementor Home Screen', 'elementor' ), |
| 91 |
'description' => esc_html__( 'Default Elementor menu page.', 'elementor' ), |
| 92 |
'hidden' => true, |
| 93 |
'release_status' => Experiments_Manager::RELEASE_STATUS_STABLE, |
| 94 |
'default' => Experiments_Manager::STATE_ACTIVE, |
| 95 |
]; |
| 96 |
} |
| 97 |
|
| 98 |
private function get_app_js_config(): array { |
| 99 |
$editor_assets_api = new EditorAssetsAPI( $this->get_api_config() ); |
| 100 |
$api = new API( $editor_assets_api ); |
| 101 |
|
| 102 |
return $api->get_home_screen_items(); |
| 103 |
} |
| 104 |
|
| 105 |
private function get_api_config(): array { |
| 106 |
return [ |
| 107 |
EditorAssetsAPI::ASSETS_DATA_URL => 'https://assets.elementor.com/home-screen/v1/home-screen.json', |
| 108 |
EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_home_screen_data', |
| 109 |
EditorAssetsAPI::ASSETS_DATA_KEY => 'home-screen', |
| 110 |
]; |
| 111 |
} |
| 112 |
|
| 113 |
public static function get_elementor_settings_page_id(): string { |
| 114 |
return Plugin::$instance->experiments->is_feature_active( self::PAGE_ID ) |
| 115 |
? 'elementor-settings' |
| 116 |
: Settings::PAGE_ID; |
| 117 |
} |
| 118 |
} |
| 119 |
|