PluginProbe
Gutenberg / 10.5.3
Gutenberg v10.5.3
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 / block.php

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

73 lines 1.8 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/block` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `core/block` block on server.
10 *
11 * @param array $attributes The block attributes.
12 *
13 * @return string Rendered HTML of the referenced block.
14 */
15 function gutenberg_render_block_core_block( $attributes ) {
16 static $seen_refs = array();
17
18 if ( empty( $attributes['ref'] ) ) {
19 return '';
20 }
21
22 $reusable_block = get_post( $attributes['ref'] );
23 if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) {
24 return '';
25 }
26
27 if ( isset( $seen_refs[ $attributes['ref'] ] ) ) {
28 if ( ! is_admin() ) {
29 trigger_error(
30 sprintf(
31 // translators: %s is the user-provided title of the reusable block.
32 __( 'Could not render Reusable Block <strong>%s</strong>. Block cannot be rendered inside itself.' ),
33 $reusable_block->post_title
34 ),
35 E_USER_WARNING
36 );
37 }
38
39 // WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
40 // is set in `wp_debug_mode()`.
41 $is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
42 defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
43
44 return $is_debug ?
45 // translators: Visible only in the front end, this warning takes the place of a faulty block.
46 __( '[block rendering halted]' ) :
47 '';
48 }
49
50 if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) {
51 return '';
52 }
53
54 $seen_refs[ $attributes['ref'] ] = true;
55
56 $result = do_blocks( $reusable_block->post_content );
57 unset( $seen_refs[ $attributes['ref'] ] );
58 return $result;
59 }
60
61 /**
62 * Registers the `core/block` block.
63 */
64 function gutenberg_register_block_core_block() {
65 register_block_type_from_metadata(
66 __DIR__ . '/block',
67 array(
68 'render_callback' => 'gutenberg_render_block_core_block',
69 )
70 );
71 }
72 add_action( 'init', 'gutenberg_register_block_core_block', 20 );
73