PluginProbe
Gutenberg / 17.0.2
Gutenberg v17.0.2
24.0.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 All 403 releases
gutenberg / build / block-library / blocks / pattern.php

pattern.php in Gutenberg 17.0.2, at build/block-library/blocks/pattern.php

55 lines 1.4 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/pattern` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Registers the `core/pattern` block on the server.
10 */
11 function gutenberg_register_block_core_pattern() {
12 register_block_type_from_metadata(
13 __DIR__ . '/pattern',
14 array(
15 'render_callback' => 'gutenberg_render_block_core_pattern',
16 )
17 );
18 }
19
20 /**
21 * Renders the `core/pattern` block on the server.
22 *
23 * @since 6.3.0 Backwards compatibility: blocks with no `syncStatus` attribute do not receive block wrapper.
24 *
25 * @param array $attributes Block attributes.
26 *
27 * @return string Returns the output of the pattern.
28 */
29 function gutenberg_render_block_core_pattern( $attributes ) {
30 if ( empty( $attributes['slug'] ) ) {
31 return '';
32 }
33
34 $slug = $attributes['slug'];
35 $registry = WP_Block_Patterns_Registry::get_instance();
36
37 if ( ! $registry->is_registered( $slug ) ) {
38 return '';
39 }
40
41 $pattern = $registry->get_registered( $slug );
42 $content = $pattern['content'];
43
44 // Backward compatibility for handling Block Hooks and injecting the theme attribute in the Gutenberg plugin.
45 // This can be removed when the minimum supported WordPress is >= 6.4.
46 if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && ! function_exists( 'traverse_and_serialize_blocks' ) ) {
47 $blocks = parse_blocks( $content );
48 $content = gutenberg_serialize_blocks( $blocks );
49 }
50
51 return do_blocks( $content );
52 }
53
54 add_action( 'init', 'gutenberg_register_block_core_pattern', 20 );
55