-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
admin-menu.php
94 lines (80 loc) · 2.33 KB
/
admin-menu.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* WP Admin Menus changes to match WordPress 5.9
*
* @package gutenberg
*/
/**
* Removes legacy pages from FSE themes.
*/
function gutenberg_remove_legacy_pages() {
if ( ! wp_is_block_theme() ) {
return;
}
global $submenu;
if ( ! isset( $submenu['themes.php'] ) ) {
return;
}
$indexes_to_remove = array();
$customize_menu = null;
foreach ( $submenu['themes.php'] as $index => $menu_item ) {
if ( false !== strpos( $menu_item[2], 'customize.php' ) ) {
$indexes_to_remove[] = $index;
$customize_menu = $menu_item;
}
if ( false !== strpos( $menu_item[2], 'site-editor.php' ) ) {
$indexes_to_remove[] = $index;
}
if ( false !== strpos( $menu_item[2], 'gutenberg-widgets' ) ) {
$indexes_to_remove[] = $index;
}
}
foreach ( $indexes_to_remove as $index ) {
unset( $submenu['themes.php'][ $index ] );
}
// Add Customizer back but with a new sub-menu position when a site requires this feature.
if ( gutenberg_site_requires_customizer() && $customize_menu ) {
$submenu['themes.php'][20] = $customize_menu;
}
}
add_action( 'admin_menu', 'gutenberg_remove_legacy_pages' );
/**
* Removes legacy adminbar items from FSE themes.
*
* @param WP_Admin_Bar $wp_admin_bar The admin-bar instance.
*/
function gutenberg_adminbar_items( $wp_admin_bar ) {
// Early exit if not a block theme.
if ( ! wp_is_block_theme() ) {
return;
}
// Remove customizer link, if this site does not rely on them for plugins or theme options.
if ( ! gutenberg_site_requires_customizer() ) {
$wp_admin_bar->remove_node( 'customize' );
$wp_admin_bar->remove_node( 'customize-background' );
$wp_admin_bar->remove_node( 'customize-header' );
$wp_admin_bar->remove_node( 'widgets' );
}
// Add site-editor link.
if ( ! is_admin() && current_user_can( 'edit_theme_options' ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'site-editor',
'title' => __( 'Edit site', 'gutenberg' ),
'href' => admin_url( 'themes.php?page=gutenberg-edit-site' ),
)
);
}
}
add_action( 'admin_bar_menu', 'gutenberg_adminbar_items', 50 );
/**
* Check if any plugin, or theme features, are using the Customizer.
*
* @return bool A boolean value indicating if Customizer support is needed.
*/
function gutenberg_site_requires_customizer() {
if ( has_action( 'customize_register' ) ) {
return true;
}
return false;
}