[ 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-content` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/comment-content` 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 content. 15 */ 16 function render_block_core_comment_content( $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 $args = array(); 29 $comment_text = get_comment_text( $comment, $args ); 30 if ( ! $comment_text ) { 31 return ''; 32 } 33 34 /** This filter is documented in wp-includes/comment-template.php */ 35 $comment_text = apply_filters( 'comment_text', $comment_text, $comment, $args ); 36 37 $moderation_note = ''; 38 if ( '0' === $comment->comment_approved ) { 39 $commenter = wp_get_current_commenter(); 40 41 if ( $commenter['comment_author_email'] ) { 42 $moderation_note = __( 'Your comment is awaiting moderation.' ); 43 } else { 44 $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.' ); 45 } 46 $moderation_note = '<p><em class="comment-awaiting-moderation">' . $moderation_note . '</em></p>'; 47 if ( ! $show_pending_links ) { 48 $comment_text = wp_kses( $comment_text, array() ); 49 } 50 } 51 52 $classes = array(); 53 if ( isset( $attributes['textAlign'] ) ) { 54 $classes[] = 'has-text-align-' . $attributes['textAlign']; 55 } 56 if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { 57 $classes[] = 'has-link-color'; 58 } 59 60 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); 61 62 return sprintf( 63 '<div %1$s>%2$s%3$s</div>', 64 $wrapper_attributes, 65 $moderation_note, 66 $comment_text 67 ); 68 } 69 70 /** 71 * Registers the `core/comment-content` block on the server. 72 */ 73 function register_block_core_comment_content() { 74 register_block_type_from_metadata( 75 __DIR__ . '/comment-content', 76 array( 77 'render_callback' => 'render_block_core_comment_content', 78 ) 79 ); 80 } 81 add_action( 'init', 'register_block_core_comment_content' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Apr 25 08:20:02 2024 | Cross-referenced by PHPXref |