Skip to content

Commit 090ebc1

Browse files
committed
PreLoad some stuff
1 parent 3698a2a commit 090ebc1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

includes/WP_Admin.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,30 @@ public static function register_assets() {
145145
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
146146
);
147147

148+
// Preload server-registered block bindings sources.
149+
$registered_sources = get_all_registered_block_bindings_sources();
150+
if ( ! empty( $registered_sources ) ) {
151+
$filtered_sources = array();
152+
foreach ( $registered_sources as $source ) {
153+
$filtered_sources[] = array(
154+
'name' => $source->name,
155+
'label' => $source->label,
156+
'usesContext' => $source->uses_context,
157+
);
158+
}
159+
$script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) );
160+
wp_add_inline_script(
161+
'wp-blocks',
162+
$script
163+
);
164+
}
165+
166+
wp_add_inline_script(
167+
'wp-blocks',
168+
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $block_editor_context ) ) ),
169+
'after'
170+
);
171+
148172
\wp_enqueue_script( self::$slug );
149173
\wp_enqueue_style( self::$slug );
150174

0 commit comments

Comments
 (0)