| 1 |
<?php |
| 2 |
namespace Elementor\Modules\AdminTopBar; |
| 3 |
|
| 4 |
use Elementor\Core\Base\App as BaseApp; |
| 5 |
use Elementor\Core\Experiments\Manager; |
| 6 |
use Elementor\Utils; |
| 7 |
use Elementor\Plugin; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
class Module extends BaseApp { |
| 14 |
|
| 15 |
/** |
| 16 |
* @return bool |
| 17 |
*/ |
| 18 |
public static function is_active() { |
| 19 |
return is_admin(); |
| 20 |
} |
| 21 |
|
| 22 |
public static function get_experimental_data() { |
| 23 |
return [ |
| 24 |
'name' => 'admin-top-bar', |
| 25 |
'title' => esc_html__( 'Admin Top Bar', 'elementor' ), |
| 26 |
'description' => esc_html__( 'Adds a top bar to elementors pages in admin area.', 'elementor' ), |
| 27 |
'release_status' => Manager::RELEASE_STATUS_BETA, |
| 28 |
'new_site' => [ |
| 29 |
'default_active' => true, |
| 30 |
], |
| 31 |
]; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* @return string |
| 36 |
*/ |
| 37 |
public function get_name() { |
| 38 |
return 'admin-top-bar'; |
| 39 |
} |
| 40 |
|
| 41 |
private function render_admin_top_bar() { |
| 42 |
?> |
| 43 |
<div id="e-admin-top-bar-root"> |
| 44 |
</div> |
| 45 |
<?php |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Enqueue admin scripts |
| 50 |
*/ |
| 51 |
private function enqueue_scripts() { |
| 52 |
wp_enqueue_style( 'elementor-admin-top-bar-fonts', 'https://fonts.googleapis.com/css2?family=Roboto&display=swap', [], ELEMENTOR_VERSION ); |
| 53 |
|
| 54 |
wp_enqueue_style( 'elementor-admin-top-bar', $this->get_css_assets_url( 'admin-top-bar', null, 'default', true ), [], ELEMENTOR_VERSION ); |
| 55 |
|
| 56 |
wp_enqueue_script( 'elementor-admin-top-bar', $this->get_js_assets_url( 'admin-top-bar' ), [ |
| 57 |
'elementor-common', |
| 58 |
'react', |
| 59 |
'react-dom', |
| 60 |
], ELEMENTOR_VERSION, true ); |
| 61 |
|
| 62 |
$min_suffix = Utils::is_script_debug() ? '' : '.min'; |
| 63 |
|
| 64 |
wp_enqueue_script( 'tipsy', ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $min_suffix . '.js', [ |
| 65 |
'jquery', |
| 66 |
], '1.0.0', true ); |
| 67 |
|
| 68 |
$this->print_config(); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Module constructor. |
| 73 |
*/ |
| 74 |
public function __construct() { |
| 75 |
parent::__construct(); |
| 76 |
|
| 77 |
add_action( 'in_admin_header', function () { |
| 78 |
$this->render_admin_top_bar(); |
| 79 |
} ); |
| 80 |
|
| 81 |
add_action( 'admin_enqueue_scripts', function () { |
| 82 |
$this->enqueue_scripts(); |
| 83 |
} ); |
| 84 |
|
| 85 |
add_action( 'elementor/init', function () { |
| 86 |
$settings = []; |
| 87 |
$settings['is_administrator'] = current_user_can( 'manage_options' ); |
| 88 |
|
| 89 |
/** @var \Elementor\Core\Common\Modules\Connect\Apps\Library $library */ |
| 90 |
$library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' ); |
| 91 |
if ( $library ) { |
| 92 |
$settings = array_merge( $settings, [ |
| 93 |
'is_user_connected' => $library->is_connected(), |
| 94 |
'connect_url' => $library->get_admin_url( 'authorize' ), |
| 95 |
] ); |
| 96 |
} |
| 97 |
|
| 98 |
$this->set_settings( $settings ); |
| 99 |
|
| 100 |
do_action( 'elementor/admin-top-bar/init', $this ); |
| 101 |
}, 12 /* After component 'connect' register the apps */ ); |
| 102 |
} |
| 103 |
} |
| 104 |
|