Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add new activity when using wp_create_user?

  • @lazharichir

    Participant

    Hi there,

    My website has several optin forms that I moved from being mailchimp to actual signups to my website (and I then automatically send these to MailChimp.) This is done! Users enter full name and email, i create the account (generate random pwd that i email them) and it works perfectly.

    Users created that way (most of my users) are not appearing a new registered users in the activity stream. Only those who use the full signup page appear on the activity stream.

    How can I change and make sure the users I create programmatically (using wp_create_user) also appear in the activity stream?

Viewing 5 replies - 1 through 5 (of 5 total)
  • @shanebp

    Moderator

    They need to have a last_activity entry in the activity table.
    Try:
    bp_update_user_last_activity( $user_id, bp_core_current_time() );

    @lazharichir

    Participant

    Doesn’t work. When wp_create_user is called, it clearly doesn’t alert BuddyPress to generate a new new_member activity. Is there any hook or any function to call to create that?

    @shanebp

    Moderator

    wp_create_user returns the user id if there are no errors.
    https://codex.wordpress.org/Function_Reference/wp_create_user

    So try:

    $user_id =  wp_create_user( // etc );
    
    if( is_wp_error( $user_id) ) 
        echo $user_id->get_error_message();
    else
        bp_update_user_last_activity( $user_id, bp_core_current_time() );

    @lazharichir

    Participant

    No no, that works and I use that IF statement in my own function. But adding a last activity doesn’t make the user show up in the activity stream.

    Perhaps we should use a function to add thag event (new user) in the activity stream database?!

    @shanebp

    Moderator

    Sorry, I was answering an oft-asked question re showing up in members loop.

    You can add an activity item:
    https://codex.buddypress.org/developer/function-examples/bp_activity_add/

    You could create a custom action, but it’s more work.
    Try using activity_update as the action

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add new activity when using wp_create_user?’ is closed to new replies.
Skip to toolbar