Code To Apply Blog Limit Per User In WordPress MU

Posted by

Hi,

WordPress is an open source tool and we can apply the changes as we desired..This kind of changes called hack in the techncal terms. In this post,

I have  provided details about a hack for wordpress MU. You can apply the limit number of blogs per user in wordpress MU blog. To do that please

perform these steps:

1) Save this code in any php [Example: wpmu-blog-limit.php] file:

<?php
add_filter(“wpmu_active_signup”,”tiw_check_current_users_blog”);
add_action(“wpmu_options”,”tiw_display_options_form”);
add_action(“update_wpmu_options”,”tiw_save_num_allowed_blogs”);

function tiw_check_current_users_blog($active_signup)
{
if( !is_user_logged_in() )
return $active_signup;

global $current_user;
$blogs=get_blogs_of_user($current_user->ID);
$number_of_blogs_per_user=tiw_num_allowed_blogs();
if($number_of_blogs_per_user>0&&count($blogs)<$number_of_blogs_per_user)
return $active_signup;
else
return “none”;
}

function tiw_num_allowed_blogs()
{
$num_allowed_blog=get_site_option(“tiw_allowed_blogs_per_user”);
if(!isset($num_allowed_blog))
$num_allowed_blog=0;

return $num_allowed_blog;
}

function tiw_display_options_form()
{
?>
<h3><?php _e(‘Limit Blog Registrations Per User’) ?></h3>
<table>
<tbody>
<tr valign=”top”>
<th scope=”row”>Number of blogs allowed per User</th>
<td>
<input type=”text” name=”num_allowed_blogs” value=”<?php echo tiw_num_allowed_blogs()?>” />
<p>If the Value is Zero,It indicates any number of blog is allowed</p>
</td>
</tr>
</tbody>
</table>
<?php
}

function tiw_save_num_allowed_blogs()
{
$allowed_number_of_blogs=intval($_POST[“num_allowed_blogs”]);
update_site_option(“tiw_allowed_blogs_per_user”,$allowed_number_of_blogs);
}
?>

Download Sample Code

2) Upload this php file in plugins directory.
3) Login into wordpress MU admin and Activate this plugin.
4) Now, Click on site admin -> options buttom.
wpmu_options
5) You will find an option to set number of limit blogs per user option at the bottom of the page.
wpmu_blog_limit
6) Apply the desired figure and save the changes. Set 0 for unlimited.

That’s it!

Thanks,

Shane G.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.