The MU forums have moved to WordPress.org

OK OK. Limit 1 user 1 blog. Finally... (8 posts)

  1. ducdigital
    Member
    Posted 16 years ago #

    OK. After searching around for nothing and stick around with those lazy coder who don't bother to look inside the code or those who dont want to share the trick.

    After a while reading the WP-SIGNUP.PHP I found out that it's supper easy to limit ONE user ONE blog...

    The reason why i CAPITALIZE the word ONE because the thing that i modify is juz simply not let anyone with a blog account register anymore...

    And here we go...
    -------------------------------------
    Go to WP-Signup.php

    search for:

    if ( is_user_logged_in() && ( $active_signup == 'all' || $active_signup == 'blog' ) ) {
    signup_another_blog($newblogname);

    replace

    signup_another_blog($newblogname);

    with:

    if ( ! empty($blogscheck) ) {
    			signup_another_blog($newblogname);
    		}
    		else
    		{
    		echo "<h2>Sorry!</h2><p>Sorry, but you only allow to create 1 blog for your account</p><p><a href='http://www.animomo.net/'>Back to homepage</a></p>";
    		}

    -----------------------------------

    That's all!

    Isnt it easy. I hope someone can give me feed back about this.

    Try it at http://www.animomo.net/

  2. ducdigital
    Member
    Posted 16 years ago #

    Final Edit: Work for Admin, fix bugs...

    Replace with these instead:

    $blogscheck = get_blogs_of_user($current_user->ID);
    		$blogarrayvalue = (get_object_vars($blogscheck[1]));
    		$blogsiteURL = "http://animomo.net";
    		if ($blogarrayvalue[siteurl] == $blogsiteURL) {
    			signup_another_blog($newblogname);
    		}
    		else
    		{
    		echo "<h2>Sorry!</h2><p>Sorry, but you only allow to create 1 blog for your account</p><p><a href='http://www.animomo.net/'>Back to homepage</a></p>";
    		}
  3. ColourDreamer
    Member
    Posted 16 years ago #

    Thanks so much!

  4. lunabyte
    Member
    Posted 16 years ago #

    nevermind

  5. jjelinek
    Member
    Posted 16 years ago #

    The first version worked fine for me.... The second version gave me a blank page... Thanks for the hard work!

  6. dsader
    Member
    Posted 16 years ago #

    Alternative to editing a core file exist. A plugin can be made with code from wpmu-functions.php:

    http://mu.wordpress.org/forums/topic.php?id=4064&page&replies=14

  7. iamcrazymoon
    Member
    Posted 15 years ago #

    I alread try the below code :

    'Go to WP-Signup.php

    search for:

    if ( is_user_logged_in() && ( $active_signup == 'all' || $active_signup == 'blog' ) ) {
    signup_another_blog($newblogname);replace

    signup_another_blog($newblogname);

    with:

    if ( ! empty($blogscheck) ) {
    signup_another_blog($newblogname);
    }
    else
    {
    echo "<h2>Sorry!</h2><p>Sorry, but you only allow to create 1 blog for your account</p><p>Back to homepage</p>";
    }-----------------------------------

    '

    But finally, it made the user even cannot create the first blog (0 blog)...

    For your information, I set my website as:
    visitor must
    1) firstly, register as user (get the login id)
    2) then login
    3) create a blog
    (my website don't want visitors to create blog directly, must register a login, first)

    but after I add the above code.
    when doing the step 3), system told the user "but you only allow to create 1 blog"!!
    Also that user control panel was linkded to admin's (my control panel), but sure, that user have no authoririty to change things..

    Do you think,
    If I set 2 blogs per user can solve the problem,
    if so, how to set?

    or I missed somthing?

  8. sbrajesh
    Member
    Posted 15 years ago #

    well, you may have a look at my plugin i recently created.It will add an option to SiteAdmin->options page ,where you can limit number of blogs per user.
    Here is the code ,which does it.
    '<?php
    add_filter("wpmu_active_signup","tiw_check_current_users_blog"); //send fake/true enable or disabled request
    add_action("wpmu_options","tiw_display_options_form"); //show the form to allow how many number of blogs per user
    add_action("update_wpmu_options","tiw_save_num_allowed_blogs");//action to save number of allowed blogs per user

    /****Check ,whether blog registration is allowed,and how many blogs per logged in user is allowed */

    function tiw_check_current_users_blog($active_signup)
    {
    if( !is_user_logged_in() )
    return $active_signup;//if the user is not logged in,do not change the site policies

    //otherwise...
    global $current_user;
    $blogs=get_blogs_of_user($current_user->ID);//get all blogs of user

    $number_of_blogs_per_user=tiw_num_allowed_blogs();//find

    //if number of allowed blog is greater than 0 and current user owns less number of blogs */
    if($number_of_blogs_per_user>0&&count($blogs)<$number_of_blogs_per_user)
    return $active_signup;
    else
    return "none";
    }

    /****How many blogs are allowed per user *************/

    function tiw_num_allowed_blogs()
    {
    $num_allowed_blog=get_site_option("tiw_allowed_blogs_per_user");//find how many blogs are allowed
    if(!isset($num_allowed_blog))
    $num_allowed_blog=0;

    return $num_allowed_blog;//return the number of allowed blogs
    }

    /*****Show the Number of Blogs to restrict per user at the bottom of Site options ****/
    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
    }

    /**************Save the Number of blogs per user when the form is updated **************/
    function tiw_save_num_allowed_blogs()
    {
    $allowed_number_of_blogs=intval($_POST["num_allowed_blogs"]);//how many blogs the user has set
    //save to the database
    update_site_option("tiw_allowed_blogs_per_user",$allowed_number_of_blogs);//now update

    }
    ?>'
    or if you wish to have the plugin you may have a look here http://www.thinkinginwordpress.com/2009/03/limit-number-of-blogs-per-user-for-wordpress-mu-and-buddypress-websiteblog-network/
    Sorry,admins,if you think,linking my page is against rules, please remove that,as I have already posted the code here.

    regards
    Brajesh

About this Topic

  • Started 16 years ago by ducdigital
  • Latest reply from sbrajesh