WordPress告诉用户文章N天之后即将关闭评论

/**
 * Supercool snippet of WPEngineer to inform your users that you will close the comments in xdays
 * The function calculates the difference between today and how many days there are left.
 *
 * @source: //wpengineer.com/2692/inform-user-about-automatic-comment-closing-time/
 */
add_action( 'comment_form_top', 'so_topic_closes_in' );
function so_topic_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( __( '(This topic will automatically close in %s. )', 'textdomain' ),  human_time_diff( $expires ) );
    }
}

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据