[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 register_block_core_pattern() { 12 register_block_type_from_metadata( 13 __DIR__ . '/pattern', 14 array( 15 'render_callback' => '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 * @global WP_Embed $wp_embed Used to process embedded content within patterns 26 * 27 * @param array $attributes Block attributes. 28 * 29 * @return string Returns the output of the pattern. 30 */ 31 function render_block_core_pattern( $attributes ) { 32 static $seen_refs = array(); 33 34 if ( empty( $attributes['slug'] ) ) { 35 return ''; 36 } 37 38 $slug = $attributes['slug']; 39 $registry = WP_Block_Patterns_Registry::get_instance(); 40 41 if ( ! $registry->is_registered( $slug ) ) { 42 return ''; 43 } 44 45 if ( isset( $seen_refs[ $attributes['slug'] ] ) ) { 46 // WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent 47 // is set in `wp_debug_mode()`. 48 $is_debug = WP_DEBUG && WP_DEBUG_DISPLAY; 49 50 return $is_debug ? 51 // translators: Visible only in the front end, this warning takes the place of a faulty block. %s represents a pattern's slug. 52 sprintf( __( '[block rendering halted for pattern "%s"]' ), $slug ) : 53 ''; 54 } 55 56 $pattern = $registry->get_registered( $slug ); 57 $content = $pattern['content']; 58 59 // Backward compatibility for handling Block Hooks and injecting the theme attribute in the Gutenberg plugin. 60 // This can be removed when the minimum supported WordPress is >= 6.4. 61 if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && ! function_exists( 'traverse_and_serialize_blocks' ) ) { 62 $blocks = parse_blocks( $content ); 63 $content = gutenberg_serialize_blocks( $blocks ); 64 } 65 66 $seen_refs[ $attributes['slug'] ] = true; 67 68 $content = do_blocks( $content ); 69 70 global $wp_embed; 71 $content = $wp_embed->autoembed( $content ); 72 73 unset( $seen_refs[ $attributes['slug'] ] ); 74 return $content; 75 } 76 77 add_action( 'init', 'register_block_core_pattern' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Wed Apr 24 08:20:01 2024 | Cross-referenced by PHPXref |