balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

module.php (2757B)


      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 
      8 if ( ! defined( 'ABSPATH' ) ) {
      9 	exit; // Exit if accessed directly.
     10 }
     11 
     12 class Module extends BaseApp {
     13 
     14 	/**
     15 	 * @return bool
     16 	 */
     17 	public static function is_active() {
     18 		return is_admin();
     19 	}
     20 
     21 	public static function get_experimental_data() {
     22 		return [
     23 			'name' => 'admin-top-bar',
     24 			'title' => esc_html__( 'Admin Top Bar', 'elementor' ),
     25 			'description' => esc_html__( 'Adds a top bar to elementors pages in admin area.', 'elementor' ),
     26 			'release_status' => Manager::RELEASE_STATUS_BETA,
     27 			'new_site' => [
     28 				'default_active' => true,
     29 			],
     30 		];
     31 	}
     32 
     33 	/**
     34 	 * @return string
     35 	 */
     36 	public function get_name() {
     37 		return 'admin-top-bar';
     38 	}
     39 
     40 	private function render_admin_top_bar() {
     41 		?>
     42 		<div id="e-admin-top-bar-root">
     43 		</div>
     44 		<?php
     45 	}
     46 	protected function get_init_settings() {
     47 		return [
     48 			'is_administrator' => current_user_can( 'manage_options' ),
     49 		];
     50 	}
     51 
     52 	/**
     53 	 * Enqueue admin scripts
     54 	 */
     55 	private function enqueue_scripts() {
     56 		wp_enqueue_style( 'elementor-admin-top-bar-fonts', 'https://fonts.googleapis.com/css2?family=Roboto&display=swap', [], ELEMENTOR_VERSION );
     57 
     58 		wp_enqueue_style( 'elementor-admin-top-bar', $this->get_css_assets_url( 'admin-top-bar', null, 'default', true ), [], ELEMENTOR_VERSION );
     59 
     60 		wp_enqueue_script( 'elementor-admin-top-bar', $this->get_js_assets_url( 'admin-top-bar' ), [
     61 			'elementor-common',
     62 			'react',
     63 			'react-dom',
     64 		], ELEMENTOR_VERSION, true );
     65 
     66 		$min_suffix = Utils::is_script_debug() ? '' : '.min';
     67 
     68 		wp_enqueue_script( 'tipsy', ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $min_suffix . '.js', [
     69 			'jquery',
     70 		], '1.0.0', true );
     71 
     72 		$this->print_config();
     73 	}
     74 
     75 	/**
     76 	 * Register dashboard widgets.
     77 	 *
     78 	 * Adds a new Elementor widgets to WordPress dashboard.
     79 	 *
     80 	 * Fired by `wp_dashboard_setup` action.
     81 	 *
     82 	 * @since 1.9.0
     83 	 * @access public
     84 	 */
     85 	public function register_dashboard_widgets() {
     86 		wp_add_dashboard_widget( 'e-dashboard-widget-admin-top-bar', __( 'Elementor Top Bar', 'elementor' ), function () {} );
     87 	}
     88 
     89 	/**
     90 	 * Module constructor.
     91 	 */
     92 	public function __construct() {
     93 		parent::__construct();
     94 
     95 		add_action( 'current_screen', function () {
     96 			$current_screen = get_current_screen();
     97 
     98 			// Only in elementor based pages.
     99 			if ( ! $current_screen || ! strstr( $current_screen->id, 'elementor' ) ) {
    100 				return;
    101 			}
    102 
    103 			add_action( 'in_admin_header', function () {
    104 				$this->render_admin_top_bar();
    105 			} );
    106 
    107 			add_action( 'admin_enqueue_scripts', function () {
    108 				$this->enqueue_scripts();
    109 			} );
    110 
    111 			add_action( 'wp_dashboard_setup', function () {
    112 				$this->register_dashboard_widgets();
    113 			} );
    114 		} );
    115 	}
    116 }