';
unset( $attributes['title'] );
} else {
$content = implode( PHP_EOL, wp_list_pluck( $block->parsed_block['innerBlocks'], 'innerHTML' ) );
// Hide empty headings.
if ( empty( wp_strip_all_tags( $content ) ) ) {
$content = '';
}
}
// Get the Post ID from attributes or use the current post.
$_post_id = $attributes['postId'] ?? get_the_ID();
// Don't leak reaction metadata for posts that are not currently publicly queryable.
if ( ! is_post_publicly_queryable( $_post_id ) ) {
return;
}
// The counts style is a line of plain links, for example in place of the comments link in a query loop.
if ( str_contains( $attributes['className'] ?? '', 'is-style-counts' ) ) {
$links = array();
foreach ( Blocks::get_reaction_types() as $_type => $type_object ) {
if ( 'comment' === $_type ) {
// Like the comments link, the comment count shows as long as comments are open.
$count = (int) get_comments_number( $_post_id );
if ( ! $count && ! comments_open( $_post_id ) ) {
continue;
}
$links[] = array(
'url' => get_comments_link( $_post_id ),
'icon' => $type_object['icon'],
'count' => $count,
'label' => get_comments_number_text( false, false, false, $_post_id ),
);
continue;
}
$count = Interactions::count_by_type( $_post_id, $_type );
if ( ! $count ) {
continue;
}
// There is no page that lists reactions, so they link to the post with the full reactions block.
$links[] = array(
'url' => get_permalink( $_post_id ),
'icon' => $type_object['icon'],
'count' => $count,
// phpcs:ignore WordPress.WP.I18n
'label' => sprintf( _n( $type_object['count_single'], $type_object['count_plural'], $count, 'activitypub' ), number_format_i18n( $count ) ),
);
}
if ( empty( $links ) ) {
echo '';
return;
}
?>