[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Server-side rendering of the `core/comment-date` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/comment-date` 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 date. 15 */ 16 function render_block_core_comment_date( $attributes, $content, $block ) { 17 if ( ! isset( $block->context['commentId'] ) ) { 18 return ''; 19 } 20 21 $comment = get_comment( $block->context['commentId'] ); 22 if ( empty( $comment ) ) { 23 return ''; 24 } 25 26 $classes = ''; 27 if ( isset( $attributes['fontSize'] ) ) { 28 $classes .= 'has-' . esc_attr( $attributes['fontSize'] ) . '-font-size'; 29 } 30 31 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); 32 $formatted_date = get_comment_date( 33 isset( $attributes['format'] ) ? $attributes['format'] : '', 34 $comment 35 ); 36 $link = get_comment_link( $comment ); 37 38 if ( ! empty( $attributes['isLink'] ) ) { 39 $formatted_date = sprintf( '<a href="%1s">%2s</a>', esc_url( $link ), $formatted_date ); 40 } 41 42 return sprintf( 43 '<div %1$s><time datetime="%2$s">%3$s</time></div>', 44 $wrapper_attributes, 45 esc_attr( get_comment_date( 'c', $comment ) ), 46 $formatted_date 47 ); 48 } 49 50 /** 51 * Registers the `core/comment-date` block on the server. 52 */ 53 function register_block_core_comment_date() { 54 register_block_type_from_metadata( 55 __DIR__ . '/comment-date', 56 array( 57 'render_callback' => 'render_block_core_comment_date', 58 ) 59 ); 60 } 61 add_action( 'init', 'register_block_core_comment_date' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |