fix: address CHRNX editorial review findings
This commit is contained in:
17 files changed
+236
-10
No files matched your search
+29
-1
@@ -17,6 +17,34 @@ function chrnx_get_heading_level( $value, $fallback_level = 2 ) {
|
||||
return in_array( $level, array( 2, 3, 4, 5, 6 ), true ) ? $level : $fallback_level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate localized reading time from stored post content without rendering it.
|
||||
*
|
||||
* @param string $content Raw post content.
|
||||
* @return int Estimated whole minutes, or zero for empty content.
|
||||
*/
|
||||
function chrnx_get_reading_time_minutes( $content ) {
|
||||
if ( ! is_string( $content ) || '' === trim( $content ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$text = preg_replace( '/<!--(?:.|\s)*?-->/', ' ', strip_shortcodes( $content ) );
|
||||
$text = html_entity_decode( wp_strip_all_tags( (string) $text, true ), ENT_QUOTES | ENT_HTML5, 'UTF-8' );
|
||||
$text = wp_check_invalid_utf8( $text );
|
||||
if ( '' === trim( $text ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( str_starts_with( wp_get_word_count_type(), 'characters' ) ) {
|
||||
$characters = preg_replace( '/\s+/u', '', $text );
|
||||
$count = mb_strlen( (string) $characters, 'UTF-8' );
|
||||
return max( 1, (int) ceil( $count / 500 ) );
|
||||
}
|
||||
|
||||
$count = preg_match_all( "/[\p{L}\p{N}]+(?:['’\x{2010}-\x{2015}-][\p{L}\p{N}]+)*/u", $text );
|
||||
return false === $count || 0 === $count ? 0 : max( 1, (int) ceil( $count / 200 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a post's meaningful featured image or decorative topic fallback.
|
||||
*
|
||||
@@ -74,7 +102,7 @@ function chrnx_get_editorial_card_markup( $post_id, $heading_level = 3, $class_n
|
||||
|
||||
/** Register all block metadata directories that exist. */
|
||||
function chrnx_register_editorial_blocks() {
|
||||
$blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools' );
|
||||
$blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link' );
|
||||
foreach ( $blocks as $block ) {
|
||||
$name = 'chrnx/' . $block;
|
||||
if ( WP_Block_Type_Registry::get_instance()->is_registered( $name ) ) {
|
||||
|
||||
Reference in new issue
Block a user