[ 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-edit-link` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/comment-edit-link` block on the server. 10 * 11 * @since 6.0.0 12 * 13 * @param array $attributes Block attributes. 14 * @param string $content Block default content. 15 * @param WP_Block $block Block instance. 16 * 17 * @return string Return the post comment's date. 18 */ 19 function render_block_core_comment_edit_link( $attributes, $content, $block ) { 20 if ( ! isset( $block->context['commentId'] ) || ! current_user_can( 'edit_comment', $block->context['commentId'] ) ) { 21 return ''; 22 } 23 24 $edit_comment_link = get_edit_comment_link( $block->context['commentId'] ); 25 26 $link_atts = ''; 27 28 if ( ! empty( $attributes['linkTarget'] ) ) { 29 $link_atts .= sprintf( 'target="%s"', esc_attr( $attributes['linkTarget'] ) ); 30 } 31 32 $classes = array(); 33 if ( isset( $attributes['textAlign'] ) ) { 34 $classes[] = 'has-text-align-' . $attributes['textAlign']; 35 } 36 if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { 37 $classes[] = 'has-link-color'; 38 } 39 40 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); 41 42 return sprintf( 43 '<div %1$s><a href="%2$s" %3$s>%4$s</a></div>', 44 $wrapper_attributes, 45 esc_url( $edit_comment_link ), 46 $link_atts, 47 esc_html__( 'Edit' ) 48 ); 49 } 50 51 /** 52 * Registers the `core/comment-edit-link` block on the server. 53 * 54 * @since 6.0.0 55 */ 56 function register_block_core_comment_edit_link() { 57 register_block_type_from_metadata( 58 __DIR__ . '/comment-edit-link', 59 array( 60 'render_callback' => 'render_block_core_comment_edit_link', 61 ) 62 ); 63 } 64 65 add_action( 'init', 'register_block_core_comment_edit_link' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Nov 21 08:20:01 2024 | Cross-referenced by PHPXref |