fix: address CHRNX editorial review findings
This commit is contained in:
17 files changed
+236
-10
No files matched your search
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||
"apiVersion": 3,
|
||||
"name": "chrnx/reading-time",
|
||||
"version": "0.1.0",
|
||||
"title": "Reading Time",
|
||||
"category": "theme",
|
||||
"description": "Display a localized estimate based on the current post content.",
|
||||
"textdomain": "chrnx",
|
||||
"usesContext": ["postId", "postType"],
|
||||
"supports": { "html": false },
|
||||
"render": "file:./render.php"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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>
|
||||
Reference in new issue
Block a user