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

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

128 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Modules\AdminBar;
3
4 use Elementor\Core\Base\Document;
5 use Elementor\Core\Base\App as BaseApp;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class Module extends BaseApp {
12 /**
13 * @var Document[]
14 */
15 private $documents = [];
16
17 /**
18 * @return bool
19 */
20 public static function is_active() {
21 return is_admin_bar_showing();
22 }
23
24 /**
25 * @return string
26 */
27 public function get_name() {
28 return 'admin-bar';
29 }
30
31 /**
32 * Collect the documents that was rendered in the current page.
33 *
34 * @param Document $document
35 * @param $is_excerpt
36 */
37 public function add_document_to_admin_bar( Document $document, $is_excerpt ) {
38 if (
39 $is_excerpt ||
40 ! $document::get_property( 'show_on_admin_bar' ) ||
41 ! $document->is_editable_by_current_user()
42 ) {
43 return;
44 }
45
46 $this->documents[ $document->get_main_id() ] = $document;
47 }
48
49 /**
50 * Scripts for module.
51 */
52 public function enqueue_scripts() {
53 if ( empty( $this->documents ) ) {
54 return;
55 }
56
57 wp_enqueue_script(
58 'elementor-admin-bar',
59 $this->get_js_assets_url( 'admin-bar' ),
60 [ 'elementor-common' ],
61 ELEMENTOR_VERSION,
62 true
63 );
64
65 $this->print_config( 'elementor-admin-bar' );
66 }
67
68 /**
69 * Creates admin bar menu items config.
70 *
71 * @return array
72 */
73 public function get_init_settings() {
74 $settings = [];
75
76 if ( ! empty( $this->documents ) ) {
77 $settings['elementor_edit_page'] = $this->get_edit_button_config();
78 }
79
80 /**
81 * Register admin_bar config to parse later in the frontend and add to the admin bar with JS
82 *
83 * @param array $settings the admin_bar config
84 *
85 * @since 3.0.0
86 */
87 return apply_filters( 'elementor/frontend/admin_bar/settings', $settings );
88 }
89
90 /**
91 * Creates the config for 'Edit with elementor' menu item.
92 *
93 * @return array
94 */
95 private function get_edit_button_config() {
96 $queried_object_id = get_queried_object_id();
97 $href = null;
98
99 if ( is_singular() && isset( $this->documents[ $queried_object_id ] ) ) {
100 $href = $this->documents[ $queried_object_id ]->get_edit_url();
101
102 unset( $this->documents[ $queried_object_id ] );
103 }
104
105 return [
106 'id' => 'elementor_edit_page',
107 'title' => __( 'Edit with Elementor', 'elementor' ),
108 'href' => $href,
109 'children' => array_map( function ( $document ) {
110 return [
111 'id' => "elementor_edit_doc_{$document->get_main_id()}",
112 'title' => $document->get_post()->post_title,
113 'sub_title' => $document::get_title(),
114 'href' => $document->get_edit_url(),
115 ];
116 }, $this->documents ),
117 ];
118 }
119
120 /**
121 * Module constructor.
122 */
123 public function __construct() {
124 add_action( 'elementor/frontend/get_builder_content', [ $this, 'add_document_to_admin_bar' ], 10, 2 );
125 add_action( 'wp_footer', [ $this, 'enqueue_scripts' ] );
126 }
127 }
128