// Load a single comment by ID
if (!function_exists('load_comment_by_id_shortcode')) {
function load_comment_by_id_shortcode($atts) {
global $wpdb;
$atts = shortcode_atts(
array(
'comment_id' => '',
),
$atts,
'load_comment_by_id'
);
$comment_id = absint($atts['comment_id']);
if (empty($comment_id)) {
return '';
}
$comment = get_comment($comment_id);
if (
!$comment ||
$comment->comment_approved !== '1' ||
empty($comment->comment_post_ID)
) {
return '';
}
$post_id = (int) $comment->comment_post_ID;
$post_author_id = (int) get_post_field('post_author', $post_id);
if (!$post_author_id) {
return '';
}
$total_replies_count = get_comment_descendant_count($comment_id);
ob_start();
$half_profile_html = do_shortcode(
'[half_render_profile author_id="' . esc_attr($comment->user_id) . '"]'
);
$is_post_author = (
!empty($comment->user_id) &&
(int) $comment->user_id === $post_author_id
);
?>
<div class="comment-container01"><div class="comment-block" data-comment-id="<?php echo esc_attr($comment->comment_ID); ?>" data-post-id="<?php echo esc_attr($comment->comment_post_ID); ?>"
data-comment-level="<?php echo $comment->comment_parent ? '1' : '0'; ?>">
<div class="comment-body">
<div class="comment-author-info">
<div class="loaded-comment-author-avatar profile-btn01"
data-author-id="<?php echo esc_attr($comment->user_id); ?>"
data-temp-profile="<?php echo esc_attr($half_profile_html); ?>"><?php echo get_avatar($comment->user_id, 32); ?></div>
<div class="loaded-comment-body">
<strong>
<span class="profile-btn01"
data-author-id="<?php echo esc_attr($comment->user_id); ?>"
data-temp-profile="<?php echo esc_attr($half_profile_html); ?>">
<?php echo esc_html(get_comment_author($comment)); ?>
<?php if ($is_post_author) : ?>
<span class="author-name01"> • Author</span>
<?php endif; ?>
</span>
</strong>
<?php
if ($is_post_author) {
$comment_content = make_clickable($comment->comment_content);
$comment_content = preg_replace(
'/<a\s+([^>]*href=["\'][^"\']+["\'][^>]*)>/i',
'<a $1 target="_blank" rel="nofollow noopener ugc">',
$comment_content
);
$comment_content = wp_kses_post($comment_content);
} else {
$comment_content = esc_html($comment->comment_content);
}
?>
<div class="comment-text">
<?php echo wpautop($comment_content); ?>
</div>
<div class="comment-footer">
<small class="comment-time">
<?php
echo esc_html(
human_time_diff(
strtotime($comment->comment_date),
current_time('timestamp')
) . ' ago'
);
?>
</small>
<div class="reply-button"
data-comment-id="<?php echo esc_attr($comment->comment_ID); ?>"
data-comment-author="<?php echo esc_attr(get_comment_author($comment)); ?>">Reply</div>
</div>
</div>
</div>
</div>
<?php if ($total_replies_count > 0) : ?>
<div class="view-replies-trigger"
data-parent-comment-id="<?php echo esc_attr($comment->comment_ID); ?>"
data-replies-offset="0"
data-replies-ppp="5"
data-total-replies-count="<?php echo esc_attr($total_replies_count); ?>"
data-post-id="<?php echo esc_attr($comment->comment_post_ID); ?>"
data-replies-loaded="false"
data-original-html='<div class="view-replies-button-text">View <?php echo esc_html($total_replies_count); ?> replies <i class="fas fa-angle-down"></i></div>'>
<div class="view-replies-button-text">
View <?php echo esc_html($total_replies_count); ?> replies
<i class="fas fa-angle-down"></i>
</div>
</div>
<div class="replies-section"
style="display: none;"
data-parent-comment-id="<?php echo esc_attr($comment->comment_ID); ?>">
<div class="replies-container"></div>
<div class="replies-action-group"
style="text-align: center; margin-top: 10px;">
<span class="replies-load-more"></span>
</div>
</div>
<?php endif; ?>
<div class="comment-notif">
<div style="position:fixed; top:0; height:100%; width:100%;left:0; display:none; z-index:999999999 !important; background:black !important;" class="notif-post01 long-feed"><?php echo do_shortcode('[load_post_by_id post_id="' . esc_attr($post_id) . '"]'); ?>
<div style="padding:5px 28px; position:fixed;top:0;margin-top:12px; width:100%; left:0; display:flex; gap:5px; z-index:999999999; backgroundgrey; border-bottom1px solid #ededed;"><div onclick="hideNotifpost(this)" style="width:10%;"><i class="fa fa-arrow-left"></i> </div><div onclick="myFunction91()" class="search-toolp" style="border-radius:100px; border:1px solid #fff; padding:7px 20px; margin-top:-10px; width:90%;"><span class="search-term01">Search...</span><span style="float: right; right:0; margin-right:0px;" onclick="toggleFullpost (this)"><i class="fa fa-search"></i></span></div></div>
</div>
<div style="position: fixed; bottom:0; margin-bottom:0px; width:100%; left:0; background:#fff; padding:10px;">
<p style="text-align:center;margin:0;"><button style="background:grey; color:#ededed !important; border-radius:100px; border: 1px solid grey; width:65%;" onclick="hideNotifpost(this)">View Post »</button></p>
</div>
</div>
<div style="padding:5px 12px; position:fixed;top:0;margin-top:0px; width:100%; left:0; display:flex; gap:5px; z-index:9999999; background:#333; border-bottom:1px solid #fff;color:#fff;"><div onclick="hideNotifpost(this)" style="width:10%;"><i class="fa fa-arrow-left"></i> </div><div onclick="myFunction91pp()" class="search-toolpp" style="border-radius:100px; border1px solid #fff; padding:7px 20px; margin-top:-7px; width:90%;"><span class="search-term01">Comment</span></div></div>
</div></div>
<?php
return ob_get_clean();
}
add_shortcode('load_comment_by_id', 'load_comment_by_id_shortcode');
}
T1.7