web/wp-includes/comment.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
   125  *
   125  *
   126  * @param object|string|int $comment Comment to retrieve.
   126  * @param object|string|int $comment Comment to retrieve.
   127  * @param string $output Optional. OBJECT or ARRAY_A or ARRAY_N constants.
   127  * @param string $output Optional. OBJECT or ARRAY_A or ARRAY_N constants.
   128  * @return object|array|null Depends on $output value.
   128  * @return object|array|null Depends on $output value.
   129  */
   129  */
   130 function &get_comment(&$comment, $output = OBJECT) {
   130 function get_comment(&$comment, $output = OBJECT) {
   131 	global $wpdb;
   131 	global $wpdb;
   132 	$null = null;
   132 	$null = null;
   133 
   133 
   134 	if ( empty($comment) ) {
   134 	if ( empty($comment) ) {
   135 		if ( isset($GLOBALS['comment']) )
   135 		if ( isset($GLOBALS['comment']) )
   188  * WordPress Comment Query class.
   188  * WordPress Comment Query class.
   189  *
   189  *
   190  * @since 3.1.0
   190  * @since 3.1.0
   191  */
   191  */
   192 class WP_Comment_Query {
   192 class WP_Comment_Query {
       
   193 	/**
       
   194 	 * Metadata query container
       
   195 	 *
       
   196 	 * @since 3.5.0
       
   197 	 * @access public
       
   198 	 * @var object WP_Meta_Query
       
   199 	 */
       
   200 	var $meta_query = false;
   193 
   201 
   194 	/**
   202 	/**
   195 	 * Execute the query
   203 	 * Execute the query
   196 	 *
   204 	 *
   197 	 * @since 3.1.0
   205 	 * @since 3.1.0
   220 			'post_type' => '',
   228 			'post_type' => '',
   221 			'status' => '',
   229 			'status' => '',
   222 			'type' => '',
   230 			'type' => '',
   223 			'user_id' => '',
   231 			'user_id' => '',
   224 			'search' => '',
   232 			'search' => '',
   225 			'count' => false
   233 			'count' => false,
       
   234 			'meta_key' => '',
       
   235 			'meta_value' => '',
       
   236 			'meta_query' => '',
   226 		);
   237 		);
   227 
   238 
       
   239 		$groupby = '';
       
   240 
   228 		$this->query_vars = wp_parse_args( $query_vars, $defaults );
   241 		$this->query_vars = wp_parse_args( $query_vars, $defaults );
       
   242 
       
   243 		// Parse meta query
       
   244 		$this->meta_query = new WP_Meta_Query();
       
   245 		$this->meta_query->parse_query_vars( $this->query_vars );
       
   246 
   229 		do_action_ref_array( 'pre_get_comments', array( &$this ) );
   247 		do_action_ref_array( 'pre_get_comments', array( &$this ) );
   230 		extract( $this->query_vars, EXTR_SKIP );
   248 		extract( $this->query_vars, EXTR_SKIP );
   231 
   249 
   232 		// $args can be whatever, only use the args defined in defaults to compute the key
   250 		// $args can be whatever, only use the args defined in defaults to compute the key
   233 		$key = md5( serialize( compact(array_keys($defaults)) )  );
   251 		$key = md5( serialize( compact(array_keys($defaults)) )  );
   234 		$last_changed = wp_cache_get('last_changed', 'comment');
   252 		$last_changed = wp_cache_get( 'last_changed', 'comment' );
   235 		if ( !$last_changed ) {
   253 		if ( ! $last_changed )
   236 			$last_changed = time();
   254 			$last_changed = wp_cache_set( 'last_changed', 1, 'comment' );
   237 			wp_cache_set('last_changed', $last_changed, 'comment');
       
   238 		}
       
   239 		$cache_key = "get_comments:$key:$last_changed";
   255 		$cache_key = "get_comments:$key:$last_changed";
   240 
   256 
   241 		if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {
   257 		if ( $cache = wp_cache_get( $cache_key, 'comment' ) )
   242 			return $cache;
   258 			return $cache;
   243 		}
       
   244 
   259 
   245 		$post_id = absint($post_id);
   260 		$post_id = absint($post_id);
   246 
   261 
   247 		if ( 'hold' == $status )
   262 		if ( 'hold' == $status )
   248 			$approved = "comment_approved = '0'";
   263 			$approved = "comment_approved = '0'";
   249 		elseif ( 'approve' == $status )
   264 		elseif ( 'approve' == $status )
   250 			$approved = "comment_approved = '1'";
   265 			$approved = "comment_approved = '1'";
   251 		elseif ( 'spam' == $status )
   266 		elseif ( ! empty( $status ) && 'all' != $status )
   252 			$approved = "comment_approved = 'spam'";
   267 			$approved = $wpdb->prepare( "comment_approved = %s", $status );
   253 		elseif ( 'trash' == $status )
       
   254 			$approved = "comment_approved = 'trash'";
       
   255 		else
   268 		else
   256 			$approved = "( comment_approved = '0' OR comment_approved = '1' )";
   269 			$approved = "( comment_approved = '0' OR comment_approved = '1' )";
   257 
   270 
   258 		$order = ( 'ASC' == strtoupper($order) ) ? 'ASC' : 'DESC';
   271 		$order = ( 'ASC' == strtoupper($order) ) ? 'ASC' : 'DESC';
   259 
   272 
   260 		if ( ! empty( $orderby ) ) {
   273 		if ( ! empty( $orderby ) ) {
   261 			$ordersby = is_array($orderby) ? $orderby : preg_split('/[,\s]/', $orderby);
   274 			$ordersby = is_array($orderby) ? $orderby : preg_split('/[,\s]/', $orderby);
   262 			$ordersby = array_intersect(
   275 			$allowed_keys = array(
   263 				$ordersby,
   276 				'comment_agent',
   264 				array(
   277 				'comment_approved',
   265 					'comment_agent',
   278 				'comment_author',
   266 					'comment_approved',
   279 				'comment_author_email',
   267 					'comment_author',
   280 				'comment_author_IP',
   268 					'comment_author_email',
   281 				'comment_author_url',
   269 					'comment_author_IP',
   282 				'comment_content',
   270 					'comment_author_url',
   283 				'comment_date',
   271 					'comment_content',
   284 				'comment_date_gmt',
   272 					'comment_date',
   285 				'comment_ID',
   273 					'comment_date_gmt',
   286 				'comment_karma',
   274 					'comment_ID',
   287 				'comment_parent',
   275 					'comment_karma',
   288 				'comment_post_ID',
   276 					'comment_parent',
   289 				'comment_type',
   277 					'comment_post_ID',
   290 				'user_id',
   278 					'comment_type',
       
   279 					'user_id',
       
   280 				)
       
   281 			);
   291 			);
       
   292 			if ( ! empty( $this->query_vars['meta_key'] ) ) {
       
   293 				$allowed_keys[] = $q['meta_key'];
       
   294 				$allowed_keys[] = 'meta_value';
       
   295 				$allowed_keys[] = 'meta_value_num';
       
   296 			}
       
   297 			$ordersby = array_intersect( $ordersby, $allowed_keys );
       
   298 			foreach ( $ordersby as $key => $value ) {
       
   299 				if ( $value == $q['meta_key'] || $value == 'meta_value' ) {
       
   300 					$ordersby[ $key ] = "$wpdb->commentmeta.meta_value";
       
   301 				} elseif ( $value == 'meta_value_num' ) {
       
   302 					$ordersby[ $key ] = "$wpdb->commentmeta.meta_value+0";
       
   303 				}
       
   304 			}
   282 			$orderby = empty( $ordersby ) ? 'comment_date_gmt' : implode(', ', $ordersby);
   305 			$orderby = empty( $ordersby ) ? 'comment_date_gmt' : implode(', ', $ordersby);
   283 		} else {
   306 		} else {
   284 			$orderby = 'comment_date_gmt';
   307 			$orderby = 'comment_date_gmt';
   285 		}
   308 		}
   286 
   309 
   329 			$join = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
   352 			$join = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID";
   330 			foreach( $post_fields as $field_name => $field_value )
   353 			foreach( $post_fields as $field_name => $field_value )
   331 				$where .= $wpdb->prepare( " AND {$wpdb->posts}.{$field_name} = %s", $field_value );
   354 				$where .= $wpdb->prepare( " AND {$wpdb->posts}.{$field_name} = %s", $field_value );
   332 		}
   355 		}
   333 
   356 
   334 		$pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' );
   357 		if ( ! empty( $this->meta_query->queries ) ) {
       
   358 			$clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this );
       
   359 			$join .= $clauses['join'];
       
   360 			$where .= $clauses['where'];
       
   361 			$groupby = "{$wpdb->comments}.comment_ID";
       
   362 		}
       
   363 
       
   364 		$pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits', 'groupby' );
   335 		$clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
   365 		$clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) );
   336 		foreach ( $pieces as $piece )
   366 		foreach ( $pieces as $piece )
   337 			$$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
   367 			$$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
   338 
   368 
   339 		$query = "SELECT $fields FROM $wpdb->comments $join WHERE $where ORDER BY $orderby $order $limits";
   369 		if ( $groupby )
       
   370 			$groupby = 'GROUP BY ' . $groupby;
       
   371 
       
   372 		$query = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby ORDER BY $orderby $order $limits";
   340 
   373 
   341 		if ( $count )
   374 		if ( $count )
   342 			return $wpdb->get_var( $query );
   375 			return $wpdb->get_var( $query );
   343 
   376 
   344 		$comments = $wpdb->get_results( $query );
   377 		$comments = $wpdb->get_results( $query );
   397 /**
   430 /**
   398  * The date the last comment was modified.
   431  * The date the last comment was modified.
   399  *
   432  *
   400  * @since 1.5.0
   433  * @since 1.5.0
   401  * @uses $wpdb
   434  * @uses $wpdb
   402  * @global array $cache_lastcommentmodified
       
   403  *
   435  *
   404  * @param string $timezone Which timezone to use in reference to 'gmt', 'blog',
   436  * @param string $timezone Which timezone to use in reference to 'gmt', 'blog',
   405  *		or 'server' locations.
   437  *		or 'server' locations.
   406  * @return string Last comment modified date.
   438  * @return string Last comment modified date.
   407  */
   439  */
   408 function get_lastcommentmodified($timezone = 'server') {
   440 function get_lastcommentmodified($timezone = 'server') {
   409 	global $cache_lastcommentmodified, $wpdb;
   441 	global $wpdb;
       
   442 	static $cache_lastcommentmodified = array();
   410 
   443 
   411 	if ( isset($cache_lastcommentmodified[$timezone]) )
   444 	if ( isset($cache_lastcommentmodified[$timezone]) )
   412 		return $cache_lastcommentmodified[$timezone];
   445 		return $cache_lastcommentmodified[$timezone];
   413 
   446 
   414 	$add_seconds_server = date('Z');
   447 	$add_seconds_server = date('Z');
   634 	global $wpdb;
   667 	global $wpdb;
   635 	extract($commentdata, EXTR_SKIP);
   668 	extract($commentdata, EXTR_SKIP);
   636 
   669 
   637 	// Simple duplicate check
   670 	// Simple duplicate check
   638 	// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
   671 	// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
   639 	$dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved != 'trash' AND ( comment_author = '$comment_author' ";
   672 	$dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_parent = '$comment_parent' AND comment_approved != 'trash' AND ( comment_author = '$comment_author' ";
   640 	if ( $comment_author_email )
   673 	if ( $comment_author_email )
   641 		$dupe .= "OR comment_author_email = '$comment_author_email' ";
   674 		$dupe .= "OR comment_author_email = '$comment_author_email' ";
   642 	$dupe .= ") AND comment_content = '$comment_content' LIMIT 1";
   675 	$dupe .= ") AND comment_content = '$comment_content' LIMIT 1";
   643 	if ( $wpdb->get_var($dupe) ) {
   676 	if ( $wpdb->get_var($dupe) ) {
   644 		do_action( 'comment_duplicate_trigger', $commentdata );
   677 		do_action( 'comment_duplicate_trigger', $commentdata );
   648 		wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
   681 		wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
   649 	}
   682 	}
   650 
   683 
   651 	do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );
   684 	do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );
   652 
   685 
   653 	if ( isset($user_id) && $user_id) {
   686 	if ( ! empty( $user_id ) ) {
   654 		$userdata = get_userdata($user_id);
   687 		$user = get_userdata( $user_id );
   655 		$user = new WP_User($user_id);
       
   656 		$post_author = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", $comment_post_ID));
   688 		$post_author = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1", $comment_post_ID));
   657 	}
   689 	}
   658 
   690 
   659 	if ( isset($userdata) && ( $user_id == $post_author || $user->has_cap('moderate_comments') ) ) {
   691 	if ( isset( $user ) && ( $user_id == $post_author || $user->has_cap( 'moderate_comments' ) ) ) {
   660 		// The author and the admins get respect.
   692 		// The author and the admins get respect.
   661 		$approved = 1;
   693 		$approved = 1;
   662 	 } else {
   694 	 } else {
   663 		// Everyone else's comments will be checked.
   695 		// Everyone else's comments will be checked.
   664 		if ( check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type) )
   696 		if ( check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type) )
   692  */
   724  */
   693 function check_comment_flood_db( $ip, $email, $date ) {
   725 function check_comment_flood_db( $ip, $email, $date ) {
   694 	global $wpdb;
   726 	global $wpdb;
   695 	if ( current_user_can( 'manage_options' ) )
   727 	if ( current_user_can( 'manage_options' ) )
   696 		return; // don't throttle admins
   728 		return; // don't throttle admins
   697 	$hour_ago = gmdate( 'Y-m-d H:i:s', time() - 3600 );
   729 	$hour_ago = gmdate( 'Y-m-d H:i:s', time() - HOUR_IN_SECONDS );
   698 	if ( $lasttime = $wpdb->get_var( $wpdb->prepare( "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email ) ) ) {
   730 	if ( $lasttime = $wpdb->get_var( $wpdb->prepare( "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email ) ) ) {
   699 		$time_lastcomment = mysql2date('U', $lasttime, false);
   731 		$time_lastcomment = mysql2date('U', $lasttime, false);
   700 		$time_newcomment  = mysql2date('U', $date, false);
   732 		$time_newcomment  = mysql2date('U', $date, false);
   701 		$flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
   733 		$flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
   702 		if ( $flood_die ) {
   734 		if ( $flood_die ) {
   716  * @since 2.7.0
   748  * @since 2.7.0
   717  *
   749  *
   718  * @param array $comments Array of comments
   750  * @param array $comments Array of comments
   719  * @return array Array of comments keyed by comment_type.
   751  * @return array Array of comments keyed by comment_type.
   720  */
   752  */
   721 function &separate_comments(&$comments) {
   753 function separate_comments(&$comments) {
   722 	$comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array());
   754 	$comments_by_type = array('comment' => array(), 'trackback' => array(), 'pingback' => array(), 'pings' => array());
   723 	$count = count($comments);
   755 	$count = count($comments);
   724 	for ( $i = 0; $i < $count; $i++ ) {
   756 	for ( $i = 0; $i < $count; $i++ ) {
   725 		$type = $comments[$i]->comment_type;
   757 		$type = $comments[$i]->comment_type;
   726 		if ( empty($type) )
   758 		if ( empty($type) )
  1256 		wp_update_comment_count($comment_post_ID);
  1288 		wp_update_comment_count($comment_post_ID);
  1257 
  1289 
  1258 	$comment = get_comment($id);
  1290 	$comment = get_comment($id);
  1259 	do_action('wp_insert_comment', $id, $comment);
  1291 	do_action('wp_insert_comment', $id, $comment);
  1260 
  1292 
       
  1293 	if ( function_exists( 'wp_cache_incr' ) ) {
       
  1294 		wp_cache_incr( 'last_changed', 1, 'comment' );
       
  1295 	} else {
       
  1296 		$last_changed = wp_cache_get( 'last_changed', 'comment' );
       
  1297 		wp_cache_set( 'last_changed', $last_changed + 1, 'comment' );
       
  1298 	}
       
  1299 
  1261 	return $id;
  1300 	return $id;
  1262 }
  1301 }
  1263 
  1302 
  1264 /**
  1303 /**
  1265  * Filters and sanitizes comment data.
  1304  * Filters and sanitizes comment data.
  1364 
  1403 
  1365 	if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching
  1404 	if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching
  1366 		if ( '0' == $commentdata['comment_approved'] )
  1405 		if ( '0' == $commentdata['comment_approved'] )
  1367 			wp_notify_moderator($comment_ID);
  1406 			wp_notify_moderator($comment_ID);
  1368 
  1407 
  1369 		$post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment
  1408 		$post = get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment
  1370 
  1409 
  1371 		if ( get_option('comments_notify') && $commentdata['comment_approved'] && ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) )
  1410 		if ( get_option('comments_notify') && $commentdata['comment_approved'] && ( ! isset( $commentdata['user_id'] ) || $post->post_author != $commentdata['user_id'] ) )
  1372 			wp_notify_postauthor($comment_ID, isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );
  1411 			wp_notify_postauthor($comment_ID, isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '' );
  1373 	}
  1412 	}
  1374 
  1413 
  1477 	else if ( 'hold' == $comment_approved )
  1516 	else if ( 'hold' == $comment_approved )
  1478 		$comment_approved = 0;
  1517 		$comment_approved = 0;
  1479 	else if ( 'approve' == $comment_approved )
  1518 	else if ( 'approve' == $comment_approved )
  1480 		$comment_approved = 1;
  1519 		$comment_approved = 1;
  1481 
  1520 
  1482 	$data = compact('comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt');
  1521 	$data = compact( 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_parent' );
  1483 	$rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
  1522 	$rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
  1484 
  1523 
  1485 	clean_comment_cache($comment_ID);
  1524 	clean_comment_cache($comment_ID);
  1486 	wp_update_comment_count($comment_post_ID);
  1525 	wp_update_comment_count($comment_post_ID);
  1487 	do_action('edit_comment', $comment_ID);
  1526 	do_action('edit_comment', $comment_ID);
  1702  * @param int $post_id Post ID to do trackbacks on.
  1741  * @param int $post_id Post ID to do trackbacks on.
  1703  */
  1742  */
  1704 function do_trackbacks($post_id) {
  1743 function do_trackbacks($post_id) {
  1705 	global $wpdb;
  1744 	global $wpdb;
  1706 
  1745 
  1707 	$post = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id) );
  1746 	$post = get_post( $post_id );
  1708 	$to_ping = get_to_ping($post_id);
  1747 	$to_ping = get_to_ping($post_id);
  1709 	$pinged  = get_pung($post_id);
  1748 	$pinged  = get_pung($post_id);
  1710 	if ( empty($to_ping) ) {
  1749 	if ( empty($to_ping) ) {
  1711 		$wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post_id) );
  1750 		$wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post_id) );
  1712 		return;
  1751 		return;
  1927  */
  1966  */
  1928 function clean_comment_cache($ids) {
  1967 function clean_comment_cache($ids) {
  1929 	foreach ( (array) $ids as $id )
  1968 	foreach ( (array) $ids as $id )
  1930 		wp_cache_delete($id, 'comment');
  1969 		wp_cache_delete($id, 'comment');
  1931 
  1970 
  1932 	wp_cache_set('last_changed', time(), 'comment');
  1971 	if ( function_exists( 'wp_cache_incr' ) ) {
       
  1972 		wp_cache_incr( 'last_changed', 1, 'comment' );
       
  1973 	} else {
       
  1974 		$last_changed = wp_cache_get( 'last_changed', 'comment' );
       
  1975 		wp_cache_set( 'last_changed', $last_changed + 1, 'comment' );
       
  1976 	}
  1933 }
  1977 }
  1934 
  1978 
  1935 /**
  1979 /**
  1936  * Updates the comment cache of given comments.
  1980  * Updates the comment cache of given comments.
  1937  *
  1981  *
  1974 
  2018 
  1975 	$days_old = (int) get_option( 'close_comments_days_old' );
  2019 	$days_old = (int) get_option( 'close_comments_days_old' );
  1976 	if ( ! $days_old )
  2020 	if ( ! $days_old )
  1977 		return $posts;
  2021 		return $posts;
  1978 
  2022 
  1979 	if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) ) {
  2023 	if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
  1980 		$posts[0]->comment_status = 'closed';
  2024 		$posts[0]->comment_status = 'closed';
  1981 		$posts[0]->ping_status = 'closed';
  2025 		$posts[0]->ping_status = 'closed';
  1982 	}
  2026 	}
  1983 
  2027 
  1984 	return $posts;
  2028 	return $posts;
  2009 
  2053 
  2010 	$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
  2054 	$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
  2011 	if ( ! in_array( $post->post_type, $post_types ) )
  2055 	if ( ! in_array( $post->post_type, $post_types ) )
  2012 		return $open;
  2056 		return $open;
  2013 
  2057 
  2014 	if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) )
  2058 	if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
  2015 		return false;
  2059 		return false;
  2016 
  2060 
  2017 	return $open;
  2061 	return $open;
  2018 }
  2062 }