The MU forums have moved to WordPress.org

How To Set Blog For Any User To Post (7 posts)

  1. chrischee18
    Member
    Posted 14 years ago #

    How can an user be automatically registered with the role of "author" to several blogs when signing up for the first time?

    For example there are 4 blogs.

    a.blog.com
    b.blog.com
    c.blog.com
    d.blog.com

    When user "Rick" registers, I want him to be able to write posts for only :

    b.blog.com
    c.blog.com
    d.blog.com

    and NOT :

    a.blog.com

    How do I do that automatically upon sign up for every user?

  2. DeannaS
    Member
    Posted 14 years ago #

    You need to run the following code.

    <?php
    add_action('wpmu_activate_user', 'add_new_user_to_blog', 10);
    
    function add_new_user_to_blog($user_id) {
    // repeat this line with the blog id of each blog you want them added to in place of 1 - you could do it with a foreach loop
    add_user_to_blog( '1', $user_id, 'author' );
    }
    ?>
  3. chrischee18
    Member
    Posted 14 years ago #

    In which file do I insert the code above?

    Before and after which line?

    And does the code automatically give newly registered user 'author' roles to the selected blogs?

  4. DeannaS
    Member
    Posted 14 years ago #

    You'd save that code to a .php file and put it in the mu-plugins folder. It'll run whenever a new user is activated. And, yes, it makes the user an author on blogid 1, in that case.

  5. DeannaS
    Member
    Posted 14 years ago #

    I'll have a plugin out for this as soon as the new repo gets set up.

  6. chrischee18
    Member
    Posted 14 years ago #

    Thanks Deanna. Will be looking forward to try out your plugin.

  7. DeannaS
    Member
    Posted 14 years ago #

    Needs a better name...but here it is. I'm tired of trying to think of a better name....

    http://wordpress.org/extend/plugins/wpmu-default-user-role/

About this Topic

  • Started 14 years ago by chrischee18
  • Latest reply from DeannaS