Skip to:
Content
Pages
Categories
Search
Top
Bottom

Earliest point in registration I can know the user ID


  • almostsultry
    Participant

    @almostsultry

    Following the flow of bp-members-screens, I can’t quite find a hook where I can add an action that can get the userID of the registering user. I am doing an automated signup to another system in parallel with this system, but I need to know that userID for it to work.

    Please advise,
    Benjamin

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

  • shanebp
    Moderator

    @shanebp

    Have you tried using the action hook in function bp_core_signup_user ?

    do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );


    almostsultry
    Participant

    @almostsultry

    Shane,

    Thanks for the answer. I have setup a function (in functions.php) that adds the bp_complete_signup action on line 266 of bp_members_screens, just after the bp_core_signup_user is called. In my custom function, can I just call bp_core_signup_user() and get back the user ID it had already created; or do I need to pass it some parameters (and won’t that just create another new user)?

    Please advise,
    Benjamin


    shanebp
    Moderator

    @shanebp

    The hook you mention does not provide any arguments.
    Perhaps you need to research how do_action works.
    The hook I mentioned already provides the $user_id.

    Example:

    function sultry( $user_id, $user_login, $user_password, $user_email, $usermeta ) {
       // do something with $user_id
    }
    add_action( 'bp_core_signup_user', 'sultry', 10, 5 );

    Boone Gorges
    Keymaster

    @boonebgorges

    @shanebp is correct that you’ll need to choose a hook where the user ID is made available.

    Unfortunately, ‘bp_core_signup_user’ may be too early. On some setups (specifically, most Multisite configs) no user has yet been created at ‘bp_core_signup_user’ – only a signup object. The earliest point when you can be confident that a WP user object exists is ‘bp_core_activated_user’.


    almostsultry
    Participant

    @almostsultry

    @boonebgorges does the signup object created at bp_core_signup_user have as its $user_id value the next incremental user ID in my wp_users table, or is it some other meta value? This is the only value I need for my custom function that I can’t get from the $usermeta array values at bp_core_signup_user. Even if the user never activates, I can at least perform my signup custom function on the external system.

    Thanks for the clarification.

    Please advise,
    Benjamin


    Boone Gorges
    Keymaster

    @boonebgorges

    @almostsultry – It depends on your setup. By default, on Multisite, WP user objects are not created at ‘bp_core_signup_user’. By default, on non-Multisite, users *are* created at the time of registration (ie ‘bp_core_signup_user’). This behavior may be modified by other plugins, especially those that interact with the login process (like SSO plugins). To test whether ‘bp_core_signup_user’ will work for you, take @shanebp’s code from above, and at the time of signup, examine whether $user_id is populated at this point. If not, it’ll be false. If so, it’ll be an integer, which you can safely use.

    Do *not* depend on incremented values, because BP (on Multisite) generates users in the order in which they are *activated*, not registered.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar