PluginProbe
Gutenberg / 10.6.1
Gutenberg v10.6.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.6.1, at lib/init.php

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