PluginProbe
Elementor Website Builder – more than just a page builder / 3.21.0-beta2
Elementor Website Builder – more than just a page builder v3.21.0-beta2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / home / module.php

module.php in Elementor Website Builder – more than just a page builder 3.21.0-beta2, at modules/home/module.php

96 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Plugin;
8 use Elementor\Utils;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 class Module extends BaseApp {
15
16 const PAGE_ID = 'home_screen';
17
18 public function get_name(): string {
19 return 'home';
20 }
21
22 public function __construct() {
23 parent::__construct();
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
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
75 if ( $active_document ) {
76 return add_query_arg( 'active-document', $active_document, $edit_link );
77 }
78
79 return $edit_link;
80 }
81
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 ] );
90 }
91
92 private function get_app_js_config(): array {
93 return API::get_home_screen_items();
94 }
95 }
96