Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoelLisenby/25a5a013ca6828646bced3e2c675b96e to your computer and use it in GitHub Desktop.
Save JoelLisenby/25a5a013ca6828646bced3e2c675b96e to your computer and use it in GitHub Desktop.
Disable comments and pingbacks settings for all WordPress network sites
<?php
// Disables comments and pingbacks settings for all existing sites in a WordPress network
$sites = get_sites();
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
update_option( 'default_comment_status', 'closed' );
update_option( 'default_ping_status', 'closed' );
restore_current_blog();
}
// Disable comments and pingbacks settings on new network site creation
add_action('wp_initialize_site', 'jbl_wp_initialize_site', 10, 2);
function jbl_wp_initialize_site( $site, $args ) {
switch_to_blog( $site->blog_id );
update_option( 'default_comment_status', 'closed' );
update_option( 'default_ping_status', 'closed' );
restore_current_blog();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment