PluginProbe
Gutenberg / 16.2.0
Gutenberg v16.2.0
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 16.2.0, at build/block-library/blocks/pattern.php

46 lines 966 B
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 * @return void
12 */
13 function gutenberg_register_block_core_pattern() {
14 register_block_type_from_metadata(
15 __DIR__ . '/pattern',
16 array(
17 'render_callback' => 'gutenberg_render_block_core_pattern',
18 )
19 );
20 }
21
22 /**
23 * Renders the `core/pattern` block on the server.
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 return do_blocks( $pattern['content'] );
43 }
44
45 add_action( 'init', 'gutenberg_register_block_core_pattern', 20 );
46