Skip to:
Content
Pages
Categories
Search
Top
Bottom

set default Role of new user


  • Mike Pratt
    Participant

    @mikepratt

    before I go digging and get myself into trouble, is it simply possible to set the default role of a new user to Author (of the main – and in my case, only) blog?

Viewing 25 replies - 1 through 25 (of 27 total)

  • gogoplata
    Participant

    @gogoplata

    Sure is! From the dashboard go to Site Admin->Blogs->Edit (for the main blog) and change “Default Role” to “author”.


    Mike Pratt
    Participant

    @mikepratt

    Thanks, Gogo!


    Mike Pratt
    Participant

    @mikepratt

    No Joy. When I went to Site Admin -> Blogs -> and changed the Default Role to “Author” (also tried “author”) but every time I register a new user it shows up in my main blog as “Administrator” and if you look at the user under the Site Admin -> Users menu it says they are a Subscriber.

    So which is it? Are there roles for both the User and the main blog that are different? I also tried a plugin found here https://mu.wordpress.org/forums/topic.php?id=4166

    no love. this is a biggie for me so I’ll be so so gracious if someone has insight! Thanks,

    Mike


    nicolagreco
    Participant

    @nicolagreco

    bp doesn’t create users in canonical way..(i think, i’ve never seen that piece of code).

    You should add a filter/action to the bp function that creates users,

    Nicola,

    BP Guru (<– too funny this :-)


    gogoplata
    Participant

    @gogoplata

    In wp-includeswpmu-functions.php change this:

    add_user_to_blog(‘1’, $user_id, ‘subscriber’);

    to this:

    add_user_to_blog(‘1’, $user_id, ‘author’);

    That should take care of all future signups, however existing users will be unchanged. If you don’t have too many users yet you can simply manually change them to authors, however, if you have a lot of signups check out this thread for a way to mass add users as authors.


    Burt Adsit
    Participant

    @burtadsit

    Hey Mike. The default role can be changed by mysite.org/wp-admin/options.php. The ‘default_role’ setting. Make it ‘author’ lower case. Save. This why you were hunting me on irc? :)


    gogoplata
    Participant

    @gogoplata

    Not sure if it’s a problem on my install only, but I modified default_role at /wp-admin/options.php and /wp-admin/wpmu-blogs.php?action=editblog&id=1 but new signups were still subscribers, not authors. I remember working on this previously and the only way I was able to change it was to do as I outlined above, though others may be able to simply change default_role in the dashboard.


    Mike Pratt
    Participant

    @mikepratt

    Gogo – I had/have the same issue so I am going to try a function as per rec from Nicola

    Burt – wanted to run another issue (which I may have solved but I am seriously nervous about opening up to users) IM, Phone, email, any way (prefer IM or Phone)


    Burt Adsit
    Participant

    @burtadsit

    @gogoplata I still have no idea what that area Site Admin > Blogs > Edit is for. It’s confusing and I just ignore it. ‘default_role’ in options.php doesn’t do anything? Gotta go try it…


    Burt Adsit
    Participant

    @burtadsit

    Yep. You’re right gogoplata. It just ignores it. I set default_role to contributor and new user gets ‘no role’. Looked in mu Trac and the mu forums. Lots of confusion and noise over this issue. You’d think it would be simple, direct and unconfused by now. It isn’t.

    I see devs posting patches and reports in trac and donncha replying something to the effect of:

    ‘this is a patch to patch the patch for a bug in rXXXXX so that the bug patch can be fixed on fix #XXX on patch of the fix for #XXX’

    I’m just walking away from this one and if I had to care about this myself I’d do things your way. :)


    gogoplata
    Participant

    @gogoplata

    Yeah, this problem should be as easy as having wpmu-functions fetch the user-specified role whereas right now “subscriber” is hardcoded into the file.

    Good luck with getting a function working Mike, if all else fails the technique above is verified to work and is as easy as modifying a single file. Shouldn’t take more than 2 minutes max. Then, when upgrading, just re-modify it. Simple as that.


    nicolagreco
    Participant

    @nicolagreco

    adding an action that do that and change registred users role with a sql query, is so difficult?

    add an action like

    default_role() {

    add_user_to_blog(‘1’, $current_user->ID, ‘author’);

    }

    or a thing like that,

    Nicola,

    BP Guru


    Mike Pratt
    Participant

    @mikepratt

    Nicola – What action would you hook that code into? Also – will the add_user function also serve to just “update” the user’s role as well? It wasn’t clear to me upon inspection of the WPMU code. In BP I can find all the code that specifies the creation of a new user Blog but since I have that turned off, it never is called. I am still trying to find the code that adds a user to the BP Main Blog (add_user is never called that i can see. Where do you suppose this is being set?


    Mike Pratt
    Participant

    @mikepratt

    The follwoing doesn’t work but I feel like I’m close, no?

    /* set new user role to Author */
    function BugleNotes_set_default_role() {
    add_uder_to_blog('1',$current_user->ID,'author');
    }
    add_action('wpmu_new_user', 'BugleNotes_set_default_role');


    nicolagreco
    Participant

    @nicolagreco

    it will never work :)

    /* set new user role to Author */
    require_once("bp-core-php");
    function BugleNotes_set_default_role() {
    global $bp;
    add_uder_to_blog('1', $bp['loggedin_userid'], 'author');
    }
    add_action('wpmu_new_user', 'BugleNotes_set_default_role');

    or another hook..

    Nicola,

    BP GURU


    Mike Pratt
    Participant

    @mikepratt

    1. should it not be require_once(“bp-core.php”) (“.php” instead of “-php”)

    2. shoudl be add_user… (typo) (my fault)

    3. I tried using ‘wpmu_new_user’ as well as ‘signup_finished’ and neither worked. In my main blog the drop down for Role is still selected to ‘Subscriber’

    I hope we solve this as I don’t want to have to manually “Author” each new user!


    nicolagreco
    Participant

    @nicolagreco

    @mike i copy and past your code there, bp-core-php was a my error :P


    buzz_lightyear
    Participant

    @buzz_lightyear

    Hi all,

    i had the very same problem at http://buzzdev.org that default role on main blog was ignored for new user signups.

    I am running plain WPMU 2.7

    Looked into the source code and solved the problem by editing wpmu-functions.php at line 672 (function “add_user_to_blog”):

    //$user->set_role($role);
    $user->set_role(get_option("default_role"));

    Now whatever default_role i set in wpmu/options.php it gets applied to new user registrations.

    take care

    buzz

    http://buzzdev.net

    http://buzzdev.org (wpmu test)


    jfcarter
    Participant

    @jfcarter

    I’m trying to understand what to do regarding this default user role issue.

    I want all new users to have a Subscriber role for the main/site blog.

    For new users setting up blogs, I want them to have an Author role.

    Does anyone know exactly how I can do this?

    I did this on this site, and like this:

    function register_user_as_contributor($username) {
    global $bp, $wpdb;

    $user_id = bp_core_get_userid_from_user_login( $username );

    if ( !$user_id )
    return false;

    $role = maybe_unserialize( get_usermeta( $user_id, $wpdb->base_prefix . '1_capabilities' ) );

    if ( is_array($role) )
    $role = $role[0];

    if ( !$role || '' == $role || 'subscriber' == $role ) {
    $role['contributor'] = 1;

    update_usermeta( $user_id, $wpdb->base_prefix . '1_capabilities', $role );
    update_usermeta( $user_id, 'primary_blog', 1 );
    update_usermeta( $user_id, 'source_domain', 'buddypress.org' );
    }
    }
    add_action( 'wp_login', 'register_user_as_contributor' );

    I’m sure there is another action you can use so it doesn’t run on every login, but this works.


    jfcarter
    Participant

    @jfcarter

    Thanks, Andy! Not sure where I should put it…wpmu-functions.php, maybe? And does it matter where within the document it goes (does it need to be before or after anything special?


    jfcarter
    Participant

    @jfcarter

    @Andy, I went ahead an put the code snippet into wpmu-functions and it sets up new users as subscribers to the main blog! But for the new blog they are still administrators. Is there more code to change that to the Author function, or did I not properly change the code you provided?


    jfcarter
    Participant

    @jfcarter

    Okay, now I’ve added Gogoplata’s step:

    in wp-includeswpmu-functions.php change this:

    add_user_to_blog(‘1’, $user_id, ‘subscriber’);

    to this:

    add_user_to_blog(‘1’, $user_id, ‘author’);

    this, combined with Andy’s code did the trick! many thanks!

    :)


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    For the record, I would put Andy’s code in bp-custom.php, located in the root of your BuddyPress install.


    buzz_lightyear
    Participant

    @buzz_lightyear

    Hi all,

    as Donncha released WPMU 2.7.1 beta2 and default_role was still not working, i have opened ticket for it on WPMU trac.

    https://trac.mu.wordpress.org/ticket/957

    Let’s hope it’ll be solved soon and permanently ;)

Viewing 25 replies - 1 through 25 (of 27 total)
  • The topic ‘set default Role of new user’ is closed to new replies.
Skip to toolbar