Files

24 lines
791 B
PHP

<?php
/**
* Reading Time block render.
*
* @package CHRNX
*/
$chrnx_post_id = isset( $block->context['postId'] ) ? absint( $block->context['postId'] ) : get_the_ID();
$chrnx_post = get_post( $chrnx_post_id );
if ( ! $chrnx_post instanceof WP_Post ) {
return;
}
$chrnx_minutes = chrnx_get_reading_time_minutes( $chrnx_post->post_content );
if ( 0 === $chrnx_minutes ) {
return;
}
$chrnx_label = sprintf(
/* translators: %s: estimated reading time in minutes. */
_n( '%s minute read', '%s minutes read', $chrnx_minutes, 'chrnx' ),
number_format_i18n( $chrnx_minutes )
);
?>
<span <?php echo get_block_wrapper_attributes( array( 'class' => 'chrnx-reading-time' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>><?php echo esc_html( $chrnx_label ); ?></span>