PluginProbe
Gutenberg / 10.0.1
Gutenberg v10.0.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 / gutenberg.php

gutenberg.php in Gutenberg 10.0.1, at gutenberg.php

245 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Gutenberg
4 * Plugin URI: https://github.com/WordPress/gutenberg
5 * Description: Printing since 1440. This is the development plugin for the new block editor in core.
6 * Requires at least: 5.3
7 * Requires PHP: 5.6
8 * Version: 10.0.1
9 * Author: Gutenberg Team
10 * Text Domain: gutenberg
11 *
12 * @package gutenberg
13 */
14
15 ### BEGIN AUTO-GENERATED DEFINES
16 define( 'GUTENBERG_VERSION', '10.0.1' );
17 define( 'GUTENBERG_GIT_COMMIT', '4d7eb5809330d3aa8fa88a80122cdc0228db66d4' );
18 ### END AUTO-GENERATED DEFINES
19
20 gutenberg_pre_init();
21
22 /**
23 * Gutenberg's Menu.
24 *
25 * Adds a new wp-admin menu page for the Gutenberg editor.
26 *
27 * @since 0.1.0
28 */
29 function gutenberg_menu() {
30 add_menu_page(
31 'Gutenberg',
32 'Gutenberg',
33 'edit_posts',
34 'gutenberg',
35 '',
36 'dashicons-edit'
37 );
38
39 add_submenu_page(
40 'gutenberg',
41 __( 'Demo', 'gutenberg' ),
42 __( 'Demo', 'gutenberg' ),
43 'edit_posts',
44 'gutenberg'
45 );
46
47 if ( gutenberg_use_widgets_block_editor() ) {
48 add_theme_page(
49 __( 'Widgets', 'gutenberg' ),
50 __( 'Widgets', 'gutenberg' ),
51 'edit_theme_options',
52 'gutenberg-widgets',
53 'the_gutenberg_widgets'
54 );
55 remove_submenu_page( 'themes.php', 'widgets.php' );
56 }
57
58 if ( get_option( 'gutenberg-experiments' ) ) {
59 if ( array_key_exists( 'gutenberg-navigation', get_option( 'gutenberg-experiments' ) ) ) {
60 add_submenu_page(
61 'gutenberg',
62 __( 'Navigation (beta)', 'gutenberg' ),
63 __( 'Navigation (beta)', 'gutenberg' ),
64 'edit_theme_options',
65 'gutenberg-navigation',
66 'gutenberg_navigation_page'
67 );
68 }
69 }
70 if ( current_user_can( 'edit_posts' ) ) {
71 add_submenu_page(
72 'gutenberg',
73 __( 'Support', 'gutenberg' ),
74 __( 'Support', 'gutenberg' ),
75 'edit_posts',
76 __( 'https://wordpress.org/support/plugin/gutenberg/', 'gutenberg' )
77 );
78 add_submenu_page(
79 'gutenberg',
80 __( 'Documentation', 'gutenberg' ),
81 __( 'Documentation', 'gutenberg' ),
82 'edit_posts',
83 'https://developer.wordpress.org/block-editor/'
84 );
85 }
86
87 add_submenu_page(
88 'gutenberg',
89 __( 'Experiments Settings', 'gutenberg' ),
90 __( 'Experiments', 'gutenberg' ),
91 'edit_posts',
92 'gutenberg-experiments',
93 'the_gutenberg_experiments'
94 );
95 }
96 add_action( 'admin_menu', 'gutenberg_menu', 9 );
97
98 /**
99 * Site editor's Menu.
100 *
101 * Adds a new wp-admin menu item for the Site editor.
102 *
103 * @since 9.4.0
104 */
105 function gutenberg_site_editor_menu() {
106 if ( gutenberg_is_fse_theme() ) {
107 add_menu_page(
108 __( 'Site Editor (beta)', 'gutenberg' ),
109 sprintf(
110 /* translators: %s: "beta" label. */
111 __( 'Site Editor %s', 'gutenberg' ),
112 '<span class="awaiting-mod">' . __( 'beta', 'gutenberg' ) . '</span>'
113 ),
114 'edit_theme_options',
115 'gutenberg-edit-site',
116 'gutenberg_edit_site_page',
117 'dashicons-layout'
118 );
119 }
120 }
121 add_action( 'admin_menu', 'gutenberg_site_editor_menu', 9 );
122
123 /**
124 * Modify WP admin bar.
125 *
126 * @param WP_Admin_Bar $wp_admin_bar Core class used to implement the Toolbar API.
127 */
128 function modify_admin_bar( $wp_admin_bar ) {
129 if ( gutenberg_use_widgets_block_editor() ) {
130 $wp_admin_bar->add_menu(
131 array(
132 'id' => 'widgets',
133 'href' => admin_url( 'themes.php?page=gutenberg-widgets' ),
134 )
135 );
136 }
137 }
138 add_action( 'admin_bar_menu', 'modify_admin_bar', 40 );
139
140
141 remove_action( 'welcome_panel', 'wp_welcome_panel' );
142 /**
143 * Modify Dashboard welcome panel.
144 *
145 * When widgets are merged in core this should go into `wp-admin/includes/dashboard.php`
146 * and replace the widgets link in the `wp_welcome_panel` checking for the same condition,
147 * because then `gutenberg_use_widgets_block_editor` will exist in core.
148 */
149 function modify_welcome_panel() {
150 ob_start();
151 wp_welcome_panel();
152 $welcome_panel = ob_get_clean();
153 if ( gutenberg_use_widgets_block_editor() ) {
154 echo str_replace(
155 admin_url( 'widgets.php' ),
156 admin_url( 'themes.php?page=gutenberg-widgets' ),
157 $welcome_panel
158 );
159 } else {
160 echo $welcome_panel;
161 }
162 }
163 add_action( 'welcome_panel', 'modify_welcome_panel', 40 );
164
165 /**
166 * Display a version notice and deactivate the Gutenberg plugin.
167 *
168 * @since 0.1.0
169 */
170 function gutenberg_wordpress_version_notice() {
171 echo '<div class="error"><p>';
172 /* translators: %s: Minimum required version */
173 printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.3.0' );
174 echo '</p></div>';
175
176 deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
177 }
178
179 /**
180 * Display a build notice.
181 *
182 * @since 0.1.0
183 */
184 function gutenberg_build_files_notice() {
185 echo '<div class="error"><p>';
186 _e( 'Gutenberg development mode requires files to be built. Run <code>npm install</code> to install dependencies, <code>npm run build</code> to build the files or <code>npm run dev</code> to build the files and watch for changes. Read the <a href="https://github.com/WordPress/gutenberg/blob/HEAD/docs/contributors/getting-started.md">contributing</a> file for more information.', 'gutenberg' );
187 echo '</p></div>';
188 }
189
190 /**
191 * Verify that we can initialize the Gutenberg editor , then load it.
192 *
193 * @since 1.5.0
194 */
195 function gutenberg_pre_init() {
196 global $wp_version;
197 if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( __DIR__ . '/build/blocks' ) ) {
198 add_action( 'admin_notices', 'gutenberg_build_files_notice' );
199 return;
200 }
201
202 // Get unmodified $wp_version.
203 include ABSPATH . WPINC . '/version.php';
204
205 // Strip '-src' from the version string. Messes up version_compare().
206 $version = str_replace( '-src', '', $wp_version );
207
208 if ( version_compare( $version, '5.3.0', '<' ) ) {
209 add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
210 return;
211 }
212
213 require_once __DIR__ . '/lib/load.php';
214 }
215
216 /**
217 * Outputs a WP REST API nonce.
218 */
219 function gutenberg_rest_nonce() {
220 exit( wp_create_nonce( 'wp_rest' ) );
221 }
222 add_action( 'wp_ajax_gutenberg_rest_nonce', 'gutenberg_rest_nonce' );
223
224
225 /**
226 * Exposes the site icon url to the Gutenberg editor through the WordPress REST
227 * API. The site icon url should instead be fetched from the wp/v2/settings
228 * endpoint when https://github.com/WordPress/gutenberg/pull/19967 is complete.
229 *
230 * @since 8.2.1
231 *
232 * @param WP_REST_Response $response Response data served by the WordPress REST index endpoint.
233 * @return WP_REST_Response
234 */
235 function register_site_icon_url( $response ) {
236 $data = $response->data;
237 $data['site_icon_url'] = get_site_icon_url();
238 $response->set_data( $data );
239 return $response;
240 }
241
242 add_filter( 'rest_index', 'register_site_icon_url' );
243
244 add_theme_support( 'widgets-block-editor' );
245