| 1 |
<?php |
| 2 |
/** |
| 3 |
* Site Editor Page - Integration file for admin menu registration. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Register site editor admin page in WordPress admin menu. |
| 10 |
*/ |
| 11 |
function gutenberg_register_site_editor_admin_page() { |
| 12 |
add_submenu_page( |
| 13 |
'nothing', |
| 14 |
__( 'Site Editor', 'gutenberg' ), |
| 15 |
__( 'Site Editor', 'gutenberg' ), |
| 16 |
'manage_options', |
| 17 |
'site-editor-v2', |
| 18 |
'gutenberg_site_editor_v2_render_page' |
| 19 |
); |
| 20 |
} |
| 21 |
add_action( 'admin_menu', 'gutenberg_register_site_editor_admin_page' ); |
| 22 |
|
| 23 |
/** |
| 24 |
* Register default menu items for the site editor page. |
| 25 |
*/ |
| 26 |
function gutenberg_site_editor_register_default_menu_items() { |
| 27 |
gutenberg_register_site_editor_v2_menu_item( 'home', __( 'Home', 'gutenberg' ), '/', '' ); |
| 28 |
gutenberg_register_site_editor_v2_menu_item( 'identity', _x( 'Identity', 'site identity', 'gutenberg' ), '/identity', '' ); |
| 29 |
gutenberg_register_site_editor_v2_menu_item( 'styles', __( 'Styles', 'gutenberg' ), '/styles', '' ); |
| 30 |
|
| 31 |
// The screen edits `wp_navigation` posts, which only block themes render. |
| 32 |
// Classic themes manage their menus through Appearance > Menus instead. |
| 33 |
if ( wp_is_block_theme() ) { |
| 34 |
gutenberg_register_site_editor_v2_menu_item( 'navigation', __( 'Navigation', 'gutenberg' ), '/navigation', '' ); |
| 35 |
} |
| 36 |
|
| 37 |
gutenberg_register_site_editor_v2_menu_item( 'pages', __( 'Pages', 'gutenberg' ), '/types/page', '' ); |
| 38 |
|
| 39 |
// Block themes and classic themes shipping a `theme.json` file opt in |
| 40 |
// automatically, other classic themes have to call |
| 41 |
// `add_theme_support( 'block-templates' )`. |
| 42 |
if ( current_theme_supports( 'block-templates' ) ) { |
| 43 |
gutenberg_register_site_editor_v2_menu_item( 'templates', __( 'Templates', 'gutenberg' ), '/templates', '' ); |
| 44 |
} |
| 45 |
|
| 46 |
// `block-template-parts` lets a classic theme opt into template parts alone, |
| 47 |
// as the Template Part block itself allows. |
| 48 |
if ( current_theme_supports( 'block-templates' ) || current_theme_supports( 'block-template-parts' ) ) { |
| 49 |
gutenberg_register_site_editor_v2_menu_item( 'templateParts', __( 'Template Parts', 'gutenberg' ), '/template-parts', '' ); |
| 50 |
} |
| 51 |
|
| 52 |
gutenberg_register_site_editor_v2_menu_item( 'patterns', __( 'Patterns', 'gutenberg' ), '/patterns', '' ); |
| 53 |
} |
| 54 |
add_action( 'site-editor-v2_init', 'gutenberg_site_editor_register_default_menu_items', 5 ); |
| 55 |
|
| 56 |
/** |
| 57 |
* Renders the admin bar on the site editor page. |
| 58 |
*/ |
| 59 |
function gutenberg_site_editor_enable_admin_bar() { |
| 60 |
if ( ! is_admin_bar_showing() ) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
remove_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 ); |
| 65 |
add_action( 'admin_footer-site-editor-v2', 'wp_admin_bar_render' ); |
| 66 |
|
| 67 |
$admin_color = get_user_option( 'admin_color' ); |
| 68 |
if ( empty( $admin_color ) ) { |
| 69 |
$admin_color = 'modern'; |
| 70 |
} |
| 71 |
$admin_color_class = 'admin-color-' . sanitize_html_class( $admin_color ); |
| 72 |
|
| 73 |
add_action( |
| 74 |
'admin_footer-site-editor-v2', |
| 75 |
static function () use ( $admin_color_class ) { |
| 76 |
echo '<script>' |
| 77 |
. 'document.body.classList.add(' . wp_json_encode( $admin_color_class ) . ');' |
| 78 |
. '</script>'; |
| 79 |
} |
| 80 |
); |
| 81 |
|
| 82 |
wp_enqueue_script( 'admin-bar' ); |
| 83 |
wp_enqueue_style( 'admin-bar' ); |
| 84 |
wp_enqueue_style( 'colors' ); |
| 85 |
|
| 86 |
$css = <<<CSS |
| 87 |
#wpadminbar { |
| 88 |
display: block; |
| 89 |
} |
| 90 |
|
| 91 |
#site-editor-v2-app { |
| 92 |
position: fixed; |
| 93 |
top: var(--wp-admin--admin-bar--height, 0); |
| 94 |
left: 0; |
| 95 |
right: 0; |
| 96 |
bottom: 0; |
| 97 |
height: calc(100vh - var(--wp-admin--admin-bar--height, 0)) !important; |
| 98 |
} |
| 99 |
|
| 100 |
@media (min-width: 782px) { |
| 101 |
body:has(.editor-editor-interface.is-distraction-free) { |
| 102 |
--wp-admin--admin-bar--height: 0px; |
| 103 |
} |
| 104 |
|
| 105 |
body:has(.editor-editor-interface.is-distraction-free) #wpadminbar { |
| 106 |
display: none; |
| 107 |
} |
| 108 |
} |
| 109 |
CSS; |
| 110 |
|
| 111 |
wp_add_inline_style( 'admin-bar', $css ); |
| 112 |
} |
| 113 |
add_action( 'site-editor-v2_init', 'gutenberg_site_editor_enable_admin_bar' ); |
| 114 |
|