[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Server-side rendering of the `core/comment-author-name` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/comment-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 Return the post comment's author. 15 */ 16 function render_block_core_comment_author_name( $attributes, $content, $block ) { 17 if ( ! isset( $block->context['commentId'] ) ) { 18 return ''; 19 } 20 21 $comment = get_comment( $block->context['commentId'] ); 22 $commenter = wp_get_current_commenter(); 23 $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author']; 24 if ( empty( $comment ) ) { 25 return ''; 26 } 27 28 $classes = array(); 29 if ( isset( $attributes['textAlign'] ) ) { 30 $classes[] = 'has-text-align-' . $attributes['textAlign']; 31 } 32 if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { 33 $classes[] = 'has-link-color'; 34 } 35 36 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); 37 $comment_author = get_comment_author( $comment ); 38 $link = get_comment_author_url( $comment ); 39 40 if ( ! empty( $link ) && ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) { 41 $comment_author = sprintf( '<a rel="external nofollow ugc" href="%1s" target="%2s" >%3s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $comment_author ); 42 } 43 if ( '0' === $comment->comment_approved && ! $show_pending_links ) { 44 $comment_author = wp_kses( $comment_author, array() ); 45 } 46 47 return sprintf( 48 '<div %1$s>%2$s</div>', 49 $wrapper_attributes, 50 $comment_author 51 ); 52 } 53 54 /** 55 * Registers the `core/comment-author-name` block on the server. 56 */ 57 function register_block_core_comment_author_name() { 58 register_block_type_from_metadata( 59 __DIR__ . '/comment-author-name', 60 array( 61 'render_callback' => 'render_block_core_comment_author_name', 62 ) 63 ); 64 } 65 add_action( 'init', 'register_block_core_comment_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 |