5 * @package WordPress |
5 * @package WordPress |
6 */ |
6 */ |
7 |
7 |
8 /** |
8 /** |
9 * Renders the `core/read-more` block on the server. |
9 * Renders the `core/read-more` block on the server. |
|
10 * |
|
11 * @since 6.0.0 |
10 * |
12 * |
11 * @param array $attributes Block attributes. |
13 * @param array $attributes Block attributes. |
12 * @param string $content Block default content. |
14 * @param string $content Block default content. |
13 * @param WP_Block $block Block instance. |
15 * @param WP_Block $block Block instance. |
14 * @return string Returns the post link. |
16 * @return string Returns the post link. |
16 function render_block_core_read_more( $attributes, $content, $block ) { |
18 function render_block_core_read_more( $attributes, $content, $block ) { |
17 if ( ! isset( $block->context['postId'] ) ) { |
19 if ( ! isset( $block->context['postId'] ) ) { |
18 return ''; |
20 return ''; |
19 } |
21 } |
20 |
22 |
21 $post_ID = $block->context['postId']; |
23 $post_ID = $block->context['postId']; |
|
24 $post_title = get_the_title( $post_ID ); |
|
25 if ( '' === $post_title ) { |
|
26 $post_title = sprintf( |
|
27 /* translators: %s is post ID to describe the link for screen readers. */ |
|
28 __( 'untitled post %s' ), |
|
29 $post_ID |
|
30 ); |
|
31 } |
|
32 $screen_reader_text = sprintf( |
|
33 /* translators: %s is either the post title or post ID to describe the link for screen readers. */ |
|
34 __( ': %s' ), |
|
35 $post_title |
|
36 ); |
22 $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; |
37 $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; |
23 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) ); |
38 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) ); |
24 $more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' ); |
39 $more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' ); |
25 return sprintf( |
40 return sprintf( |
26 '<a %1s href="%2s" target="%3s">%4s</a>', |
41 '<a %1s href="%2s" target="%3s">%4s<span class="screen-reader-text">%5s</span></a>', |
27 $wrapper_attributes, |
42 $wrapper_attributes, |
28 get_the_permalink( $post_ID ), |
43 get_the_permalink( $post_ID ), |
29 esc_attr( $attributes['linkTarget'] ), |
44 esc_attr( $attributes['linkTarget'] ), |
30 $more_text |
45 $more_text, |
|
46 $screen_reader_text |
31 ); |
47 ); |
32 } |
48 } |
33 |
49 |
34 /** |
50 /** |
35 * Registers the `core/read-more` block on the server. |
51 * Registers the `core/read-more` block on the server. |
|
52 * |
|
53 * @since 6.0.0 |
36 */ |
54 */ |
37 function register_block_core_read_more() { |
55 function register_block_core_read_more() { |
38 register_block_type_from_metadata( |
56 register_block_type_from_metadata( |
39 __DIR__ . '/read-more', |
57 __DIR__ . '/read-more', |
40 array( |
58 array( |