WordPress MU not adding new users as subscribers to main blog

If you’re using WordPress MU you may have run into a problem where new users aren’t added as subscribers to the main blog (blogid: 1). Some may prefer it this way but I ran into this issue on Stampin Corner because I also wanted users to be able to post in the help forums which use BBPress. For some reason nobody could post in there, and it turns out this was the reason.

According to the developers BBPress is a bit behind handling this integration and it’s assumed at some point it will. That said, I got around this irksome problem by creating my own little plugin. (Actually I maintain a custom-functions plugin for just this type of thing). It’s pretty simple really, just create a new file in your mu-plugins directory and this code to it.

//--------------------------------------------------------//
//---Hook-------------------------------------------------//
//--------------------------------------------------------//
add_action('wpmu_activate_blog', 'add_new_user_to_mainblog', 10,2);
add_action('wpmu_new_blog', 'add_new_user_to_mainblog', 10,2);

//--------------------------------------------------------//
//---Functions---------------------------------------------//
//--------------------------------------------------------//
function add_new_user_to_mainblog($blog_id, $user_id) {
	add_user_to_blog( '1', $user_id, 'subscriber' );
}

Basically all this is doing is using the hook wpmu_activate_blog to trigger the function add_user_to_blog. WPMU also has this habit (not sure why exactly) of removing an existing user from the main blog when they reated another new blog. Not a huge deal again but problematic if they haven’t logged into BBPress already. So the second add_action triggers on wpmu_new_blog to add the user back.

Simple as that. Of course, this doesn’t handle getting any existing users set as subscribers so you’ll have to do those manually or write a script to do it, but any new users should get added just fine.