Globally Disable Comments and Pings in WordPress Multi-Site

October 7th, 2011  |  Published in Mind

Over the past couple years I’ve worked on a number of WordPress Multi-Sites that wanted to have their comments and pings disabled. In other words, they weren’t accepting comments and didn’t want them to be displayed. Normally this is easy to accomplish, simply turn off comments in the back end.

However, SPAMMERS knowing exactly how WordPress works and how to inject comment SPAM into WordPress. Though, if you do not have comments automatically approved, they definitely should not appear… if a comment does get injected, the WordPress administrator (and author) should receive a notification of a pending comment. So, there is a simple way in WordPress Multi-Site to just set all comment and ping submissions to false. Just stick this little bit of code into a php file in the mu-plugins directory:

add_filter( 'pings_open', '__return_false', 10, 2 );
add_filter( 'comments_open', '__return_false', 10, 2 );

One of the Multi-Site installations that I have this enabled in wanted to allow comments on two of their sites. If this is something you need, just setup a mu-plugin php file that looks like this:

function comments_and_pings_closed( $open, $post_id ) {

	global $blog_id;

	$comment_sites = array( 10, 15 ); // Site IDs of site that you don't want automatically disabled

	if ( in_array( $blog_id, $comment_sites ) ) {

		return $open;

	}

	return false;

}
add_filter( 'pings_open', 'comments_and_pings_closed', 10, 2 );
add_filter( 'comments_open', 'comments_and_pings_closed', 10, 2 );

Tags: , , , ,

Update Arguments for the WordPress Built-in Tag Cloud Widget

July 11th, 2010  |  Published in Mind

Usually I’d just call the wp_tag_cloud() function manually from a WordPress theme file, but I have a client who wants to use the Tag Cloud Widget on their site. The tag cloud widget has been in WordPress since WP 2.3. Unfortunately, it isn’t the easiest widget to use because you can’t customize it from the backend.

Luckily there are two filters that can be used to set the arguments your client needs and maintain the ability for them to modify the widget location from the WordPress backend.

  1. widget_tag_cloud_args – lets you set the wp_tag_cloud arguments
  2. wp_tag_cloud – lets you edit the wp_tag_cloud output

So, for my clients need’s, I just needed to set the small and large font size arguments and change the widget output a little to fit their sidebar properly. I added these lines to the theme’s function.php:

function tag_cloud_args() {
	$args = array( 'smallest' => 8, 'largest' => 14 );
	return $args;
}
add_filter('widget_tag_cloud_args', 'tag_cloud_args');

function tag_cloud($return) {
	$return = "<div class="box menu tags">" . $return . "</div>";
	return $return;
}
add_filter('wp_tag_cloud', 'tag_cloud');

As with any function in WordPress, be sure to check out the codex for all the Tag Cloud Arguments that you can use.

Tags: , , , ,