Last active
August 29, 2015 14:23
-
-
Save mattheu/380c841e611a64ab329b to your computer and use it in GitHub Desktop.
Close comments for new autodrafts
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
<?php | |
/** | |
* Set default comment status to closed for woocommerce products. | |
*/ | |
add_filter( 'wp_insert_post_data', function( $data, $postarr ) { | |
// Auto draft is the status given to the initial post created | |
// when visiting the 'add new product' page in the WP-Admin. | |
// This still allows posts to be created programatically with comments open. | |
// This will default to the value of `default_comment_status` | |
if ( 'product' === $data['post_type'] && 'auto-draft' === $data['post_status'] ) { | |
$data['comment_status'] = 'closed'; | |
$data['ping_status'] = 'closed'; | |
} | |
return $data; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment