Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: close_comments_for_post_types

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 2 times in this file.

Line Code
2040  *
2041  * @param object $posts Post data object.
2042  * @param object $query Query object.
2043  * @return object
2044  */
2045 function _close_comments_for_old_posts( $posts, $query ) {
2046      if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )
2047           return $posts;
2048
2049      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2050      if ( ! in_array( $posts[0]->post_type, $post_types ) )
2051           return $posts;
2052
2053      $days_old = (int) get_option( 'close_comments_days_old' );
2054      if ( ! $days_old )
2055           return $posts;
2056
2057      if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
2058           $posts[0]->comment_status = 'closed';
 
Line Code
2079      if ( !get_option('close_comments_for_old_posts') )
2080           return $open;
2081
2082      $days_old = (int) get_option('close_comments_days_old');
2083      if ( !$days_old )
2084           return $open;
2085
2086      $post = get_post($post_id);
2087
2088      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2089      if ( ! in_array( $post->post_type, $post_types ) )
2090           return $open;
2091
2092      if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
2093           return false;
2094
2095      return $open;
2096 }
2097