PluginProbe
Elementor Website Builder – more than just a page builder / 3.16.6
Elementor Website Builder – more than just a page builder v3.16.6
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 / admin-top-bar / module.php

module.php in Elementor Website Builder – more than just a page builder 3.16.6, at modules/admin-top-bar/module.php

131 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\AdminTopBar;
3
4 use Elementor\Plugin;
5 use Elementor\Core\Base\App as BaseApp;
6 use Elementor\Core\Experiments\Manager;
7 use Elementor\Utils;
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 /**
23 * @return string
24 */
25 public function get_name() {
26 return 'admin-top-bar';
27 }
28
29 private function render_admin_top_bar() {
30 ?>
31 <div id="e-admin-top-bar-root">
32 </div>
33 <?php
34 }
35
36 /**
37 * Enqueue admin scripts
38 */
39 private function enqueue_scripts() {
40 wp_enqueue_style( 'elementor-admin-top-bar-fonts', 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap', [], ELEMENTOR_VERSION );
41
42 wp_enqueue_style( 'elementor-admin-top-bar', $this->get_css_assets_url( 'admin-top-bar', null, 'default', true ), [], ELEMENTOR_VERSION );
43
44 wp_enqueue_script( 'elementor-admin-top-bar', $this->get_js_assets_url( 'admin-top-bar' ), [
45 'elementor-common',
46 'react',
47 'react-dom',
48 'tipsy',
49 ], ELEMENTOR_VERSION, true );
50
51 wp_set_script_translations( 'elementor-admin-top-bar', 'elementor' );
52
53 $min_suffix = Utils::is_script_debug() ? '' : '.min';
54
55 wp_enqueue_script( 'tipsy', ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $min_suffix . '.js', [
56 'jquery',
57 ], '1.0.0', true );
58
59 $this->print_config();
60 }
61
62 private function add_frontend_settings() {
63 $settings = [];
64 $settings['is_administrator'] = current_user_can( 'manage_options' );
65
66 // TODO: Find a better way to add apps page url to the admin top bar.
67 $settings['apps_url'] = admin_url( 'admin.php?page=elementor-apps' );
68
69 $current_screen = get_current_screen();
70
71 /** @var \Elementor\Core\Common\Modules\Connect\Apps\Library $library */
72 $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' );
73 if ( $library ) {
74 $settings = array_merge( $settings, [
75 'is_user_connected' => $library->is_connected(),
76 'connect_url' => $library->get_admin_url( 'authorize', [
77 'utm_source' => 'top-bar',
78 'utm_medium' => 'wp-dash',
79 'utm_campaign' => 'connect-account',
80 'utm_content' => $current_screen->id,
81 'source' => 'generic',
82 ] ),
83 ] );
84 }
85
86 $this->set_settings( $settings );
87
88 do_action( 'elementor/admin-top-bar/init', $this );
89 }
90
91 private function is_top_bar_active() {
92 $current_screen = get_current_screen();
93
94 if ( ! $current_screen ) {
95 return false;
96 }
97
98 $is_elementor_page = strpos( $current_screen->id ?? '', 'elementor' ) !== false;
99 $is_elementor_post_type_page = strpos( $current_screen->post_type ?? '', 'elementor' ) !== false;
100
101 return apply_filters(
102 'elementor/admin-top-bar/is-active',
103 $is_elementor_page || $is_elementor_post_type_page,
104 $current_screen
105 );
106 }
107
108 /**
109 * Module constructor.
110 */
111 public function __construct() {
112 parent::__construct();
113
114 add_action( 'current_screen', function () {
115 if ( ! $this->is_top_bar_active() ) {
116 return;
117 }
118
119 $this->add_frontend_settings();
120
121 add_action( 'in_admin_header', function () {
122 $this->render_admin_top_bar();
123 } );
124
125 add_action( 'admin_enqueue_scripts', function () {
126 $this->enqueue_scripts();
127 } );
128 } );
129 }
130 }
131