| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Home; |
| 3 |
|
| 4 |
use Elementor\Core\Base\App as BaseApp; |
| 5 |
use Elementor\Includes\EditorAssetsAPI; |
| 6 |
use Elementor\Utils; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
class Module extends BaseApp { |
| 13 |
|
| 14 |
const PAGE_ID = 'home_screen'; |
| 15 |
|
| 16 |
public function get_name(): string { |
| 17 |
return 'home'; |
| 18 |
} |
| 19 |
|
| 20 |
public function __construct() { |
| 21 |
parent::__construct(); |
| 22 |
|
| 23 |
add_filter( 'elementor/document/urls/edit', [ $this, 'add_active_document_to_edit_link' ] ); |
| 24 |
} |
| 25 |
|
| 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 |
public function enqueue_home_screen_scripts(): void { |
| 36 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
$this->enqueue_fonts(); |
| 41 |
|
| 42 |
$min_suffix = Utils::is_script_debug() ? '' : '.min'; |
| 43 |
|
| 44 |
wp_enqueue_script( |
| 45 |
'e-home-screen', |
| 46 |
ELEMENTOR_ASSETS_URL . 'js/e-home-screen' . $min_suffix . '.js', |
| 47 |
[ |
| 48 |
'react', |
| 49 |
'react-dom', |
| 50 |
'elementor-common', |
| 51 |
'elementor-v2-ui', |
| 52 |
], |
| 53 |
ELEMENTOR_VERSION, |
| 54 |
true |
| 55 |
); |
| 56 |
|
| 57 |
wp_set_script_translations( 'e-home-screen', 'elementor' ); |
| 58 |
|
| 59 |
wp_localize_script( |
| 60 |
'e-home-screen', |
| 61 |
'elementorHomeScreenData', |
| 62 |
$this->get_app_js_config() |
| 63 |
); |
| 64 |
|
| 65 |
wp_enqueue_style( |
| 66 |
'e-home-screen', |
| 67 |
$this->get_css_assets_url( 'modules/home/e-home-screen' ), |
| 68 |
[], |
| 69 |
ELEMENTOR_VERSION |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
public function add_active_document_to_edit_link( $edit_link ) { |
| 74 |
$active_document = Utils::get_super_global_value( $_GET, 'active-document' ) ?? null; |
| 75 |
$active_tab = Utils::get_super_global_value( $_GET, 'active-tab' ) ?? null; |
| 76 |
|
| 77 |
if ( $active_document ) { |
| 78 |
$edit_link = add_query_arg( 'active-document', $active_document, $edit_link ); |
| 79 |
} |
| 80 |
|
| 81 |
if ( $active_tab ) { |
| 82 |
$edit_link = add_query_arg( 'active-tab', $active_tab, $edit_link ); |
| 83 |
} |
| 84 |
|
| 85 |
return $edit_link; |
| 86 |
} |
| 87 |
|
| 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; |
| 97 |
} |
| 98 |
|
| 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'; |
| 109 |
} |
| 110 |
} |
| 111 |
|