' . ThemeData::notice(__('The comments of the post appear here.', 'zadex')) . '', \Zadex\Frontend\Kses::allowed_html()); } return; } $zx_post_id = (int) $zx_post->ID; $open = function_exists('comments_open') ? comments_open($zx_post_id) : false; $count = function_exists('get_comments_number') ? (int) get_comments_number($zx_post_id) : 0; if (!$open && $count === 0) { if (ThemeData::is_preview()) { echo wp_kses('
' . ThemeData::notice(__('Comments are closed for this post.', 'zadex')) . '
', \Zadex\Frontend\Kses::allowed_html()); } return; } $source = ThemeData::tag($settings['source'] ?? 'auto', ['auto', 'theme', 'zadex'], 'auto'); $use_theme = $source === 'theme' || ($source === 'auto' && function_exists('locate_template') && locate_template('comments.php') !== ''); // comments_template() only prints on singular views (is_single() / is_page()). Elsewhere (editor / REST previews, // archives) the list and the form are rendered directly, so no WordPress global has to be forced. $use_theme = $use_theme && function_exists('comments_template') && function_exists('is_singular') && is_singular(); // The widget's post is the current post while WordPress prints the comments (template tags, reply links). $html = (string) \Zadex\Frontend\PostData::with($zx_post, static function () use ($use_theme, $zx_post_id, $count, $open): string { if ($use_theme) { ob_start(); comments_template(); return (string) ob_get_clean(); } $out = ''; $zx_comments = function_exists('get_comments') ? get_comments(['post_id' => $zx_post_id, 'status' => 'approve', 'order' => 'ASC']) : []; if ($zx_comments) { /* translators: %s: number of comments */ $out .= '

' . esc_html(sprintf(_n('%s comment', '%s comments', $count, 'zadex'), number_format_i18n($count))) . '

' . '
    ' . (string) wp_list_comments(['style' => 'ol', 'avatar_size' => 48, 'short_ping' => true, 'echo' => false], $zx_comments) . '
'; } if ($open && function_exists('comment_form')) { ob_start(); comment_form([], $zx_post_id); $out .= (string) ob_get_clean(); } return $out; }); // The comments list / form is WordPress's own markup: stored by Kses::protect() and restored at the output boundary. echo wp_kses('
' . \Zadex\Frontend\Kses::protect($html) . "
\n", \Zadex\Frontend\Kses::allowed_html());