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
3112           return $posts;
3113
3114      /**
3115       * Filter the list of post types to automatically close comments for.
3116       *
3117       * @since 3.2.0
3118       *
3119       * @param array $post_types An array of registered post types. Default array with 'post'.
3120       */
3121      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
3122      if ( ! in_array( $posts[0]->post_type, $post_types ) )
3123           return $posts;
3124
3125      $days_old = (int) get_option( 'close_comments_days_old' );
3126      if ( ! $days_old )
3127           return $posts;
3128
3129      if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
3130           $posts[0]->comment_status = 'closed';
 
Line Code
3152           return $open;
3153
3154      $days_old = (int) get_option('close_comments_days_old');
3155      if ( !$days_old )
3156           return $open;
3157
3158      $post = get_post($post_id);
3159
3160      /** This filter is documented in wp-includes/comment.php */
3161      $post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
3162      if ( ! in_array( $post->post_type, $post_types ) )
3163           return $open;
3164
3165      if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) )
3166           return false;
3167
3168      return $open;
3169 }
3170