[ Index ] |
PHP Cross Reference of WordPress |
[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 = ''; 53 if ( isset( $attributes['textAlign'] ) ) { 54 $classes .= 'has-text-align-' . $attributes['textAlign']; 55 } 56 57 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); 58 59 return sprintf( 60 '<div %1$s>%2$s%3$s</div>', 61 $wrapper_attributes, 62 $moderation_note, 63 $comment_text 64 ); 65 } 66 67 /** 68 * Registers the `core/comment-content` block on the server. 69 */ 70 function register_block_core_comment_content() { 71 register_block_type_from_metadata( 72 __DIR__ . '/comment-content', 73 array( 74 'render_callback' => 'render_block_core_comment_content', 75 ) 76 ); 77 } 78 add_action( 'init', 'register_block_core_comment_content' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:03 2024 | Cross-referenced by PHPXref 0.7.1 |