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
2422           return $posts;
2423
2424      /**
2425       * Filter the list of post types to automatically close comments for.
2426       *
2427       * @since 3.2.0
2428       *
2429       * @param array $post_types An array of registered post types. Default array with 'post'.
2430       */
2431      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2432      if ( ! in_array( $posts[0]->post_type, $post_types ) )
2433           return $posts;
2434
2435      $days_old = (int) get_option( 'close_comments_days_old' );
2436      if ( ! $days_old )
2437           return $posts;
2438
2439      if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
2440           $posts[0]->comment_status = 'closed';
 
Line Code
2462           return $open;
2463
2464      $days_old = (int) get_option('close_comments_days_old');
2465      if ( !$days_old )
2466           return $open;
2467
2468      $post = get_post($post_id);
2469
2470      /** This filter is documented in wp-includes/comment.php */
2471      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
2472      if ( ! in_array( $post->post_type, $post_types ) )
2473           return $open;
2474
2475      if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
2476           return false;
2477
2478      return $open;
2479 }
2480