PluginProbe
Elementor Website Builder – more than just a page builder / 3.19.2
Elementor Website Builder – more than just a page builder v3.19.2
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.19.2, at modules/admin-top-bar/module.php

140 lines 3.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\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 /**
45 * Before admin top bar enqueue scripts.
46 *
47 * Fires before Elementor admin top bar scripts are enqueued.
48 *
49 * @since 3.19.0
50 */
51 do_action( 'elementor/admin_top_bar/before_enqueue_scripts', $this );
52
53 wp_enqueue_script( 'elementor-admin-top-bar', $this->get_js_assets_url( 'admin-top-bar' ), [
54 'elementor-common',
55 'react',
56 'react-dom',
57 'tipsy',
58 ], ELEMENTOR_VERSION, true );
59
60 wp_set_script_translations( 'elementor-admin-top-bar', 'elementor' );
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 private function add_frontend_settings() {
72 $settings = [];
73 $settings['is_administrator'] = current_user_can( 'manage_options' );
74
75 // TODO: Find a better way to add apps page url to the admin top bar.
76 $settings['apps_url'] = admin_url( 'admin.php?page=elementor-apps' );
77
78 $current_screen = get_current_screen();
79
80 /** @var \Elementor\Core\Common\Modules\Connect\Apps\Library $library */
81 $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' );
82 if ( $library ) {
83 $settings = array_merge( $settings, [
84 'is_user_connected' => $library->is_connected(),
85 'connect_url' => $library->get_admin_url( 'authorize', [
86 'utm_source' => 'top-bar',
87 'utm_medium' => 'wp-dash',
88 'utm_campaign' => 'connect-account',
89 'utm_content' => $current_screen->id,
90 'source' => 'generic',
91 ] ),
92 ] );
93 }
94
95 $this->set_settings( $settings );
96
97 do_action( 'elementor/admin-top-bar/init', $this );
98 }
99
100 private function is_top_bar_active() {
101 $current_screen = get_current_screen();
102
103 if ( ! $current_screen ) {
104 return false;
105 }
106
107 $is_elementor_page = strpos( $current_screen->id ?? '', 'elementor' ) !== false;
108 $is_elementor_post_type_page = strpos( $current_screen->post_type ?? '', 'elementor' ) !== false;
109
110 return apply_filters(
111 'elementor/admin-top-bar/is-active',
112 $is_elementor_page || $is_elementor_post_type_page,
113 $current_screen
114 );
115 }
116
117 /**
118 * Module constructor.
119 */
120 public function __construct() {
121 parent::__construct();
122
123 add_action( 'current_screen', function () {
124 if ( ! $this->is_top_bar_active() ) {
125 return;
126 }
127
128 $this->add_frontend_settings();
129
130 add_action( 'in_admin_header', function () {
131 $this->render_admin_top_bar();
132 } );
133
134 add_action( 'admin_enqueue_scripts', function () {
135 $this->enqueue_scripts();
136 } );
137 } );
138 }
139 }
140