diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php index 8d52c1487a7a5..5e87559256c36 100644 --- a/src/wp-admin/includes/post.php +++ b/src/wp-admin/includes/post.php @@ -2406,6 +2406,8 @@ function the_block_editor_meta_boxes() { \n%s\n\n", trim( $script ) ); } + /* + * If collaboration is enabled and any meta boxes are marked as RTC-compatible, + * pass their IDs to the editor so it can determine which meta boxes are safe + * to use alongside real-time collaboration. + */ + if ( wp_is_collaboration_enabled() && ! empty( $rtc_compatible_ids ) ) { + $rtc_script = 'window._wpLoadBlockEditor.then( function() { + wp.data.dispatch( \'core/edit-post\' ).setRtcCompatibleMetaBoxIds( ' + . wp_json_encode( array_values( array_unique( $rtc_compatible_ids ) ) ) + . ' ); + } );'; + + wp_add_inline_script( 'wp-edit-post', $rtc_script ); + + /* + * When `wp-edit-post` is output in the ``, the inline script needs to be + * manually printed. Otherwise, inline scripts for `wp-edit-post` will not be + * printed again after this point. + */ + if ( wp_script_is( 'wp-edit-post', 'done' ) ) { + printf( "\n", trim( $rtc_script ) ); + } + } + /* * If the 'postcustom' meta box is enabled, then we need to perform * some extra initialization on it.