diff --git a/lib/blocks.php b/lib/blocks.php index 76bf0d74eed4da..9aa111dfff61a4 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -66,6 +66,8 @@ function gutenberg_reregister_core_block_types() { 'comment-template.php' => 'core/comment-template', 'file.php' => 'core/file', 'home-link.php' => 'core/home-link', + 'image.php' => 'core/image', + 'gallery.php' => 'core/gallery', 'latest-comments.php' => 'core/latest-comments', 'latest-posts.php' => 'core/latest-posts', 'loginout.php' => 'core/loginout', diff --git a/packages/block-library/src/gallery/index.php b/packages/block-library/src/gallery/index.php new file mode 100644 index 00000000000000..74ac0e3b96946a --- /dev/null +++ b/packages/block-library/src/gallery/index.php @@ -0,0 +1,52 @@ + $inner_block ) { + if ( 'core/image' === $inner_block['blockName'] ) { + if ( ! isset( $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] ) && isset( $inner_block['attrs']['id'] ) ) { + $parsed_block['innerBlocks'][ $key ]['attrs']['data-id'] = esc_attr( $inner_block['attrs']['id'] ); + } + } + } + } + + return $parsed_block; +} + +add_filter( 'render_block_data', 'render_block_core_gallery_data' ); + +/** + * Registers the `core/gallery` block on server. + * This render callback needs to be here + * so that the gallery styles are loaded in block-based themes. + */ +function gutenberg_register_block_core_gallery() { + register_block_type_from_metadata( + __DIR__ . '/gallery', + array( + 'render_callback' => function ( $attributes, $content ) { + return $content; + }, + ) + ); +} + +add_action( 'init', 'gutenberg_register_block_core_gallery', 20 ); diff --git a/packages/block-library/src/image/index.php b/packages/block-library/src/image/index.php new file mode 100644 index 00000000000000..4e149a9c13fcea --- /dev/null +++ b/packages/block-library/src/image/index.php @@ -0,0 +1,42 @@ + 'render_block_core_image', + ) + ); +} +add_action( 'init', 'register_block_core_image' );