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

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

2014-11-20_095300_wpdaxue_com

 

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

2014-11-20_100020_wpdaxue_com

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

/**
 * 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/

来源:

https://www.wpdaxue.com/automatic-comment-closing.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33102.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?