PluginProbe
Gutenberg / 5.0.0
Gutenberg v5.0.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 / gutenberg.php

gutenberg.php in Gutenberg 5.0.0, at gutenberg.php

343 lines 9.0 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 * Version: 5.0.0
7 * Author: Gutenberg Team
8 *
9 * @package gutenberg
10 */
11
12 ### BEGIN AUTO-GENERATED DEFINES
13 define( 'GUTENBERG_VERSION', '5.0.0' );
14 define( 'GUTENBERG_GIT_COMMIT', 'de6e3bd667c3d1c94ca930e042c1e4081b08a1b6' );
15 ### END AUTO-GENERATED DEFINES
16
17 gutenberg_pre_init();
18
19 /**
20 * Project.
21 *
22 * The main entry point for the Gutenberg editor. Renders the editor on the
23 * wp-admin page for the plugin.
24 *
25 * The gutenberg and gutenberg__editor classNames are left for backward compatibility.
26 *
27 * @since 0.1.0
28 */
29 function the_gutenberg_project() {
30 global $post_type_object;
31 ?>
32 <noscript>
33 <div class="error" style="position:absolute;top:32px;z-index:40"><p>
34 <?php
35 // Using Gutenberg as Plugin.
36 if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
37 $current_url = esc_url( add_query_arg( 'classic-editor', true, $_SERVER['REQUEST_URI'] ) );
38 printf(
39 // Translators: link is to current page specify classic editor.
40 __( 'The Block Editor requires JavaScript. You can use the <a href="%s">Classic Editor</a>.', 'gutenberg' ),
41 $current_url
42 );
43 } else { // Using Gutenberg in Core.
44 printf(
45 /* translators: %s: https://wordpress.org/plugins/classic-editor/ */
46 __( 'The Block Editor requires JavaScript. Please try the <a href="%s">Classic Editor plugin</a>.', 'gutenberg' ),
47 __( 'https://wordpress.org/plugins/classic-editor/', 'gutenberg' )
48 );
49 }
50 ?>
51 </p></div>
52 </noscript>
53 <div class="block-editor gutenberg">
54 <h1 class="screen-reader-text"><?php echo esc_html( $post_type_object->labels->edit_item ); ?></h1>
55 <div id="editor" class="block-editor__container gutenberg__editor"></div>
56 <div id="metaboxes" class="hidden">
57 <?php the_block_editor_meta_boxes(); ?>
58 </div>
59 </div>
60 <?php
61 }
62
63 /**
64 * Gutenberg's Menu.
65 *
66 * Adds a new wp-admin menu page for the Gutenberg editor.
67 *
68 * @since 0.1.0
69 */
70 function gutenberg_menu() {
71 global $submenu;
72
73 add_menu_page(
74 'Gutenberg',
75 'Gutenberg',
76 'edit_posts',
77 'gutenberg',
78 'the_gutenberg_project',
79 'dashicons-edit'
80 );
81
82 add_submenu_page(
83 'gutenberg',
84 __( 'Demo', 'gutenberg' ),
85 __( 'Demo', 'gutenberg' ),
86 'edit_posts',
87 'gutenberg'
88 );
89
90 if ( current_user_can( 'edit_posts' ) ) {
91 $submenu['gutenberg'][] = array(
92 __( 'Support', 'gutenberg' ),
93 'edit_posts',
94 __( 'https://wordpress.org/support/plugin/gutenberg', 'gutenberg' ),
95 );
96
97 $submenu['gutenberg'][] = array(
98 __( 'Documentation', 'gutenberg' ),
99 'edit_posts',
100 'https://wordpress.org/gutenberg/handbook/',
101 );
102 }
103 }
104 add_action( 'admin_menu', 'gutenberg_menu' );
105
106 /**
107 * Checks whether we're currently loading a Gutenberg page
108 *
109 * @return boolean Whether Gutenberg is being loaded.
110 *
111 * @since 3.1.0
112 */
113 function is_gutenberg_page() {
114 global $post;
115
116 if ( ! is_admin() ) {
117 return false;
118 }
119
120 /*
121 * There have been reports of specialized loading scenarios where `get_current_screen`
122 * does not exist. In these cases, it is safe to say we are not loading Gutenberg.
123 */
124 if ( ! function_exists( 'get_current_screen' ) ) {
125 return false;
126 }
127
128 if ( get_current_screen()->base !== 'post' ) {
129 return false;
130 }
131
132 if ( isset( $_GET['classic-editor'] ) ) {
133 return false;
134 }
135
136 if ( ! gutenberg_can_edit_post( $post ) ) {
137 return false;
138 }
139
140 return true;
141 }
142
143 /**
144 * Display a version notice and deactivate the Gutenberg plugin.
145 *
146 * @since 0.1.0
147 */
148 function gutenberg_wordpress_version_notice() {
149 echo '<div class="error"><p>';
150 /* translators: %s: Minimum required version */
151 printf( __( 'Gutenberg requires WordPress %s or later to function properly. Please upgrade WordPress before activating Gutenberg.', 'gutenberg' ), '5.0.0' );
152 echo '</p></div>';
153
154 deactivate_plugins( array( 'gutenberg/gutenberg.php' ) );
155 }
156
157 /**
158 * Display a build notice.
159 *
160 * @since 0.1.0
161 */
162 function gutenberg_build_files_notice() {
163 echo '<div class="error"><p>';
164 _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/master/CONTRIBUTING.md">contributing</a> file for more information.', 'gutenberg' );
165 echo '</p></div>';
166 }
167
168 /**
169 * Verify that we can initialize the Gutenberg editor , then load it.
170 *
171 * @since 1.5.0
172 */
173 function gutenberg_pre_init() {
174 if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE && ! file_exists( dirname( __FILE__ ) . '/build/blocks' ) ) {
175 add_action( 'admin_notices', 'gutenberg_build_files_notice' );
176 return;
177 }
178
179 // Get unmodified $wp_version.
180 include ABSPATH . WPINC . '/version.php';
181
182 // Strip '-src' from the version string. Messes up version_compare().
183 $version = str_replace( '-src', '', $wp_version );
184
185 if ( version_compare( $version, '5.0.0', '<' ) ) {
186 add_action( 'admin_notices', 'gutenberg_wordpress_version_notice' );
187 return;
188 }
189
190 require_once dirname( __FILE__ ) . '/lib/load.php';
191
192 add_filter( 'replace_editor', 'gutenberg_init', 10, 2 );
193 }
194
195 /**
196 * Initialize Gutenberg.
197 *
198 * Load API functions, register scripts and actions, etc.
199 *
200 * @param bool $return Whether to replace the editor. Used in the `replace_editor` filter.
201 * @param object $post The post to edit or an auto-draft.
202 * @return bool Whether Gutenberg was initialized.
203 */
204 function gutenberg_init( $return, $post ) {
205 if ( true === $return && current_filter() === 'replace_editor' ) {
206 return $return;
207 }
208
209 if ( ! is_gutenberg_page() ) {
210 return false;
211 }
212
213 // Instruct WordPress that this is the block editor. Without this, a call
214 // to `is_block_editor()` would yield `false` while editing a post with
215 // Gutenberg.
216 //
217 // [TODO]: This is temporary so long as Gutenberg is implemented to use
218 // `replace_editor`, rather than allow `edit-form-blocks.php` from core to
219 // take effect, where this would otherwise be assigned.
220 get_current_screen()->is_block_editor( true );
221
222 add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' );
223 add_filter( 'screen_options_show_screen', '__return_false' );
224
225 /*
226 * Remove the emoji script as it is incompatible with both React and any
227 * contenteditable fields.
228 */
229 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
230
231 /*
232 * Ensure meta box functions are available to third-party code;
233 * includes/meta-boxes is typically loaded from edit-form-advanced.php.
234 */
235 require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
236 register_and_do_post_meta_boxes( $post );
237
238 require_once ABSPATH . 'wp-admin/admin-header.php';
239 the_gutenberg_project();
240
241 return true;
242 }
243
244 /**
245 * Adds the filters to register additional links for the Gutenberg editor in
246 * the post/page screens.
247 *
248 * @since 1.5.0
249 * @deprecated 5.0.0
250 */
251 function gutenberg_add_edit_link_filters() {
252 _deprecated_function( __FUNCTION__, '5.0.0' );
253 }
254
255 /**
256 * Registers an additional link in the post/page screens to edit any post/page in
257 * the Classic editor.
258 *
259 * @since 1.5.0
260 * @deprecated 5.0.0
261 *
262 * @param array $actions Post actions.
263 *
264 * @return array Updated post actions.
265 */
266 function gutenberg_add_edit_link( $actions ) {
267 _deprecated_function( __FUNCTION__, '5.0.0' );
268
269 return $actions;
270 }
271
272 /**
273 * Removes the Edit action from the reusable block list's Bulk Actions dropdown.
274 *
275 * @since 3.8.0
276 * @deprecated 5.0.0
277 *
278 * @param array $actions Bulk actions.
279 *
280 * @return array Updated bulk actions.
281 */
282 function gutenberg_block_bulk_actions( $actions ) {
283 _deprecated_function( __FUNCTION__, '5.0.0' );
284
285 return $actions;
286 }
287
288 /**
289 * Prints the JavaScript to replace the default "Add New" button.$_COOKIE
290 *
291 * @since 1.5.0
292 * @deprecated 5.0.0
293 */
294 function gutenberg_replace_default_add_new_button() {
295 _deprecated_function( __FUNCTION__, '5.0.0' );
296 }
297
298 /**
299 * Adds the block-editor-page class to the body tag on the Gutenberg page.
300 *
301 * @since 1.5.0
302 * @deprecated 5.0.0
303 *
304 * @param string $classes Space separated string of classes being added to the body tag.
305 * @return string The $classes string, with block-editor-page appended.
306 */
307 function gutenberg_add_admin_body_class( $classes ) {
308 _deprecated_function( __FUNCTION__, '5.0.0' );
309
310 return $classes;
311 }
312
313 /**
314 * Adds attributes to kses allowed tags that aren't in the default list
315 * and that Gutenberg needs to save blocks such as the Gallery block.
316 *
317 * @deprecated 5.0.0
318 *
319 * @param array $tags Allowed HTML.
320 * @return array (Maybe) modified allowed HTML.
321 */
322 function gutenberg_kses_allowedtags( $tags ) {
323 _deprecated_function( __FUNCTION__, '5.0.0' );
324
325 return $tags;
326 }
327
328 /**
329 * Adds the wp-embed-responsive class to the body tag if the theme has opted in to
330 * Gutenberg responsive embeds.
331 *
332 * @since 4.1.0
333 * @deprecated 5.0.0
334 *
335 * @param Array $classes Array of classes being added to the body tag.
336 * @return Array The $classes array, with wp-embed-responsive appended.
337 */
338 function gutenberg_add_responsive_body_class( $classes ) {
339 _deprecated_function( __FUNCTION__, '5.0.0' );
340
341 return $classes;
342 }
343