@@ -2406,6 +2406,8 @@ function the_block_editor_meta_boxes() {
24062406 <?php
24072407
24082408 $ meta_boxes_per_location = array ();
2409+ $ rtc_compatible_ids = array ();
2410+
24092411 foreach ( $ locations as $ location ) {
24102412 $ meta_boxes_per_location [ $ location ] = array ();
24112413
@@ -2424,6 +2426,11 @@ function the_block_editor_meta_boxes() {
24242426 continue ;
24252427 }
24262428
2429+ // Track meta boxes marked as compatible with real-time collaboration.
2430+ if ( isset ( $ meta_box ['args ' ]['__rtc_compatible_meta_box ' ] ) && $ meta_box ['args ' ]['__rtc_compatible_meta_box ' ] ) {
2431+ $ rtc_compatible_ids [] = $ meta_box ['id ' ];
2432+ }
2433+
24272434 // If a meta box is just here for back compat, don't show it in the block editor.
24282435 if ( isset ( $ meta_box ['args ' ]['__back_compat_meta_box ' ] ) && $ meta_box ['args ' ]['__back_compat_meta_box ' ] ) {
24292436 continue ;
@@ -2459,6 +2466,30 @@ function the_block_editor_meta_boxes() {
24592466 printf ( "<script> \n%s \n</script> \n" , trim ( $ script ) );
24602467 }
24612468
2469+ /*
2470+ * If collaboration is enabled and any meta boxes are marked as RTC-compatible,
2471+ * pass their IDs to the editor so it can determine which meta boxes are safe
2472+ * to use alongside real-time collaboration.
2473+ */
2474+ if ( wp_is_collaboration_enabled () && ! empty ( $ rtc_compatible_ids ) ) {
2475+ $ rtc_script = 'window._wpLoadBlockEditor.then( function() {
2476+ wp.data.dispatch( \'core/edit-post \' ).setRtcCompatibleMetaBoxIds( '
2477+ . wp_json_encode ( array_values ( array_unique ( $ rtc_compatible_ids ) ) )
2478+ . ' );
2479+ } ); ' ;
2480+
2481+ wp_add_inline_script ( 'wp-edit-post ' , $ rtc_script );
2482+
2483+ /*
2484+ * When `wp-edit-post` is output in the `<head>`, the inline script needs to be
2485+ * manually printed. Otherwise, inline scripts for `wp-edit-post` will not be
2486+ * printed again after this point.
2487+ */
2488+ if ( wp_script_is ( 'wp-edit-post ' , 'done ' ) ) {
2489+ printf ( "<script> \n%s \n</script> \n" , trim ( $ rtc_script ) );
2490+ }
2491+ }
2492+
24622493 /*
24632494 * If the 'postcustom' meta box is enabled, then we need to perform
24642495 * some extra initialization on it.
0 commit comments