_close_comments_for_old_post

函数
_close_comments_for_old_post ( $open, $post_id )
Access
Private
参数
  • (bool) $open Comments open or closed.
    Required:
  • (int) $post_id Post ID.
    Required:
返回值
  • (bool) $open
定义位置
相关方法
_close_comments_for_old_postswp_latest_comments_draft_or_post_titlewp_set_comment_cookieswp_check_comment_floodcheck_comment_flood_db
引入
2.7.0
弃用
-

close_comments_for_old_post: 这个函数用来关闭旧文章的评论。它接受一个文章的ID和一个可选的$days参数,它指定了评论应该被关闭的天数。如果评论被成功关闭,它返回true,否则返回false。

关闭旧文章的评论。与 comments_open 和 pings_open 挂钩。

function _close_comments_for_old_post( $open, $post_id ) {
	if ( ! $open ) {
		return $open;
	}

	if ( ! get_option( 'close_comments_for_old_posts' ) ) {
		return $open;
	}

	$days_old = (int) get_option( 'close_comments_days_old' );
	if ( ! $days_old ) {
		return $open;
	}

	$post = get_post( $post_id );

	/** This filter is documented in wp-includes/comment.php */
	$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
	if ( ! in_array( $post->post_type, $post_types, true ) ) {
		return $open;
	}

	// Undated drafts should not show up as comments closed.
	if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
		return $open;
	}

	if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
		return false;
	}

	return $open;
}

常见问题

FAQs
查看更多 >