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
1962  *
1963  * @param object $posts Post data object.
1964  * @param object $query Query object.
1965  * @return object
1966  */
1967 function _close_comments_for_old_posts( $posts, $query ) {
1968      if ( empty( $posts ) || ! $query->is_singular() || ! get_option( 'close_comments_for_old_posts' ) )
1969           return $posts;
1970
1971      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
1972      if ( ! in_array( $posts[0]->post_type, $post_types ) )
1973           return $posts;
1974
1975      $days_old = (int) get_option( 'close_comments_days_old' );
1976      if ( ! $days_old )
1977           return $posts;
1978
1979      if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) ) {
1980           $posts[0]->comment_status = 'closed';
 
Line Code
2001      if ( !get_option('close_comments_for_old_posts') )
2002           return $open;
2003
2004      $days_old = (int) get_option('close_comments_days_old');
2005      if ( !$days_old )
2006           return $open;
2007
2008      $post = get_post($post_id);
2009
2010      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2011      if ( ! in_array( $post->post_type, $post_types ) )
2012           return $open;
2013
2014      if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) )
2015           return false;
2016
2017      return $open;
2018 }
2019