[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Server-side rendering of the `core/post-author-name` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/post-author-name` block on the server. 10 * 11 * @param array $attributes Block attributes. 12 * @param string $content Block default content. 13 * @param WP_Block $block Block instance. 14 * @return string Returns the rendered post author name block. 15 */ 16 function render_block_core_post_author_name( $attributes, $content, $block ) { 17 if ( ! isset( $block->context['postId'] ) ) { 18 return ''; 19 } 20 21 $author_id = get_post_field( 'post_author', $block->context['postId'] ); 22 if ( empty( $author_id ) ) { 23 return ''; 24 } 25 26 $author_name = get_the_author_meta( 'display_name', $author_id ); 27 if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) { 28 $author_name = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a>', get_author_posts_url( $author_id ), esc_attr( $attributes['linkTarget'] ), $author_name ); 29 } 30 31 $classes = array(); 32 if ( isset( $attributes['textAlign'] ) ) { 33 $classes[] = 'has-text-align-' . $attributes['textAlign']; 34 } 35 if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { 36 $classes[] = 'has-link-color'; 37 } 38 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); 39 40 return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $author_name ); 41 } 42 43 /** 44 * Registers the `core/post-author-name` block on the server. 45 */ 46 function register_block_core_post_author_name() { 47 register_block_type_from_metadata( 48 __DIR__ . '/post-author-name', 49 array( 50 'render_callback' => 'render_block_core_post_author_name', 51 ) 52 ); 53 } 54 add_action( 'init', 'register_block_core_post_author_name' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Fri Apr 26 08:20:02 2024 | Cross-referenced by PHPXref |