BuddyDev

Search

[Resolved] Automatically Create New Post for Every New BuddyPress Registration

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #3916

    Hello,

    I am looking to make it so that After a BuddyPress registration is confirmed (‘bp_after_registration_confirmed’)

    WordPress automatically creates a new post (‘ wp_insert_post ‘) with contents based off user registration input.

    Would it be best to insert this new function in register.php, or elsewhere?

    Thanks

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #3917

    I got this working in activate.php adding wp_insert_post in the if else statements..

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2505
    Ravi on #3924

    Hi Brian

    Good to know that it is working. If I were you, I would have used the activation hook instead to be sure that the post is created when accounts are activated. Using ‘bp_core_activated_user’ this hook and code should be in bp-custom.php

    All the best with your project.

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #3940

    Hi Ravi,

    Thanks for the tip. I tried this and it is working properly to add a new post on user activation.

    Do you know of a way to get user data for the Title field?

    I am trying like

    $userid = bp_loggedin_user_id();
    $bandname = xprofile_get_field_data( ‘Band Name’, $userid, $multi_format = ‘comma’ );
    ….
    ‘post_title’ => $bandname

    But it seems it is not parsing this information properly as post title output is ‘(no title)’.

    I am trying this with BP-AutoLogin-On-Activation plug-in so the user is logged in upon activation https://buddydev.com/plugins/bp-autologin-on-activation/

    Any tips?

    Thank you!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2505
    Ravi on #3941

    Hi Brian,

    Please try the following

    
    $userid = bp_loggedin_user_id();
    
    $field_id = "Your field ID";
    $bandname = xprofile_get_field_data( $field_id, $userid );
    
    

    and let me know if it is working or not

    Thank You
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2505
    Ravi on #3944

    Hi Brian,

    Please try this way. Don’t use above code

    
    function buddydev_create_post_on_activation( $user_id, $key, $user ) {
    
    	//do something like this
    
    	$field_id = "Your field ID";
    	$bandname = xprofile_get_field_data( $field_id, $user_id );
    
    }
    add_action( 'bp_core_activated_user', 'buddydev_create_post_on_activation', 10, 3 );
    
    

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #3945

    Checked MySQL tables and the field for Band Name is just simply “1”.

    Tried your code to echo out in profiles.php. Worked perfectly.

    Tried the code in bp-custom.php and still outputs (no title).

    Maybe since bp-custom.php loads before the page it is not seeing logged in user id?

    edit: just saw your new reply. Will update in a minute

    • This reply was modified 6 years, 6 months ago by Brian.
  • Participant
    Level: Enlightened
    Posts: 31
    Brian on #3949

    Yes!!

    That worked.

    Thanks a bunch Ravi!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2505
    Ravi on #3951

    Hi Brian

    Thank You for acknowledgement. I am glad that I could help.

    Thank You
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved