Created
January 5, 2019 08:53
-
-
Save Tsunamijaan/0e5f14e792968af9183709c645f1586e to your computer and use it in GitHub Desktop.
Automatically Disable comments on posts over one month
This file contains hidden or 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
| function close_comments( $posts ) { | |
| if ( !is_single() ) { return $posts; } | |
| if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( 30 * 24 * 60 * 60 ) ) { | |
| $posts[0]->comment_status = 'closed'; | |
| $posts[0]->ping_status = 'closed'; | |
| } | |
| return $posts; | |
| } | |
| add_filter( 'the_posts', 'close_comments' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment