Support MB User Profile MB User Profile: Pass new user ID to subsequent form for post creation Reply To: MB User Profile: Pass new user ID to subsequent form for post creation

#13215
Content PilotContent Pilot
Participant

For anybody else that wants this functionality, here is what I did.

Set the user_id as a transient in the database after the user object is created.


add_action( 'rwmb_profile_after_save_user', 'set_user_id_as_transient', 10 ,1 ); 
function set_user_id_as_transient( $object ) {
     set_transient( 'user_id', $object->user_id, HOUR_IN_SECONDS );
}

Then modify the form submission with the transient data.


add_filter( 'rwmb_frontend_insert_post_data', 'insert_user_id', 10, 2 );
function insert_user_id( $data, $config ) {

    $user_id = get_transient( 'user_id' );

    if ( false !== $user_id ) {
         $data['post_author'] = $user_id;
    }

    return $data;

}

Ahn, please mark as complete.