Created
June 13, 2014 02:57
-
-
Save pommiegranit/d15ee7ef196df5fe25f2 to your computer and use it in GitHub Desktop.
Applies the 'close comments after x days' to all WordPress post types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Link PDF Attachment | |
Plugin URI: http://premium.wpmudev.org | |
Description: Adds a link to the top of a WordPress post to the first PDF attachment | |
Author: Chris Knowles | |
Version: 1.0 | |
Author URI: http://twitter.com/ChrisKnowles | |
*/ | |
function check_comments_open() { | |
global $post; | |
// if the post comment status is not open then no need to worry | |
if ( $post->comment_status != 'open' ) return false; | |
// if not closing comments on old posts then also don't worry | |
if ( !get_option('close_comments_for_old_posts') ) return $post->comment_status; | |
// calculate the age (in days) of the post | |
$post_date = date_create( $post->post_date ); | |
$today = date_create(); | |
$age = date_interval_format( date_diff( $post_date , $today ) , '%a' ); | |
// if the post is older than the 'close after x days' then close comments | |
if ( $age > get_option('close_comments_days_old') ) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
add_filter( 'comments_open' , 'check_comments_open' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment