| 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\Modules\EditorOne\Classes\Menu_Config; |
| 8 |
use Elementor\Modules\EditorOne\Classes\Menu_Data_Provider; |
| 9 |
use Elementor\Modules\EditorOne\Components\Sidebar_Navigation_Handler; |
| 10 |
use Elementor\Modules\EditorOne\Components\Top_Bar_Handler; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
class Module extends BaseModule { |
| 16 |
|
| 17 |
const CUSTOM_REACT_APP_PAGES = [ |
| 18 |
'elementor-element-manager', |
| 19 |
]; |
| 20 |
|
| 21 |
public function get_name(): string { |
| 22 |
return 'editor-one'; |
| 23 |
} |
| 24 |
|
| 25 |
public function __construct() { |
| 26 |
parent::__construct(); |
| 27 |
|
| 28 |
if ( is_admin() ) { |
| 29 |
$this->add_component( 'editor-one-menu-manager', new Elementor_One_Menu_Manager() ); |
| 30 |
$this->add_component( 'sidebar-navigation-handler', new Sidebar_Navigation_Handler() ); |
| 31 |
$this->add_component( 'top-bar-handler', new Top_Bar_Handler() ); |
| 32 |
} |
| 33 |
|
| 34 |
add_action( 'current_screen', function () { |
| 35 |
$menu_data_provider = Menu_Data_Provider::instance(); |
| 36 |
|
| 37 |
if ( ! $menu_data_provider->is_editor_one_admin_page() ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
add_action( 'admin_enqueue_scripts', function () { |
| 42 |
$this->enqueue_styles(); |
| 43 |
} ); |
| 44 |
} ); |
| 45 |
|
| 46 |
add_filter( 'elementor/admin-top-bar/is-active', function ( $_is_active ) { |
| 47 |
return false; |
| 48 |
} ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Check if current page has a custom React app that uses @elementor/ui |
| 53 |
* |
| 54 |
* @return bool |
| 55 |
*/ |
| 56 |
private function is_custom_react_app_page() { |
| 57 |
$current_screen = get_current_screen(); |
| 58 |
|
| 59 |
if ( ! $current_screen ) { |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
foreach ( self::CUSTOM_REACT_APP_PAGES as $page_slug ) { |
| 64 |
if ( str_contains( $current_screen->id ?? '', $page_slug ) ) { |
| 65 |
return true; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Enqueue admin styles |
| 74 |
*/ |
| 75 |
private function enqueue_styles() { |
| 76 |
|
| 77 |
wp_enqueue_style( 'elementor-admin' ); |
| 78 |
|
| 79 |
wp_enqueue_style( |
| 80 |
'elementor-editor-one-common', |
| 81 |
$this->get_css_assets_url( 'editor-one-common' ), |
| 82 |
[ 'elementor-admin' ], |
| 83 |
ELEMENTOR_VERSION |
| 84 |
); |
| 85 |
|
| 86 |
if ( ! $this->is_custom_react_app_page() ) { |
| 87 |
wp_enqueue_style( |
| 88 |
'elementor-editor-one-elements', |
| 89 |
$this->get_css_assets_url( 'editor-one-elements' ), |
| 90 |
[ 'elementor-editor-one-common' ], |
| 91 |
ELEMENTOR_VERSION |
| 92 |
); |
| 93 |
|
| 94 |
wp_enqueue_style( |
| 95 |
'elementor-editor-one-tables', |
| 96 |
$this->get_css_assets_url( 'editor-one-tables' ), |
| 97 |
[ 'elementor-editor-one-common' ], |
| 98 |
ELEMENTOR_VERSION |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
wp_enqueue_script( |
| 103 |
'editor-one-admin', |
| 104 |
$this->get_js_assets_url( 'editor-one-admin' ), |
| 105 |
[ 'jquery' ], |
| 106 |
ELEMENTOR_VERSION, |
| 107 |
true |
| 108 |
); |
| 109 |
} |
| 110 |
} |
| 111 |
|