- md5
- 9546ca188f1ceb1b81319aaeb259d55f
- sha1
- a6b5181e40d3bab2128514928e50c105e8eb4e21
- sha256
- 9df034d6cc59127afdfa2877be1f3acbc55059e2fee193684af73b07bff3efe5
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
<?php
/**
* Server-side rendering of the `core/read-more` block.
*
* @package WordPress
*/
/**
* Renders the `core/read-more` block on the server.
*
* @since 6.0.0
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
* @return string Returns the post link.
*/
function render_block_core_read_more( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$post_ID = $block->context['postId'];
$post_title = get_the_title( $post_ID );
if ( '' === $post_title ) {
$post_title = sprintf(
/* translators: %s is post ID to describe the link for screen readers. */
__( 'untitled post %s' ),
$post_ID
);
}
$screen_reader_text = sprintf(
/* translators: %s is either the post title or post ID to describe the link for screen readers. */
__( ': %s' ),
$post_title
);
$justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}";
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) );
$more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' );
return sprintf(
'<a %1$s href="%2$s" target="%3$s">%4$s<span class="screen-reader-text">%5$s</span></a>',
$wrapper_attributes,
esc_url( get_the_permalink( $post_ID ) ),
esc_attr( $attributes['linkTarget'] ),
$more_text,
$screen_reader_text
);
}
/**
* Registers the `core/read-more` block on the server.
*
* @since 6.0.0
*/
function register_block_core_read_more() {
register_block_type_from_metadata(
__DIR__ . '/read-more',
array(
'render_callback' => 'render_block_core_read_more',
)
);
}
add_action( 'init', 'register_block_core_read_more' );
The same content is in 6 releases, WordPress 7.2-beta1 to 7.2-RC1. See them all, or every version of this file.