latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Populating Custom Fields after registration

Home Forums Community Forum Populating Custom Fields after registration

This topic contains 9 replies, has 4 voices. Last updated by  Anton Karbanovich 4 years, 1 month ago.

Topic Author Topic
Posted: Saturday Nov 10th, 2012 at 6:24 am #31191

Hello,
Would like to thank you guys first for the great plugin. I am recommending it to all my clients now who need this kind of functionality.

I have one question. I s2Member plugin that limits the access to the buddypress on my website.
My buddypress profile has some custom profile fields that are currently used by the members, and a lot of things are connected already to those custom profile fields. like the mapology plugin and other stuff.

so what i am trying to do it to add those fields to my registration page. which i have already, but then upon registration i would populate the corresponding data to my original buddypress custom profile fields.
http://beta.christianheritageonline.org/network

I know that you already have that functionality of connecting your s2member custom fields to my buddypress, but it is not really gonna work for me since a lot of work is already done with those buddypress fields.

so i found this function on the following page.
ms_process_signup_meta()
http://www.s2member.com/codex/stable/s2member/registrations/c_ws_plugin__s2member_registrations/

and i was wondering if there is a way i can populate the data after s2member registration?
maybe something like that

function my_field_population() { 
	
	$user_id = ???;
	
	$s2field_value = ???;
	
	xprofile_set_field_data('Spouse Name', $user_id,  $s2field_value);
}
add_action('ms_process_signup_meta','my_field_population');
	

List Of Topic Replies

Viewing 9 replies - 1 through 9 (of 9 total)
Author Replies
Author Replies
Posted: Monday Nov 12th, 2012 at 7:07 am #31281

To get an s2Member custom profile field value in your hack, you can use one of these functions:

http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field()
http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_s2member_custom_fields()

I hope that helps. :)

Would like to thank you guys first for the great plugin. I am recommending it to all my clients now who need this kind of functionality.

Thanks for the kudos!

Posted: Monday Nov 12th, 2012 at 11:07 am #31319

what about user id?
does this ms_process_signup_meta return user id?

thanks for the help!

Posted: Monday Nov 12th, 2012 at 7:00 pm #31383

I don’t know. You can see what it returns using the filter [hilite mono]ws_plugin__s2member_ms_process_signup_meta[/hilite]. http://www.s2member.com/codex/stable/source/s2member/includes/classes/registrations.inc.php/#src_doc_line_148

Posted: Tuesday Nov 13th, 2012 at 6:33 am #31436

ok thanks…
also a quick question…
is there a function something like set_user_field where i can change the value of the field?

thanks for your help!

Posted: Tuesday Nov 13th, 2012 at 8:07 pm #31519
Raam Dev
Username: Raam
Staff Member

Hi Anton,

Here’s how you can do that:

// Get an array of all the users' s2Member Custom Fields
$custom_fields = get_user_option("s2member_custom_fields");

// Set the value for a specific field ($custom_fields is an array)
$custom_fields["custom_field_name"] = $NewValue;

// Update the Custom Field data
update_user_option($user->ID, "s2member_custom_fields", $custom_fields);
Posted: Thursday Nov 22nd, 2012 at 5:47 am #32320

Hi Anton,
I’m trying to implement the same thing in my installation of S2Member and Buddypress but I’m having a little trouble making sense of this thread.
Would be able to explain/share your final code on how you got this running?
Many thanks in advance,
Laurie

Posted: Thursday Nov 22nd, 2012 at 6:44 am #32332

I emailed Anton and he replied with this:

hey sure
here is the code

just put it in the functions.php
and change the names of the s1member filed ids with the proper buddypress field names.

/* ----------- POPULATING CUSTOM FIELDS AT REGISTRATION ------------- */




add_action('wp_head', 'ch_s2_registration_field_population', 10, 2);
function ch_s2_registration_field_population() {

        global $current_user;

        get_currentuserinfo();

        // Do that only at the first login of the user
        if(get_user_field("s2member_login_counter") < 2) {

                if(xprofile_get_field_data('Spouse Name', $current_user->id) == '' && get_user_field('Spouse_Name') != '' ) {  // checking if the BP field is empty and s2Member field is not…
                        xprofile_set_field_data('Spouse Name', $current_user->id,  get_user_field('Spouse_Name')); // then populating it.
                }

                if(xprofile_get_field_data('Address', $current_user->id) == '' && get_user_field('Address') != '' ) {
                        xprofile_set_field_data('Address', $current_user->id,  get_user_field('Address'));
                }

                if(xprofile_get_field_data('City', $current_user->id) == '' && get_user_field('City') != '' ) {
                        xprofile_set_field_data('City', $current_user->id,  get_user_field('City'));
                }

                if(xprofile_get_field_data('State', $current_user->id) == '' && get_user_field('State') != '' ) {
                        xprofile_set_field_data('State', $current_user->id,  get_user_field('State'));
                }

                if(xprofile_get_field_data('Zip', $current_user->id) == '' && get_user_field('Zip') != '' ) {
                        xprofile_set_field_data('Zip', $current_user->id,  get_user_field('Zip'));
                }

                if(xprofile_get_field_data('Home Phone Number', $current_user->id) == '' && get_user_field('Home_Phone_Number') != '' ) {
                        xprofile_set_field_data('Home Phone Number', $current_user->id,  get_user_field('Home_Phone_Number'));
                }

                if(xprofile_get_field_data('Cell Phone', $current_user->id) == '' && get_user_field('Cell_Phone') != '' ) {
                        xprofile_set_field_data('Cell Phone', $current_user->id,  get_user_field('Cell_Phone'));
                }

                if(xprofile_get_field_data('Occupation/Family Businesses and Services', $current_user->id) == '' && get_user_field('Occupation_Family_Busines') != '' ) {
                        xprofile_set_field_data('Occupation/Family Businesses and Services', $current_user->id,  get_user_field('Occupation_Family_Busines'));
                }

                if(xprofile_get_field_data('Family Interests and Hobbies', $current_user->id) == '' && get_user_field('Family_Interests_Hobby') != '' ) {
                        xprofile_set_field_data('Family Interests and Hobbies', $current_user->id,  get_user_field('Family_Interests_Hobby'));
                }

                if(xprofile_get_field_data('Church', $current_user->id) == '' && get_user_field('Church') != '' ) {
                        xprofile_set_field_data('Church', $current_user->id,  get_user_field('Church'));
                }


        }


}
Posted: Friday Nov 23rd, 2012 at 1:31 pm #32432
Raam Dev
Username: Raam
Staff Member

Laurie, Anton, thanks for sharing the code! I’m sure it will help others looking for a similar solution. :)

Awarded Laurie and Anton the Helpful badge.
Posted: Thursday Nov 29th, 2012 at 6:11 am #32882

hey thanks for the helpful badge! )))

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

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.