| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\EditorOne; |
| 4 |
|
| 5 |
use Elementor\Core\Admin\EditorOneMenu\Elementor_One_Menu_Manager; |
| 6 |
use Elementor\Core\Base\Module as BaseModule; |
| 7 |
use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 8 |
use Elementor\Modules\EditorOne\Classes\Editor_One_Pointer; |
| 9 |
use Elementor\Modules\EditorOne\Classes\Menu_Config; |
| 10 |
use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 11 |
use Elementor\Modules\EditorOne\Components\Sidebar_Navigation_Handler; |
| 12 |
use Elementor\Modules\EditorOne\Components\Top_Bar_Handler; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
class Module extends BaseModule { |
| 18 |
|
| 19 |
const EXPERIMENT_NAME = 'e_editor_one'; |
| 20 |
|
| 21 |
const CUSTOM_REACT_APP_PAGES = [ |
| 22 |
'elementor-element-manager', |
| 23 |
]; |
| 24 |
|
| 25 |
public function get_name(): string { |
| 26 |
return 'editor-one'; |
| 27 |
} |
| 28 |
|
| 29 |
public static function is_active(): bool { |
| 30 |
return Menu_Config::is_elementor_home_menu_available(); |
| 31 |
} |
| 32 |
|
| 33 |
public static function get_experimental_data(): array { |
| 34 |
return [ |
| 35 |
'name' => static::EXPERIMENT_NAME, |
| 36 |
'title' => esc_html__( 'Editor one', 'elementor' ), |
| 37 |
'description' => esc_html__( 'General', 'elementor' ), |
| 38 |
'hidden' => true, |
| 39 |
'default' => Experiments_Manager::STATE_ACTIVE, |
| 40 |
'release_status' => Experiments_Manager::RELEASE_STATUS_STABLE, |
| 41 |
'mutable' => false, |
| 42 |
]; |
| 43 |
} |
| 44 |
|
| 45 |
public function __construct() { |
| 46 |
parent::__construct(); |
| 47 |
|
| 48 |
if ( is_admin() ) { |
| 49 |
$this->add_component( 'editor-one-menu-manager', new Elementor_One_Menu_Manager() ); |
| 50 |
$this->add_component( 'sidebar-navigation-handler', new Sidebar_Navigation_Handler() ); |
| 51 |
$this->add_component( 'top-bar-handler', new Top_Bar_Handler() ); |
| 52 |
$this->add_component( 'editor-one-pointer', new Editor_One_Pointer() ); |
| 53 |
} |
| 54 |
|
| 55 |
add_action( 'current_screen', function () { |
| 56 |
$menu_data_provider = Menu_Data_Provider::instance(); |
| 57 |
|
| 58 |
if ( ! $menu_data_provider->is_editor_one_admin_page() || ! static::is_active() ) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
add_action( 'admin_enqueue_scripts', function () { |
| 63 |
$this->enqueue_styles(); |
| 64 |
} ); |
| 65 |
} ); |
| 66 |
|
| 67 |
add_filter( 'elementor/admin-top-bar/is-active', function ( $is_active ) { |
| 68 |
return static::is_active() ? false : $is_active; |
| 69 |
} ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Check if current page has a custom React app that uses @elementor/ui |
| 74 |
* |
| 75 |
* @return bool |
| 76 |
*/ |
| 77 |
private function is_custom_react_app_page() { |
| 78 |
$current_screen = get_current_screen(); |
| 79 |
|
| 80 |
if ( ! $current_screen ) { |
| 81 |
return false; |
| 82 |
} |
| 83 |
|
| 84 |
foreach ( self::CUSTOM_REACT_APP_PAGES as $page_slug ) { |
| 85 |
if ( str_contains( $current_screen->id ?? '', $page_slug ) ) { |
| 86 |
return true; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Enqueue admin styles |
| 95 |
*/ |
| 96 |
private function enqueue_styles() { |
| 97 |
|
| 98 |
wp_enqueue_style( 'elementor-admin' ); |
| 99 |
|
| 100 |
wp_enqueue_style( |
| 101 |
'elementor-editor-one-common', |
| 102 |
$this->get_css_assets_url( 'editor-one-common' ), |
| 103 |
[ 'elementor-admin' ], |
| 104 |
ELEMENTOR_VERSION |
| 105 |
); |
| 106 |
|
| 107 |
if ( ! $this->is_custom_react_app_page() ) { |
| 108 |
wp_enqueue_style( |
| 109 |
'elementor-editor-one-elements', |
| 110 |
$this->get_css_assets_url( 'editor-one-elements' ), |
| 111 |
[ 'elementor-editor-one-common' ], |
| 112 |
ELEMENTOR_VERSION |
| 113 |
); |
| 114 |
|
| 115 |
wp_enqueue_style( |
| 116 |
'elementor-editor-one-tables', |
| 117 |
$this->get_css_assets_url( 'editor-one-tables' ), |
| 118 |
[ 'elementor-editor-one-common' ], |
| 119 |
ELEMENTOR_VERSION |
| 120 |
); |
| 121 |
} |
| 122 |
|
| 123 |
wp_enqueue_script( |
| 124 |
'editor-one-admin', |
| 125 |
$this->get_js_assets_url( 'editor-one-admin' ), |
| 126 |
[ 'jquery' ], |
| 127 |
ELEMENTOR_VERSION, |
| 128 |
true |
| 129 |
); |
| 130 |
} |
| 131 |
} |
| 132 |
|