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
2030  *
2031  * @param object $posts Post data object.
2032  * @param object $query Query object.
2033  * @return object
2034  */
2035 function _close_comments_for_old_posts( $posts, $query ) {
2036      if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )
2037           return $posts;
2038
2039      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2040      if ( ! in_array( $posts[0]->post_type, $post_types ) )
2041           return $posts;
2042
2043      $days_old = (int) get_option( 'close_comments_days_old' );
2044      if ( ! $days_old )
2045           return $posts;
2046
2047      if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
2048           $posts[0]->comment_status = 'closed';
 
Line Code
2069      if ( !get_option('close_comments_for_old_posts') )
2070           return $open;
2071
2072      $days_old = (int) get_option('close_comments_days_old');
2073      if ( !$days_old )
2074           return $open;
2075
2076      $post = get_post($post_id);
2077
2078      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2079      if ( ! in_array( $post->post_type, $post_types ) )
2080           return $open;
2081
2082      if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
2083           return false;
2084
2085      return $open;
2086 }
2087