[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Server-side rendering of the `core/widget-group` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the 'core/widget-group' block. 10 * 11 * @param array $attributes The block attributes. 12 * @param string $content The block content. 13 * @param WP_Block $block The block. 14 * 15 * @return string Rendered block. 16 */ 17 function render_block_core_widget_group( $attributes, $content, $block ) { 18 global $wp_registered_sidebars, $_sidebar_being_rendered; 19 20 if ( isset( $wp_registered_sidebars[ $_sidebar_being_rendered ] ) ) { 21 $before_title = $wp_registered_sidebars[ $_sidebar_being_rendered ]['before_title']; 22 $after_title = $wp_registered_sidebars[ $_sidebar_being_rendered ]['after_title']; 23 } else { 24 $before_title = '<h2 class="widget-title">'; 25 $after_title = '</h2>'; 26 } 27 28 $html = ''; 29 30 if ( ! empty( $attributes['title'] ) ) { 31 $html .= $before_title . $attributes['title'] . $after_title; 32 } 33 34 $html .= '<div class="wp-widget-group__inner-blocks">'; 35 foreach ( $block->inner_blocks as $inner_block ) { 36 $html .= $inner_block->render(); 37 } 38 $html .= '</div>'; 39 40 return $html; 41 } 42 43 /** 44 * Registers the 'core/widget-group' block. 45 */ 46 function register_block_core_widget_group() { 47 register_block_type_from_metadata( 48 __DIR__ . '/widget-group', 49 array( 50 'render_callback' => 'render_block_core_widget_group', 51 ) 52 ); 53 } 54 55 add_action( 'init', 'register_block_core_widget_group' ); 56 57 /** 58 * Make a note of the sidebar being rendered before WordPress starts rendering 59 * it. This lets us get to the current sidebar in 60 * render_block_core_widget_group(). 61 * 62 * @param int|string $index Index, name, or ID of the dynamic sidebar. 63 */ 64 function note_sidebar_being_rendered( $index ) { 65 global $_sidebar_being_rendered; 66 $_sidebar_being_rendered = $index; 67 } 68 add_action( 'dynamic_sidebar_before', 'note_sidebar_being_rendered' ); 69 70 /** 71 * Clear whatever we set in note_sidebar_being_rendered() after WordPress 72 * finishes rendering a sidebar. 73 */ 74 function discard_sidebar_being_rendered() { 75 global $_sidebar_being_rendered; 76 unset( $_sidebar_being_rendered ); 77 } 78 add_action( 'dynamic_sidebar_after', 'discard_sidebar_being_rendered' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |