PluginProbe
Gutenberg / 4.6.1
Gutenberg v4.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 / register.php

register.php in Gutenberg 4.6.1, at lib/register.php

634 lines 20.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Initialization and wp-admin integration for the Gutenberg editor plugin.
4 *
5 * @package gutenberg
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 die( 'Silence is golden.' );
10 }
11
12 /**
13 * Collect information about meta_boxes registered for the current post.
14 *
15 * Redirects to classic editor if a meta box is incompatible.
16 *
17 * @since 1.5.0
18 */
19 function gutenberg_collect_meta_box_data() {
20 global $current_screen, $wp_meta_boxes, $post, $typenow;
21
22 $screen = $current_screen;
23
24 // If we are working with an already predetermined post.
25 if ( isset( $_REQUEST['post'] ) ) {
26 $post = get_post( absint( $_REQUEST['post'] ) );
27 $typenow = $post->post_type;
28
29 if ( ! gutenberg_can_edit_post( $post->ID ) ) {
30 return;
31 }
32 } else {
33 // Eventually add handling for creating new posts of different types in Gutenberg.
34 }
35 $post_type = $post->post_type;
36 $post_type_object = get_post_type_object( $post_type );
37
38 if ( ! gutenberg_can_edit_post_type( $post_type ) ) {
39 return;
40 }
41
42 // Disable hidden metaboxes because there's no UI to toggle visibility.
43 add_filter( 'hidden_meta_boxes', '__return_empty_array' );
44
45 $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
46 if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
47 if ( wp_attachment_is( 'audio', $post ) ) {
48 $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
49 } elseif ( wp_attachment_is( 'video', $post ) ) {
50 $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
51 }
52 }
53
54 /*
55 * WIP: Collect and send information needed to render meta boxes.
56 * From wp-admin/edit-form-advanced.php
57 * Relevant code there:
58 * do_action( 'do_meta_boxes', $post_type, {'normal','advanced','side'}, $post );
59 * do_meta_boxes( $post_type, 'side', $post );
60 * do_meta_boxes( null, 'normal', $post );
61 * do_meta_boxes( null, 'advanced', $post );
62 */
63 $publish_callback_args = null;
64 if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' !== $post->post_status ) {
65 $revisions = wp_get_post_revisions( $post->ID );
66
67 // We should aim to show the revisions meta box only when there are revisions.
68 if ( count( $revisions ) > 1 ) {
69 reset( $revisions ); // Reset pointer for key().
70 $publish_callback_args = array(
71 'revisions_count' => count( $revisions ),
72 'revision_id' => key( $revisions ),
73 );
74 add_meta_box( 'revisionsdiv', __( 'Revisions', 'gutenberg' ), 'post_revisions_meta_box', $screen, 'normal', 'core' );
75 }
76 }
77
78 if ( 'attachment' == $post_type ) {
79 wp_enqueue_script( 'image-edit' );
80 wp_enqueue_style( 'imgareaselect' );
81 add_meta_box( 'submitdiv', __( 'Save', 'gutenberg' ), 'attachment_submit_meta_box', $screen, 'side', 'core' );
82 add_action( 'edit_form_after_title', 'edit_form_image_editor' );
83
84 if ( wp_attachment_is( 'audio', $post ) ) {
85 add_meta_box( 'attachment-id3', __( 'Metadata', 'gutenberg' ), 'attachment_id3_data_meta_box', $screen, 'normal', 'core' );
86 }
87 } else {
88 add_meta_box( 'submitdiv', __( 'Publish', 'gutenberg' ), 'post_submit_meta_box', $screen, 'side', 'core', $publish_callback_args );
89 }
90
91 if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) {
92 add_meta_box( 'formatdiv', _x( 'Format', 'post format', 'gutenberg' ), 'post_format_meta_box', $screen, 'side', 'core' );
93 }
94
95 // All taxonomies.
96 foreach ( get_object_taxonomies( $post ) as $tax_name ) {
97 $taxonomy = get_taxonomy( $tax_name );
98 if ( ! $taxonomy->show_ui || false === $taxonomy->meta_box_cb ) {
99 continue;
100 }
101
102 $label = $taxonomy->labels->name;
103
104 if ( ! is_taxonomy_hierarchical( $tax_name ) ) {
105 $tax_meta_box_id = 'tagsdiv-' . $tax_name;
106 } else {
107 $tax_meta_box_id = $tax_name . 'div';
108 }
109
110 add_meta_box( $tax_meta_box_id, $label, $taxonomy->meta_box_cb, $screen, 'side', 'core', array( 'taxonomy' => $tax_name ) );
111 }
112
113 if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) {
114 add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', $screen, 'side', 'core' );
115 }
116
117 if ( $thumbnail_support && current_user_can( 'upload_files' ) ) {
118 add_meta_box( 'postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', $screen, 'side', 'low' );
119 }
120
121 if ( post_type_supports( $post_type, 'excerpt' ) ) {
122 add_meta_box( 'postexcerpt', __( 'Excerpt', 'gutenberg' ), 'post_excerpt_meta_box', $screen, 'normal', 'core' );
123 }
124
125 if ( post_type_supports( $post_type, 'trackbacks' ) ) {
126 add_meta_box( 'trackbacksdiv', __( 'Send Trackbacks', 'gutenberg' ), 'post_trackback_meta_box', $screen, 'normal', 'core' );
127 }
128
129 if ( post_type_supports( $post_type, 'custom-fields' ) ) {
130 add_meta_box( 'postcustom', __( 'Custom Fields', 'gutenberg' ), 'post_custom_meta_box', $screen, 'normal', 'core' );
131 }
132
133 /**
134 * Fires in the middle of built-in meta box registration.
135 *
136 * @since 2.1.0
137 * @deprecated 3.7.0 Use 'add_meta_boxes' instead.
138 *
139 * @param WP_Post $post Post object.
140 */
141 do_action( 'dbx_post_advanced', $post );
142
143 // Allow the Discussion meta box to show up if the post type supports comments,
144 // or if comments or pings are open.
145 if ( comments_open( $post ) || pings_open( $post ) || post_type_supports( $post_type, 'comments' ) ) {
146 add_meta_box( 'commentstatusdiv', __( 'Discussion', 'gutenberg' ), 'post_comment_status_meta_box', $screen, 'normal', 'core' );
147 }
148
149 $stati = get_post_stati( array( 'public' => true ) );
150 if ( empty( $stati ) ) {
151 $stati = array( 'publish' );
152 }
153 $stati[] = 'private';
154
155 if ( in_array( get_post_status( $post ), $stati ) ) {
156 // If the post type support comments, or the post has comments, allow the
157 // Comments meta box.
158 if ( comments_open( $post ) || pings_open( $post ) || $post->comment_count > 0 || post_type_supports( $post_type, 'comments' ) ) {
159 add_meta_box( 'commentsdiv', __( 'Comments', 'gutenberg' ), 'post_comment_meta_box', $screen, 'normal', 'core' );
160 }
161 }
162
163 if ( ! ( 'pending' == get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
164 add_meta_box( 'slugdiv', __( 'Slug', 'gutenberg' ), 'post_slug_meta_box', $screen, 'normal', 'core' );
165 }
166
167 if ( post_type_supports( $post_type, 'author' ) && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
168 add_meta_box( 'authordiv', __( 'Author', 'gutenberg' ), 'post_author_meta_box', $screen, 'normal', 'core' );
169 }
170
171 // Run the hooks for adding meta boxes for a specific post type.
172 do_action( 'add_meta_boxes', $post_type, $post );
173 do_action( "add_meta_boxes_{$post_type}", $post );
174
175 // Set up meta box locations.
176 $locations = array( 'normal', 'advanced', 'side' );
177
178 // Foreach location run the hooks meta boxes are potentially registered on.
179 foreach ( $locations as $location ) {
180 do_action(
181 'do_meta_boxes',
182 $screen,
183 $location,
184 $post
185 );
186 }
187 do_action( 'edit_form_advanced', $post );
188
189 // Copy meta box state.
190 $_meta_boxes_copy = $wp_meta_boxes;
191
192 /**
193 * Documented in lib/meta-box-partial-page.php
194 *
195 * @param array $wp_meta_boxes Global meta box state.
196 */
197 $_meta_boxes_copy = apply_filters( 'filter_gutenberg_meta_boxes', $_meta_boxes_copy );
198
199 // Redirect to classic editor if a meta box is incompatible.
200 foreach ( $locations as $location ) {
201 if ( ! isset( $_meta_boxes_copy[ $post->post_type ][ $location ] ) ) {
202 continue;
203 }
204 // Check if we have a meta box that has declared itself incompatible with the block editor.
205 foreach ( $_meta_boxes_copy[ $post->post_type ][ $location ] as $boxes ) {
206 foreach ( $boxes as $box ) {
207 /*
208 * If __block_editor_compatible_meta_box is declared as a false-y value,
209 * the meta box is not compatible with the block editor.
210 */
211 if ( is_array( $box['args'] )
212 && isset( $box['args']['__block_editor_compatible_meta_box'] )
213 && ! $box['args']['__block_editor_compatible_meta_box'] ) {
214 $incompatible_meta_box = true;
215 ?>
216 <script type="text/javascript">
217 var joiner = '?';
218 if ( window.location.search ) {
219 joiner = '&';
220 }
221 window.location.href += joiner + 'classic-editor';
222 </script>
223 <?php
224 exit;
225 }
226 }
227 }
228 }
229 }
230
231 /**
232 * Return whether the post can be edited in Gutenberg and by the current user.
233 *
234 * @since 0.5.0
235 *
236 * @param int|WP_Post $post Post ID or WP_Post object.
237 * @return bool Whether the post can be edited with Gutenberg.
238 */
239 function gutenberg_can_edit_post( $post ) {
240 $post = get_post( $post );
241 $can_edit = true;
242
243 if ( ! $post ) {
244 $can_edit = false;
245 }
246
247 if ( $can_edit && 'trash' === $post->post_status ) {
248 $can_edit = false;
249 }
250
251 if ( $can_edit && ! gutenberg_can_edit_post_type( $post->post_type ) ) {
252 $can_edit = false;
253 }
254
255 if ( $can_edit && ! current_user_can( 'edit_post', $post->ID ) ) {
256 $can_edit = false;
257 }
258
259 // Disable the editor if on the blog page and there is no content.
260 if ( $can_edit && absint( get_option( 'page_for_posts' ) ) === $post->ID && empty( $post->post_content ) ) {
261 $can_edit = false;
262 }
263
264 /**
265 * Filter to allow plugins to enable/disable Gutenberg for particular post.
266 *
267 * @since 3.5
268 *
269 * @param bool $can_edit Whether the post can be edited or not.
270 * @param WP_Post $post The post being checked.
271 */
272 return apply_filters( 'gutenberg_can_edit_post', $can_edit, $post );
273
274 }
275
276 /**
277 * Return whether the post type can be edited in Gutenberg.
278 *
279 * Gutenberg depends on the REST API, and if the post type is not shown in the
280 * REST API, then the post cannot be edited in Gutenberg.
281 *
282 * @since 1.5.2
283 *
284 * @param string $post_type The post type.
285 * @return bool Whether the post type can be edited with Gutenberg.
286 */
287 function gutenberg_can_edit_post_type( $post_type ) {
288 $can_edit = true;
289 if ( ! post_type_exists( $post_type ) ) {
290 $can_edit = false;
291 }
292
293 if ( ! post_type_supports( $post_type, 'editor' ) ) {
294 $can_edit = false;
295 }
296
297 $post_type_object = get_post_type_object( $post_type );
298 if ( $post_type_object && ! $post_type_object->show_in_rest ) {
299 $can_edit = false;
300 }
301
302 /**
303 * Filter to allow plugins to enable/disable Gutenberg for particular post types.
304 *
305 * @since 1.5.2
306 *
307 * @param bool $can_edit Whether the post type can be edited or not.
308 * @param string $post_type The post type being checked.
309 */
310 return apply_filters( 'gutenberg_can_edit_post_type', $can_edit, $post_type );
311 }
312
313 if ( ! function_exists( 'has_blocks' ) ) {
314 /**
315 * Determine whether a post or content string has blocks.
316 *
317 * This test optimizes for performance rather than strict accuracy, detecting
318 * the pattern of a block but not validating its structure. For strict accuracy
319 * you should use the block parser on post content.
320 *
321 * @since 3.6.0
322 * @see gutenberg_parse_blocks()
323 *
324 * @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post.
325 * @return bool Whether the post has blocks.
326 */
327 function has_blocks( $post = null ) {
328 if ( ! is_string( $post ) ) {
329 $wp_post = get_post( $post );
330 if ( $wp_post instanceof WP_Post ) {
331 $post = $wp_post->post_content;
332 }
333 }
334
335 return false !== strpos( (string) $post, '<!-- wp:' );
336 }
337 }
338
339 /**
340 * Determine whether a post has blocks. This test optimizes for performance
341 * rather than strict accuracy, detecting the pattern of a block but not
342 * validating its structure. For strict accuracy, you should use the block
343 * parser on post content.
344 *
345 * @see gutenberg_parse_blocks()
346 *
347 * @since 0.5.0
348 * @deprecated 3.6.0 Use has_blocks()
349 *
350 * @param object $post Post.
351 * @return bool Whether the post has blocks.
352 */
353 function gutenberg_post_has_blocks( $post ) {
354 _deprecated_function( __FUNCTION__, '3.6.0', 'has_blocks()' );
355 return has_blocks( $post );
356 }
357
358 /**
359 * Determine whether a content string contains blocks. This test optimizes for
360 * performance rather than strict accuracy, detecting the pattern of a block
361 * but not validating its structure. For strict accuracy, you should use the
362 * block parser on post content.
363 *
364 * @see gutenberg_parse_blocks()
365 *
366 * @since 1.6.0
367 * @deprecated 3.6.0 Use has_blocks()
368 *
369 * @param string $content Content to test.
370 * @return bool Whether the content contains blocks.
371 */
372 function gutenberg_content_has_blocks( $content ) {
373 _deprecated_function( __FUNCTION__, '3.6.0', 'has_blocks()' );
374 return has_blocks( $content );
375 }
376
377 if ( ! function_exists( 'has_block' ) ) {
378 /**
379 * Determine whether a $post or a string contains a specific block type.
380 * This test optimizes for performance rather than strict accuracy, detecting
381 * the block type exists but not validating its structure.
382 * For strict accuracy, you should use the block parser on post content.
383 *
384 * @since 3.6.0
385 *
386 * @param string $block_type Full Block type to look for.
387 * @param int|string|WP_Post|null $post Optional. Post content, post ID, or post object. Defaults to global $post.
388 * @return bool Whether the post content contains the specified block.
389 */
390 function has_block( $block_type, $post = null ) {
391 if ( ! has_blocks( $post ) ) {
392 return false;
393 }
394
395 if ( ! is_string( $post ) ) {
396 $wp_post = get_post( $post );
397 if ( $wp_post instanceof WP_Post ) {
398 $post = $wp_post->post_content;
399 }
400 }
401
402 return false !== strpos( $post, '<!-- wp:' . $block_type . ' ' );
403 }
404 }
405
406 /**
407 * Returns the current version of the block format that the content string is using.
408 *
409 * If the string doesn't contain blocks, it returns 0.
410 *
411 * @since 2.8.0
412 * @see gutenberg_content_has_blocks()
413 *
414 * @param string $content Content to test.
415 * @return int The block format version.
416 */
417 function gutenberg_content_block_version( $content ) {
418 return has_blocks( $content ) ? 1 : 0;
419 }
420
421 /**
422 * Adds a "Gutenberg" post state for post tables, if the post contains blocks.
423 *
424 * @param array $post_states An array of post display states.
425 * @param WP_Post $post The current post object.
426 * @return array A filtered array of post display states.
427 */
428 function gutenberg_add_gutenberg_post_state( $post_states, $post ) {
429 if ( has_blocks( $post ) ) {
430 $post_states[] = 'Gutenberg';
431 }
432
433 return $post_states;
434 }
435 add_filter( 'display_post_states', 'gutenberg_add_gutenberg_post_state', 10, 2 );
436
437 /**
438 * Registers custom post types required by the Gutenberg editor.
439 *
440 * @since 0.10.0
441 */
442 function gutenberg_register_post_types() {
443 register_post_type(
444 'wp_block',
445 array(
446 'labels' => array(
447 'name' => _x( 'Blocks', 'post type general name', 'gutenberg' ),
448 'singular_name' => _x( 'Block', 'post type singular name', 'gutenberg' ),
449 'menu_name' => _x( 'Blocks', 'admin menu', 'gutenberg' ),
450 'name_admin_bar' => _x( 'Block', 'add new on admin bar', 'gutenberg' ),
451 'add_new' => _x( 'Add New', 'Block', 'gutenberg' ),
452 'add_new_item' => __( 'Add New Block', 'gutenberg' ),
453 'new_item' => __( 'New Block', 'gutenberg' ),
454 'edit_item' => __( 'Edit Block', 'gutenberg' ),
455 'view_item' => __( 'View Block', 'gutenberg' ),
456 'all_items' => __( 'All Blocks', 'gutenberg' ),
457 'search_items' => __( 'Search Blocks', 'gutenberg' ),
458 'not_found' => __( 'No blocks found.', 'gutenberg' ),
459 'not_found_in_trash' => __( 'No blocks found in Trash.', 'gutenberg' ),
460 'filter_items_list' => __( 'Filter blocks list', 'gutenberg' ),
461 'items_list_navigation' => __( 'Blocks list navigation', 'gutenberg' ),
462 'items_list' => __( 'Blocks list', 'gutenberg' ),
463 'item_published' => __( 'Block published.', 'gutenberg' ),
464 'item_published_privately' => __( 'Block published privately.', 'gutenberg' ),
465 'item_reverted_to_draft' => __( 'Block reverted to draft.', 'gutenberg' ),
466 'item_scheduled' => __( 'Block scheduled.', 'gutenberg' ),
467 'item_updated' => __( 'Block updated.', 'gutenberg' ),
468 ),
469 'public' => false,
470 'show_ui' => true,
471 'show_in_menu' => false,
472 'rewrite' => false,
473 'show_in_rest' => true,
474 'rest_base' => 'blocks',
475 'rest_controller_class' => 'WP_REST_Blocks_Controller',
476 'capability_type' => 'block',
477 'capabilities' => array(
478 'read' => 'read_blocks',
479 'create_posts' => 'create_blocks',
480 ),
481 'map_meta_cap' => true,
482 'supports' => array(
483 'title',
484 'editor',
485 ),
486 )
487 );
488
489 $editor_caps = array(
490 'edit_blocks',
491 'edit_others_blocks',
492 'publish_blocks',
493 'read_private_blocks',
494 'read_blocks',
495 'delete_blocks',
496 'delete_private_blocks',
497 'delete_published_blocks',
498 'delete_others_blocks',
499 'edit_private_blocks',
500 'edit_published_blocks',
501 'create_blocks',
502 );
503
504 $caps_map = array(
505 'administrator' => $editor_caps,
506 'editor' => $editor_caps,
507 'author' => array(
508 'edit_blocks',
509 'publish_blocks',
510 'read_blocks',
511 'delete_blocks',
512 'delete_published_blocks',
513 'edit_published_blocks',
514 'create_blocks',
515 ),
516 'contributor' => array(
517 'read_blocks',
518 ),
519 );
520
521 foreach ( $caps_map as $role_name => $caps ) {
522 $role = get_role( $role_name );
523
524 if ( empty( $role ) ) {
525 continue;
526 }
527
528 foreach ( $caps as $cap ) {
529 if ( ! $role->has_cap( $cap ) ) {
530 $role->add_cap( $cap );
531 }
532 }
533 }
534 }
535 add_action( 'init', 'gutenberg_register_post_types' );
536
537 /**
538 * Apply the correct labels for Reusable Blocks in the bulk action updated messages.
539 *
540 * @since 4.3.0
541 *
542 * @param array $messages Arrays of messages, each keyed by the corresponding post type.
543 * @param array $bulk_counts Array of item counts for each message, used to build internationalized strings.
544 *
545 * @return array
546 */
547 function gutenberg_bulk_post_updated_messages( $messages, $bulk_counts ) {
548 $messages['wp_block'] = array(
549 // translators: Number of blocks updated.
550 'updated' => _n( '%s block updated.', '%s blocks updated.', $bulk_counts['updated'], 'gutenberg' ),
551 // translators: Blocks not updated because they're locked.
552 'locked' => ( 1 == $bulk_counts['locked'] ) ? __( '1 block not updated, somebody is editing it.', 'gutenberg' ) : _n( '%s block not updated, somebody is editing it.', '%s blocks not updated, somebody is editing them.', $bulk_counts['locked'], 'gutenberg' ),
553 // translators: Number of blocks deleted.
554 'deleted' => _n( '%s block permanently deleted.', '%s blocks permanently deleted.', $bulk_counts['deleted'], 'gutenberg' ),
555 // translators: Number of blocks trashed.
556 'trashed' => _n( '%s block moved to the Trash.', '%s blocks moved to the Trash.', $bulk_counts['trashed'], 'gutenberg' ),
557 // translators: Number of blocks untrashed.
558 'untrashed' => _n( '%s block restored from the Trash.', '%s blocks restored from the Trash.', $bulk_counts['untrashed'], 'gutenberg' ),
559 );
560
561 return $messages;
562 }
563
564 add_filter( 'bulk_post_updated_messages', 'gutenberg_bulk_post_updated_messages', 10, 2 );
565
566 /**
567 * Injects a hidden input in the edit form to propagate the information that classic editor is selected.
568 *
569 * @since 1.5.2
570 */
571 function gutenberg_remember_classic_editor_when_saving_posts() {
572 ?>
573 <input type="hidden" name="classic-editor" />
574 <?php
575 }
576 add_action( 'edit_form_top', 'gutenberg_remember_classic_editor_when_saving_posts' );
577
578 /**
579 * Appends a query argument to the redirect url to make sure it gets redirected to the classic editor.
580 *
581 * @since 1.5.2
582 *
583 * @param string $url Redirect url.
584 * @return string Redirect url.
585 */
586 function gutenberg_redirect_to_classic_editor_when_saving_posts( $url ) {
587 if ( isset( $_REQUEST['classic-editor'] ) ) {
588 $url = add_query_arg( 'classic-editor', '', $url );
589 }
590 return $url;
591 }
592 add_filter( 'redirect_post_location', 'gutenberg_redirect_to_classic_editor_when_saving_posts', 10, 1 );
593
594 /**
595 * Appends a query argument to the edit url to make sure it is redirected to
596 * the editor from which the user navigated.
597 *
598 * @since 1.5.2
599 *
600 * @param string $url Edit url.
601 * @return string Edit url.
602 */
603 function gutenberg_revisions_link_to_editor( $url ) {
604 global $pagenow;
605 if ( 'revision.php' !== $pagenow || isset( $_REQUEST['gutenberg'] ) ) {
606 return $url;
607 }
608
609 return add_query_arg( 'classic-editor', '', $url );
610 }
611 add_filter( 'get_edit_post_link', 'gutenberg_revisions_link_to_editor' );
612
613 /**
614 * Modifies revisions data to preserve Gutenberg argument used in determining
615 * where to redirect user returning to editor.
616 *
617 * @since 1.9.0
618 *
619 * @param array $revisions_data The bootstrapped data for the revisions screen.
620 * @return array Modified bootstrapped data for the revisions screen.
621 */
622 function gutenberg_revisions_restore( $revisions_data ) {
623 if ( isset( $_REQUEST['gutenberg'] ) ) {
624 $revisions_data['restoreUrl'] = add_query_arg(
625 'gutenberg',
626 $_REQUEST['gutenberg'],
627 $revisions_data['restoreUrl']
628 );
629 }
630
631 return $revisions_data;
632 }
633 add_filter( 'wp_prepare_revision_for_js', 'gutenberg_revisions_restore' );
634