[ 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` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/post-author` 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 author block. 15 */ 16 function render_block_core_post_author( $attributes, $content, $block ) { 17 if ( ! isset( $block->context['postId'] ) ) { 18 $author_id = get_query_var( 'author' ); 19 } else { 20 $author_id = get_post_field( 'post_author', $block->context['postId'] ); 21 } 22 23 if ( empty( $author_id ) ) { 24 return ''; 25 } 26 27 $avatar = ! empty( $attributes['avatarSize'] ) ? get_avatar( 28 $author_id, 29 $attributes['avatarSize'] 30 ) : null; 31 32 $link = get_author_posts_url( $author_id ); 33 $author_name = get_the_author_meta( 'display_name', $author_id ); 34 if ( ! empty( $attributes['isLink'] && ! empty( $attributes['linkTarget'] ) ) ) { 35 $author_name = sprintf( '<a href="%1$s" target="%2$s">%3$s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $author_name ); 36 } 37 38 $byline = ! empty( $attributes['byline'] ) ? $attributes['byline'] : false; 39 $classes = array(); 40 if ( isset( $attributes['itemsJustification'] ) ) { 41 $classes[] = 'items-justified-' . $attributes['itemsJustification']; 42 } 43 if ( isset( $attributes['textAlign'] ) ) { 44 $classes[] = 'has-text-align-' . $attributes['textAlign']; 45 } 46 if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { 47 $classes[] = 'has-link-color'; 48 } 49 50 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); 51 52 return sprintf( '<div %1$s>', $wrapper_attributes ) . 53 ( ! empty( $attributes['showAvatar'] ) ? '<div class="wp-block-post-author__avatar">' . $avatar . '</div>' : '' ) . 54 '<div class="wp-block-post-author__content">' . 55 ( ! empty( $byline ) ? '<p class="wp-block-post-author__byline">' . wp_kses_post( $byline ) . '</p>' : '' ) . 56 '<p class="wp-block-post-author__name">' . $author_name . '</p>' . 57 ( ! empty( $attributes['showBio'] ) ? '<p class="wp-block-post-author__bio">' . get_the_author_meta( 'user_description', $author_id ) . '</p>' : '' ) . 58 '</div>' . 59 '</div>'; 60 } 61 62 /** 63 * Registers the `core/post-author` block on the server. 64 */ 65 function register_block_core_post_author() { 66 register_block_type_from_metadata( 67 __DIR__ . '/post-author', 68 array( 69 'render_callback' => 'render_block_core_post_author', 70 ) 71 ); 72 } 73 add_action( 'init', 'register_block_core_post_author' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Wed Apr 24 08:20:01 2024 | Cross-referenced by PHPXref |