PluginProbe
Gutenberg / 23.7.2
Gutenberg v23.7.2
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / experimental / pages / site-editor.php

site-editor.php in Gutenberg 23.7.2, at lib/experimental/pages/site-editor.php

95 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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( 'styles', __( 'Styles', 'gutenberg' ), '/styles', '' );
29 gutenberg_register_site_editor_v2_menu_item( 'navigation', __( 'Navigation', 'gutenberg' ), '/navigation', '' );
30 gutenberg_register_site_editor_v2_menu_item( 'pages', __( 'Pages', 'gutenberg' ), '/types/page', '' );
31 gutenberg_register_site_editor_v2_menu_item( 'templates', __( 'Templates', 'gutenberg' ), '/templates', '' );
32 gutenberg_register_site_editor_v2_menu_item( 'templateParts', __( 'Template Parts', 'gutenberg' ), '/template-parts', '' );
33 gutenberg_register_site_editor_v2_menu_item( 'patterns', __( 'Patterns', 'gutenberg' ), '/patterns', '' );
34 }
35 add_action( 'site-editor-v2_init', 'gutenberg_site_editor_register_default_menu_items', 5 );
36
37 /**
38 * Renders the admin bar on the site editor page.
39 */
40 function gutenberg_site_editor_enable_admin_bar() {
41 if ( ! is_admin_bar_showing() ) {
42 return;
43 }
44
45 remove_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 );
46 add_action( 'admin_footer-site-editor-v2', 'wp_admin_bar_render' );
47
48 $admin_color = get_user_option( 'admin_color' );
49 if ( empty( $admin_color ) ) {
50 $admin_color = 'modern';
51 }
52 $admin_color_class = 'admin-color-' . sanitize_html_class( $admin_color );
53
54 add_action(
55 'admin_footer-site-editor-v2',
56 static function () use ( $admin_color_class ) {
57 echo '<script>'
58 . 'document.body.classList.add(' . wp_json_encode( $admin_color_class ) . ');'
59 . '</script>';
60 }
61 );
62
63 wp_enqueue_script( 'admin-bar' );
64 wp_enqueue_style( 'admin-bar' );
65 wp_enqueue_style( 'colors' );
66
67 $css = <<<CSS
68 #wpadminbar {
69 display: block;
70 }
71
72 #site-editor-v2-app {
73 position: fixed;
74 top: var(--wp-admin--admin-bar--height, 0);
75 left: 0;
76 right: 0;
77 bottom: 0;
78 height: calc(100vh - var(--wp-admin--admin-bar--height, 0)) !important;
79 }
80
81 @media (min-width: 782px) {
82 body:has(.editor-editor-interface.is-distraction-free) {
83 --wp-admin--admin-bar--height: 0px;
84 }
85
86 body:has(.editor-editor-interface.is-distraction-free) #wpadminbar {
87 display: none;
88 }
89 }
90 CSS;
91
92 wp_add_inline_style( 'admin-bar', $css );
93 }
94 add_action( 'site-editor-v2_init', 'gutenberg_site_editor_enable_admin_bar' );
95