Last active
May 4, 2023 16:58
-
-
Save JoelLisenby/25a5a013ca6828646bced3e2c675b96e to your computer and use it in GitHub Desktop.
Disable comments and pingbacks settings for all WordPress network sites
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 | |
// 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