PluginProbe
Gutenberg / 10.9.0
Gutenberg v10.9.0
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.9.0, at lib/init.php

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