PluginProbe
Gutenberg / 10.5.1
Gutenberg v10.5.1
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 / init.php

init.php in Gutenberg 10.5.1, at lib/init.php

181 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Init hooks.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Gutenberg's Menu.
10 *
11 * Adds a new wp-admin menu page for the Gutenberg editor.
12 *
13 * @since 0.1.0
14 */
15 function gutenberg_menu() {
16 add_menu_page(
17 'Gutenberg',
18 'Gutenberg',
19 'edit_posts',
20 'gutenberg',
21 '',
22 'dashicons-edit'
23 );
24
25 add_submenu_page(
26 'gutenberg',
27 __( 'Demo', 'gutenberg' ),
28 __( 'Demo', 'gutenberg' ),
29 'edit_posts',
30 'gutenberg'
31 );
32
33 if ( gutenberg_use_widgets_block_editor() ) {
34 add_theme_page(
35 __( 'Widgets', 'gutenberg' ),
36 __( 'Widgets', 'gutenberg' ),
37 'edit_theme_options',
38 'gutenberg-widgets',
39 'the_gutenberg_widgets'
40 );
41 remove_submenu_page( 'themes.php', 'widgets.php' );
42 }
43
44 if ( get_option( 'gutenberg-experiments' ) ) {
45 if ( array_key_exists( 'gutenberg-navigation', get_option( 'gutenberg-experiments' ) ) ) {
46 add_submenu_page(
47 'gutenberg',
48 __( 'Navigation (beta)', 'gutenberg' ),
49 __( 'Navigation (beta)', 'gutenberg' ),
50 'edit_theme_options',
51 'gutenberg-navigation',
52 'gutenberg_navigation_page'
53 );
54 }
55 }
56 if ( current_user_can( 'edit_posts' ) ) {
57 add_submenu_page(
58 'gutenberg',
59 __( 'Support', 'gutenberg' ),
60 __( 'Support', 'gutenberg' ),
61 'edit_posts',
62 __( 'https://wordpress.org/support/plugin/gutenberg/', 'gutenberg' )
63 );
64 add_submenu_page(
65 'gutenberg',
66 __( 'Documentation', 'gutenberg' ),
67 __( 'Documentation', 'gutenberg' ),
68 'edit_posts',
69 'https://developer.wordpress.org/block-editor/'
70 );
71 }
72
73 add_submenu_page(
74 'gutenberg',
75 __( 'Experiments Settings', 'gutenberg' ),
76 __( 'Experiments', 'gutenberg' ),
77 'edit_posts',
78 'gutenberg-experiments',
79 'the_gutenberg_experiments'
80 );
81 }
82 add_action( 'admin_menu', 'gutenberg_menu', 9 );
83
84 /**
85 * Site editor's Menu.
86 *
87 * Adds a new wp-admin menu item for the Site editor.
88 *
89 * @since 9.4.0
90 */
91 function gutenberg_site_editor_menu() {
92 if ( gutenberg_is_fse_theme() ) {
93 add_menu_page(
94 __( 'Site Editor (beta)', 'gutenberg' ),
95 sprintf(
96 /* translators: %s: "beta" label. */
97 __( 'Site Editor %s', 'gutenberg' ),
98 '<span class="awaiting-mod">' . __( 'beta', 'gutenberg' ) . '</span>'
99 ),
100 'edit_theme_options',
101 'gutenberg-edit-site',
102 'gutenberg_edit_site_page',
103 'dashicons-layout'
104 );
105 }
106 }
107 add_action( 'admin_menu', 'gutenberg_site_editor_menu', 9 );
108
109 /**
110 * Modify WP admin bar.
111 *
112 * @param WP_Admin_Bar $wp_admin_bar Core class used to implement the Toolbar API.
113 */
114 function modify_admin_bar( $wp_admin_bar ) {
115 if ( gutenberg_use_widgets_block_editor() ) {
116 $wp_admin_bar->add_menu(
117 array(
118 'id' => 'widgets',
119 'href' => admin_url( 'themes.php?page=gutenberg-widgets' ),
120 )
121 );
122 }
123 }
124 add_action( 'admin_bar_menu', 'modify_admin_bar', 40 );
125
126
127 remove_action( 'welcome_panel', 'wp_welcome_panel' );
128 /**
129 * Modify Dashboard welcome panel.
130 *
131 * When widgets are merged in core this should go into `wp-admin/includes/dashboard.php`
132 * and replace the widgets link in the `wp_welcome_panel` checking for the same condition,
133 * because then `gutenberg_use_widgets_block_editor` will exist in core.
134 */
135 function modify_welcome_panel() {
136 ob_start();
137 wp_welcome_panel();
138 $welcome_panel = ob_get_clean();
139 if ( gutenberg_use_widgets_block_editor() ) {
140 echo str_replace(
141 admin_url( 'widgets.php' ),
142 admin_url( 'themes.php?page=gutenberg-widgets' ),
143 $welcome_panel
144 );
145 } else {
146 echo $welcome_panel;
147 }
148 }
149 add_action( 'welcome_panel', 'modify_welcome_panel', 40 );
150
151 /**
152 * Outputs a WP REST API nonce.
153 */
154 function gutenberg_rest_nonce() {
155 exit( wp_create_nonce( 'wp_rest' ) );
156 }
157 add_action( 'wp_ajax_gutenberg_rest_nonce', 'gutenberg_rest_nonce' );
158
159
160 /**
161 * Exposes the site icon url to the Gutenberg editor through the WordPress REST
162 * API. The site icon url should instead be fetched from the wp/v2/settings
163 * endpoint when https://github.com/WordPress/gutenberg/pull/19967 is complete.
164 *
165 * @since 8.2.1
166 *
167 * @param WP_REST_Response $response Response data served by the WordPress REST index endpoint.
168 * @return WP_REST_Response
169 */
170 function register_site_icon_url( $response ) {
171 $data = $response->data;
172 $data['site_icon_url'] = get_site_icon_url();
173 $response->set_data( $data );
174 return $response;
175 }
176
177 add_filter( 'rest_index', 'register_site_icon_url' );
178
179 add_theme_support( 'widgets-block-editor' );
180 add_theme_support( 'block-templates' );
181