The MU forums have moved to WordPress.org

Automatically Add User to Main Blog at Registration as Contributors (8 posts)

  1. honewatson
    Member
    Posted 15 years ago #

    I wanted new users to be automatically added to the main blog as contributors when they signed up as a User at the /wp-signup.php page.

    I made the following change in the /wp-includes/wpmu-functions.php

    function wpmu_create_user( $user_name, $password, $email) {
    if ( username_exists($user_name) )
    return false;

    // Check if the email address has been used already.
    if ( email_exists($email) )
    return false;

    $user_id = wp_create_user( $user_name, $password, $email );
    $user = new WP_User($user_id);
    // Newly created users have no roles or caps until they are added to a blog.
    update_user_option($user_id, 'capabilities', '');
    update_user_option($user_id, 'user_level', '');

    Add this to the bottom of the above lines:

    add_user_to_blog(1, $user_id, 'contributor');

  2. PBO
    Member
    Posted 14 years ago #

    add_user_to_blog(1, $user_id, 'contributor');

    does this mean 1 is the number of the home blog?

  3. PBO
    Member
    Posted 14 years ago #

    This worked as author, but I cannot author users who register as usernmame only, any hints?

  4. PBO
    Member
    Posted 14 years ago #

    here is the answer to my question

    add_user_to_blog(1, $user_id, 'author');

  5. demonicume
    Member
    Posted 14 years ago #

    'add_user_to_blog('1', $user_id, 'subscriber');'

    i see this has been included in the wpmu-functions.php, but i dont see it working for me. if i'm looking at this right, when a user creates a blog, it should send them the email and add them to blog#1.

  6. demonicume
    Member
    Posted 14 years ago #

    ok, to get this to work, hack this bit to suit your needs (As in blog# and role) and add it directly after
    'add_user_to_blog($blog_id, $user_id, 'administrator');'
    and before
    'if ( is_array($meta) ) foreach ($meta as $key => $value)'

    hey, my hacks aint pretty. but this will add new users to the blog of your choice as the role of your choice. anyone ogt a cleaner way to do this.

  7. DragonFlyEye
    Member
    Posted 14 years ago #

    Why would you hack this? Wouldn't it be easier in the long run to just hook a plugin into the user_register hook?

    http://adambrown.info/p/wp_hooks/hook/user_register

  8. demonicume
    Member
    Posted 14 years ago #

    yup, that'd be easier. thanks for the link.

    curt

About this Topic

  • Started 15 years ago by honewatson
  • Latest reply from demonicume