_close_comments_for_old_posts
函数
_close_comments_for_old_posts ( $posts, $query )
- Access
- Private
- 参数
-
-
(WP_Post)
$posts
Post data object.- Required: 是
-
(WP_Query)
$query
Query object.- Required: 是
-
(WP_Post)
- 返回值
-
- (array)
- 定义位置
-
-
wp-includes/comment.php
, line 3355
-
wp-includes/comment.php
- 引入
- 2.7.0
- 弃用
- –
Closes comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
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 string[] $post_types An array of post type names. */ $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) ); if ( ! in_array( $posts[0]->post_type, $post_types, true ) ) { 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; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。