[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Server-side rendering of the `core/read-more` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/read-more` 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 Returns the post link. 15 */ 16 function render_block_core_read_more( $attributes, $content, $block ) { 17 if ( ! isset( $block->context['postId'] ) ) { 18 return ''; 19 } 20 21 $post_ID = $block->context['postId']; 22 $post_title = get_the_title( $post_ID ); 23 if ( '' === $post_title ) { 24 $post_title = sprintf( 25 /* translators: %s is post ID to describe the link for screen readers. */ 26 __( 'untitled post %s' ), 27 $post_ID 28 ); 29 } 30 $screen_reader_text = sprintf( 31 /* translators: %s is either the post title or post ID to describe the link for screen readers. */ 32 __( ': %s' ), 33 $post_title 34 ); 35 $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; 36 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) ); 37 $more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' ); 38 return sprintf( 39 '<a %1s href="%2s" target="%3s">%4s<span class="screen-reader-text">%5s</span></a>', 40 $wrapper_attributes, 41 get_the_permalink( $post_ID ), 42 esc_attr( $attributes['linkTarget'] ), 43 $more_text, 44 $screen_reader_text 45 ); 46 } 47 48 /** 49 * Registers the `core/read-more` block on the server. 50 */ 51 function register_block_core_read_more() { 52 register_block_type_from_metadata( 53 __DIR__ . '/read-more', 54 array( 55 'render_callback' => 'render_block_core_read_more', 56 ) 57 ); 58 } 59 add_action( 'init', 'register_block_core_read_more' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Tue Apr 23 08:20:01 2024 | Cross-referenced by PHPXref |