PluginProbe
Gutenberg / 12.1.0
Gutenberg v12.1.0
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 / build / block-library / blocks / image.php

image.php in Gutenberg 12.1.0, at build/block-library/blocks/image.php

43 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of the `core/image` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `core/image` block on the server,
10 * adding a data-id attribute to the element if core/gallery has added on pre-render.
11 *
12 * @param array $attributes The block attributes.
13 * @param array $content The block content.
14 * @return string Returns the block content with the data-id attribute added.
15 */
16 function gutenberg_render_block_core_image( $attributes, $content ) {
17 if ( isset( $attributes['data-id'] ) ) {
18 // Add the data-id="$id" attribute to the img element
19 // to provide backwards compatibility for the Gallery Block,
20 // which now wraps Image Blocks within innerBlocks.
21 // The data-id attribute is added in a core/gallery `render_block_data` hook.
22 $data_id_attribute = 'data-id="' . esc_attr( $attributes['data-id'] ) . '"';
23 if ( ! strpos( $content, $data_id_attribute ) ) {
24 $content = str_replace( '<img', '<img ' . $data_id_attribute . ' ', $content );
25 }
26 }
27 return $content;
28 }
29
30
31 /**
32 * Registers the `core/image` block on server.
33 */
34 function gutenberg_register_block_core_image() {
35 register_block_type_from_metadata(
36 __DIR__ . '/image',
37 array(
38 'render_callback' => 'gutenberg_render_block_core_image',
39 )
40 );
41 }
42 add_action( 'init', 'gutenberg_register_block_core_image', 20 );
43