返回介绍

_close_comments_for_old_posts()

发布于 2017-09-11 13:15:16 字数 2173 浏览 903 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_close_comments_for_old_posts( WP_Post $posts,  WP_Query $query )

Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.


description


参数

$posts

(WP_Post) (Required) Post data object.

$query

(WP_Query) (Required) Query object.


返回值

(array)


源代码

File: wp-includes/comment.php

function _close_comments_for_old_posts( $posts, $query ) {
	if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )
		return $posts;

	/**
	 * Filters the list of post types to automatically close comments for.
	 *
	 * @since 3.2.0
	 *
	 * @param array $post_types An array of registered post types. Default array with 'post'.
	 */
	$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
	if ( ! in_array( $posts[0]->post_type, $post_types ) )
		return $posts;

	$days_old = (int) get_option( 'close_comments_days_old' );
	if ( ! $days_old )
		return $posts;

	if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
		$posts[0]->comment_status = 'closed';
		$posts[0]->ping_status = 'closed';
	}

	return $posts;
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_option()
  • wp-includes/comment.php: close_comments_for_post_types

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文