WordPress 定时关闭评论以及告知用户评论关闭的时间

丹桂飘香、秋风萧瑟、黄叶遍地。当头顶掠过个性的风,我知道,十一月来了。虽然红枫妖娆,野草还在坚持,可,白杨还是降下了翠绿的旗帜。一行雁鸣慢慢合拢台幕,盛宴即将结束。

在 WordPress 后台 设置-讨论,我们可以设置自动关闭发布了多少天后的文章评论:

但是用户并不知道文章的关闭评论的时间,我们可以在评论表单上方添加一个提示:

要实现这个功能,只需要将下面的代码添加到当前主题的 functions.php 即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
 * WordPress 告知用户评论关闭的时间
 * https://www.wpdaxue.com/automatic-comment-closing.html
 */
add_action( 'comment_form_top', 'wpdx_comment_closes_in' );
function wpdx_comment_closes_in() {
    global $post;
    if ($post->comment_status == 'open') {
        $close_comments_days_old = get_option( 'close_comments_days_old' );
        $expires = strtotime( "{$post->post_date_gmt} GMT" ) +  $close_comments_days_old * DAY_IN_SECONDS;
        printf( __( '(该文章的评论功能将在 %s 后关闭)', 'domain' ),  human_time_diff( $expires ));
    }
}

/** * WordPress 告知用户评论关闭的时间 * https://www.wpdaxue.com/automatic-comment-closing.html */ add_action( 'comment_form_top', 'wpdx_comment_closes_in' ); function wpdx_comment_closes_in() { global $post; if ($post->comment_status == 'open') { $close_comments_days_old = get_option( 'close_comments_days_old' ); $expires = strtotime( "{$post->post_date_gmt} GMT" ) + $close_comments_days_old * DAY_IN_SECONDS; printf( __( '(该文章的评论功能将在 %s 后关闭)', 'domain' ), human_time_diff( $expires )); } }

参考资料:http://wpengineer.com/2692/inform-user-about-automatic-comment-closing-time/

本文WordPress 定时关闭评论以及告知用户评论关闭的时间到此结束。在避风的港湾里,找不到昂扬的帆。小编再次感谢大家对我们的支持!

您可能有感兴趣的文章
WordPress站点Gravatar头像前后台不显示的如何解决办法

WordPress主题需要支持https吗?WordPress站点如何如何实现https?

WordPress站点的页面/标签/分类URL地址如何添加.html?

WordPress站点更换了域名后数据库应该如何操作替换新旧域名?

WordPress安装在主机空间的什么目录里面?根目录在哪里?