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

151 lines 3.8 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\Core\Utils\Promotions\Filtered_Promotions_Manager;
5 use Elementor\Plugin;
6 use Elementor\Core\Base\App as BaseApp;
7 use Elementor\Core\Experiments\Manager;
8 use Elementor\Utils;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 class Module extends BaseApp {
15
16 /**
17 * @return bool
18 */
19 public static function is_active() {
20 return is_admin();
21 }
22
23 /**
24 * @return string
25 */
26 public function get_name() {
27 return 'admin-top-bar';
28 }
29
30 private function render_admin_top_bar() {
31 ?>
32 <div id="e-admin-top-bar-root">
33 </div>
34 <?php
35 }
36
37 /**
38 * Enqueue admin scripts
39 */
40 private function enqueue_scripts() {
41 wp_enqueue_style( 'elementor-admin-top-bar-fonts', 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap', [], ELEMENTOR_VERSION );
42
43 wp_enqueue_style( 'elementor-admin-top-bar', $this->get_css_assets_url( 'admin-top-bar', null, 'default', true ), [], ELEMENTOR_VERSION );
44
45 /**
46 * Before admin top bar enqueue scripts.
47 *
48 * Fires before Elementor admin top bar scripts are enqueued.
49 *
50 * @since 3.19.0
51 */
52 do_action( 'elementor/admin_top_bar/before_enqueue_scripts', $this );
53
54 wp_enqueue_script( 'elementor-admin-top-bar', $this->get_js_assets_url( 'admin-top-bar' ), [
55 'elementor-common',
56 'react',
57 'react-dom',
58 'tipsy',
59 ], ELEMENTOR_VERSION, true );
60
61 wp_set_script_translations( 'elementor-admin-top-bar', 'elementor' );
62
63 $min_suffix = Utils::is_script_debug() ? '' : '.min';
64
65 wp_enqueue_script( 'tipsy', ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $min_suffix . '.js', [
66 'jquery',
67 ], '1.0.0', true );
68
69 $this->print_config();
70 }
71
72 private function add_frontend_settings() {
73 $settings = [];
74 $settings['is_administrator'] = current_user_can( 'manage_options' );
75
76 // TODO: Find a better way to add apps page url to the admin top bar.
77 $settings['apps_url'] = admin_url( 'admin.php?page=elementor-apps' );
78 $settings['promotion'] = [
79 'text' => __( 'Upgrade Now', 'elementor' ),
80 'url' => 'https://go.elementor.com/wp-dash-admin-top-bar-upgrade/',
81 ];
82
83 $settings['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data(
84 $settings['promotion'],
85 'elementor/admin_top_bar/go_pro_promotion',
86 'url'
87 );
88
89 $current_screen = get_current_screen();
90
91 /** @var \Elementor\Core\Common\Modules\Connect\Apps\Library $library */
92 $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' );
93 if ( $library ) {
94 $settings = array_merge( $settings, [
95 'is_user_connected' => $library->is_connected(),
96 'connect_url' => $library->get_admin_url( 'authorize', [
97 'utm_source' => 'top-bar',
98 'utm_medium' => 'wp-dash',
99 'utm_campaign' => 'connect-account',
100 'utm_content' => $current_screen->id,
101 'source' => 'generic',
102 ] ),
103 ] );
104 }
105
106 $this->set_settings( $settings );
107
108 do_action( 'elementor/admin-top-bar/init', $this );
109 }
110
111 private function is_top_bar_active() {
112 $current_screen = get_current_screen();
113
114 if ( ! $current_screen ) {
115 return false;
116 }
117
118 $is_elementor_page = strpos( $current_screen->id ?? '', 'elementor' ) !== false;
119 $is_elementor_post_type_page = strpos( $current_screen->post_type ?? '', 'elementor' ) !== false;
120
121 return apply_filters(
122 'elementor/admin-top-bar/is-active',
123 $is_elementor_page || $is_elementor_post_type_page,
124 $current_screen
125 );
126 }
127
128 /**
129 * Module constructor.
130 */
131 public function __construct() {
132 parent::__construct();
133
134 add_action( 'current_screen', function () {
135 if ( ! $this->is_top_bar_active() ) {
136 return;
137 }
138
139 $this->add_frontend_settings();
140
141 add_action( 'in_admin_header', function () {
142 $this->render_admin_top_bar();
143 } );
144
145 add_action( 'admin_enqueue_scripts', function () {
146 $this->enqueue_scripts();
147 } );
148 } );
149 }
150 }
151