Disabling Comments Globally/Sitewide on a Multisite
-
The Problem:
———–
You have over 3000 sites/blogs on a WPMU site and the requirement is to disable comment postings for all sites. Ignore the reason for no comment, the requirement for whatever reason is to turn off comment posting. Also when a new site is added, say 3001, comments must also be turned as well as for all future sites.The Long Way:
————
Check off comments in each of the 3000+ sites daashboard? Not feasible.The Solution:
———–
For Multisite Only:create a new file under wp-content/mu-plugins directory call it disable_comments.php Files under this path, are loaded early in the WP boot process and do not need manual activation. Add the following code to disable_comments.php file: <? $blog_id = get_current_blog_id(); if ($blog_id > 0) { add_filter('comments_open', 'change_comments_open_to_close'); add_filter('comments_template','load_no_comments_template'); } function change_comments_open_to_close() { echo 'Comments Off'; return false; } function load_no_comments_template() { return dirname(__FILE__).'/extra/comments.php'; } ?> Now create a new subdirectory under mu-plugins called extra, mu-plugins/extra and create a new file under this directory called comments.php, mu-plugins/extra/comments.php Files located in subdirectories under mu-plugin are safe from loading during the boot process. Now edit mu-plugins/extra/comments.php and add the following code, <?php echo '<h2>Comments have been disabled!</h2>'; ?>
[Please use the code buttons when posting code here]Now to explain what will happen,
when WP checks to see if it should create a comment form, will the comments_template filter, by returning a new comment template filename, that WP will check via file_exists, you over any other comment template.The comments_open tag is check and returns an override status that comments are closed.
- The topic ‘Disabling Comments Globally/Sitewide on a Multisite’ is closed to new replies.