Skip to:
Content
Pages
Categories
Search
Top
Bottom

New User Actions for BP


  • techguy
    Participant

    @crashutah

    In the beloved wp-fb-autoconnect plugin that allows users to login to BP using Facebook, I think I found an error in how it creates a user. I believe it’s using the WP user creation and misses some of the BP user creation. Hopefully, Andy or someone can tell me if my assumption is correct.

    Here’s what the wp-fb-autoconnect plugin uses to create a new user:

    $user_login_id = wp_insert_user($user_data);

    wp_new_user_notification($user_login_name);

    //Tag the user with our meta so we can recognize them next time, without resorting to email hashes

    update_usermeta($user_login_id, $jfb_uid_meta_name, $fb_uid);

    In another plugin I saw these actions for user creation, but I couldn’t tell if they just built on other BP core items or were the actual actions that needed to be called.

    add_action(“user_register”);

    add_action(“bp_core_signup_user”);

    I also found this one for creating a wpmu user:

    wpmucreateuser()

    I also checked the documentation and thought it should be in this link, but it wasn’t:

    http://codex.buddypress.org/developer-docs/action-reference/

    I imagine somewhere in the core is a list of the functions that create a new user, but I’m hoping someone might know which actions need to be called by a plugin to create a BP user properly.

Viewing 10 replies - 1 through 10 (of 10 total)

  • techguy
    Participant

    @crashutah

    There has to be someone that knows the answer to this question. Even just pointing me to the core files where I can find the actions that are used to create users would be great.


    techguy
    Participant

    @crashutah

    There has to be someone that knows the answer to this question. Even just pointing me to the core files where I can find the actions that are used to create users would be great.


    r-a-y
    Keymaster

    @r-a-y

    The bp_core_signup_user action is a BP action. Look at /bp-core/bp-core-signup.php for this function.


    r-a-y
    Keymaster

    @r-a-y

    The bp_core_signup_user action is a BP action. Look at /bp-core/bp-core-signup.php for this function.


    techguy
    Participant

    @crashutah

    Thanks for the help on this r-a-y. I’m getting pretty close. So, I’ve changed the user creation to the following so that it will do the regular user creation if it’s not BP and it will do bp_core_signup_user() for BP. Here’s the code:

    if (!defined (“BP_VERSION”)) /* Not compatible with BuddyPress. */

    {

    $user_login_id = wp_insert_user($user_data);

    } else {

    //$usermeta = ”;

    $user_login_id = bp_core_signup_user($user_data[‘user_login’], $user_data[‘user_pass’], $user_data[‘user_email’], $usermeta);

    }

    The question I have is how can I load $usermeta with the meta data for that user? I have this other data available to be put into the $usermeta:

    $user_data[‘first_name’] = $fbuser[‘first_name’];

    $user_data[‘last_name’] = $fbuser[‘last_name’];

    $user_data[‘user_nicename’] = $fbuser[‘name’];

    $user_data[‘display_name’] = $fbuser[‘first_name’];

    $user_data[‘user_url’] = $fbuser[“profile_url”];

    I also think there might be something wrong with the way I’m passing the email into bp_core_signup_user(). Not sure if that makes a difference or not.


    techguy
    Participant

    @crashutah

    I started to look into the core files for the bp_core_signup_user() function and it seems like the $usermeta variable that needs to be passed in needs the xprofile information stored in there. Is that true?

    Also, it seems like the If (!defined (“BP_VERSION”)) isn’t working quite right. Do I have to declare the $bp variable or include a BP file or something to get that function to work?


    r-a-y
    Keymaster

    @r-a-y

    @techguy

    That’s correct the $usermeta variable holds the submitted xprofile fields from the BP registration page.

    eg. you could do this:

    $usermeta['field_1'] = $fbuser['first_name']; // field_1 = "Name" on BP registration page

    You’ll have to grab the correct field_x name for each xprofile meta you want to sync up with the FB auto plugin.

    BP_VERSION might not be working because WP-FB-AutoConnect is probably loaded before BP, so WP-FB-AutoConnect (man that’s a mouthful!) doesn’t know that BP exists.


    techguy
    Participant

    @crashutah

    Excuse my ignorance, but shouldn’t the bp_core_signup_user() create a new user even without the $usermeta? Although, I guess the Full Name is required and so maybe it needs at least the Full Name entered into the $usermeta?

    Is there a way I can have it display any errors that may be occurring when I call the bp_core_signup_user() so I could better see the problems it’s having?

    Looks like I’m going to have to find another way to check if they have BP. I think WP-FB-Autoconnect has something that could be used in the options. I’ll play with it.


    r-a-y
    Keymaster

    @r-a-y

    Just looking into the bp_core_signup_user() function again. Sorry for pointing this to you in the first place!

    I would not recommend using this function because it sets a user’s status to “not active”, then sends an email to activate the account (which makes sense because that’s the default registration behavior in BP!).

    Since we don’t want to ask a FB user to activate their account, stick with the wp_insert_user() function, then use some code to sync up the xprofile fields like:

    // set xprofile field 1 (Name) with the fbuser's first name
    xprofile_set_field_data(1,$user_login_id,$fbuser['first_name']);

    /*
    * @param $field The ID of the field, or the $name of the field.
    * @param $user_id The ID of the user
    * @param $value The value for the field you want to set for the user.
    */

    To initialize BP, look at using the bp_init action:

    https://codex.buddypress.org/how-to-guides/checking-buddypress-is-active/

    [EDIT]

    Just looking into the WP-FB-AutoConnect plugin, Justin (the author) has a do_action that you could hook into:

    do_action('wpfb_login', array('WP_ID' => $user_login_id, 'FB_ID' => $fb_uid, 'facebook' => $facebook) );

    Here you can sync up your xprofile fields, etc. Unfortunately, this action occurs every time a Facebook user logs in. You could view this as a positive or a negative!

    I think it would be nice if Justin added another do_action right after the wp_insert_user() function in _process_login.php.

    [EDIT #2]

    Requested a new do_action on Justin’s plugin page – http://www.justin-klein.com/projects/wp-fb-autoconnect/comment-page-5#comment-11638.


    techguy
    Participant

    @crashutah

    Thanks r-a-y. I was actually ok with them having to activate it, but I guess if they don’t agree to give their Facebook email there’s no sense. Plus, if they already verified with Facebook, we should be good to go.

    However, should we still do something like this:

    /* Multisite installs have their own install procedure */

    if ( bp_core_is_multisite() ) {

    wpmu_signup_user( $user_login, $user_email, $usermeta );

    } else {

    wp_insert_user($user_data) ;

    }

    Although, maybe that doesn’t matter so much once WPMU and WP are merged?

    I also think it’s better to offer the code to the plugin developer instead of using his hook, no? Then, future BP users it will just work out of the box.

    I’ll try out the x-profile field stuff. Is there any documentation anywhere on the x-profile fields? What’s required? What’s available, etc?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘New User Actions for BP’ is closed to new replies.
Skip to toolbar