-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-admin-bar.php
More file actions
62 lines (54 loc) · 1.7 KB
/
Copy pathclass-admin-bar.php
File metadata and controls
62 lines (54 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* The edit-mode toggle.
*
* Deliberately hung off the admin bar, NOT the admin menu — it would be absurd
* (and fragile) for the toggle to live inside the very menu it rearranges and
* can hide. The toggle just flips a URL param; nothing is persisted.
*
* @package Maestro
*/
namespace Maestro;
defined( 'ABSPATH' ) || exit;
/**
* Registers the edit-mode toggle node in the WordPress admin bar.
*
* @package Maestro
*/
class Admin_Bar {
/**
* Register the admin-bar hook.
*/
public function __construct() {
add_action( 'admin_bar_menu', array( $this, 'node' ), 100 );
}
/**
* Add the toggle node.
*
* @param \WP_Admin_Bar $bar Admin bar instance.
* @return void
*/
public function node( $bar ) {
if ( ! is_admin() || ! current_user_can( capability() ) ) {
return;
}
$editing = is_edit_mode();
// Toggle target: current URL with maestro_edit added or removed.
$current = remove_query_arg( 'maestro_edit' );
$href = $editing ? $current : add_query_arg( 'maestro_edit', '1', $current );
$bar->add_node(
array(
'id' => 'maestro-toggle',
'title' => $editing
? '<span class="ab-icon dashicons dashicons-exit" style="margin-top:2px;"></span><span class="maestro-ab-label">' . esc_html__( 'Exit Menu Editor', 'maestro-menu-editor' ) . '</span>'
: '<span class="ab-icon dashicons dashicons-edit" style="margin-top:2px;"></span><span class="maestro-ab-label">' . esc_html__( 'Edit Menu', 'maestro-menu-editor' ) . '</span>',
'href' => esc_url( $href ),
'meta' => array(
'title' => $editing
? esc_attr__( 'Exit Menu Editor', 'maestro-menu-editor' )
: esc_attr__( 'Edit Admin Menu', 'maestro-menu-editor' ),
),
)
);
}
}