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.

Populate WordPress User Details

Home Forums Community Forum Populate WordPress User Details

This topic contains 11 replies, has 3 voices. Last updated by  Raam Dev 4 years, 6 months ago.

Topic Author Topic
Posted: Tuesday Jun 26th, 2012 at 6:01 pm #17591
Pete Piper
Username: Jubille

Hi,

I am using S2Member to manage my login and membership system for my website.

I have just upgraded to the pro version specifically to get an answer to this problem I am having! Fingers crossed you can help me!

When users write a comment on my message boards, I would like their display name on their comment to link to a website of their choice. As I am sure you know, you can do this in WordPress by populating the ‘website’ box on a Users contact information.

My question – Is their a way of collecting information from my users using S2Member to automatically populate the ‘Website’ box in wordpress on their User contact information? I have seen custom fields/profile registration in S2Member, but do not know how to migrate this information from S2member to populate the ‘Website’ box in wordpress on their User contact information.

I could really do with some help as have no idea what to do!

Thanks in advance

List Of Topic Replies

Viewing 11 replies - 1 through 11 (of 11 total)
Author Replies
Author Replies
Posted: Wednesday Jun 27th, 2012 at 8:03 am #17645
Raam Dev
Username: Raam
Staff Member

Hi Pete,

You’d need to use an s2Member Pro-Form for registrations and include a Custom Registration field called Website. Then–here’s the tricky part–you’d need to execute some code upon submission of the Pro-Form that calls the WordPress update_user_meta() function to assign the contents of the s2Member Custom Registration field (i.e., the ‘website’ field that the user just filled out on the Pro-Form) to the user_url field in WordPress (see the aforementioned link for an example).

You should be able to accomplish this using an s2Member Hook.

Posted: Wednesday Jun 27th, 2012 at 5:18 pm #17701
Staff Member

Thanks for the heads up on this request for support.

All registration data ultimately is piped through s2Member’s core registration routines, located inside:
/s2member/includes/classes/registrations.inc.php

If you wanted to update meta values, based on GET/POST data; you might do it like this:

Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
( these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins )

<?php
add_action('ws_plugin__s2member_after_configure_user_registration', 'my_registration_function');
function my_registration_function($vars = array())
{
	if($vars&#91;'processed'&#93; === 'yes')
		{
			$user = $vars&#91;'user'&#93;; // A WP_User object instance.
			update_user_option($user->ID, 'my_value', $_POST['my_value']);
		}
}

If you only want to run this for paying customers, you can change the hook in the code above, to:
ws_plugin__s2member_during_configure_user_registration_front_side_paid

Posted: Wednesday Jun 27th, 2012 at 5:52 pm #17705
Pete Piper
Username: Jubille

Hi Jason,

Many thanks for the response.

All my customers are free customers. So, from your reply, will this work if I do the following:

(1) Leave my current member registration form and profile registration form as is (this is the one I set up on the free version), but add a custom field called website
(2) Insert the code above into the new WP file as you suggested. Do I simple copy and paste that exact code or does it need to be edited to pick up the url data my customers have entered?

Just to be crystal clear – my aim is not to collect website data from customers at registration, but only collect the website data when they edit their profile once they are members.

Many thanks for your help, it is very much appreciated.

Pete

Posted: Thursday Jun 28th, 2012 at 7:24 am #17750
Raam Dev
Username: Raam
Staff Member

Hi Pete,

That code that Jason provided will only work with s2Member Pro-Forms. It will not work with the default WordPress registration form (which is what you’re probably using if you set it up using the free version of s2Member, since Pro-Forms are not available with the free version).

If you’re using the [s2Member-Profile /] shortcode to allow users to edit their profiles and you want to add an s2Member Custom Registration/Profile field that, when edited on their profile using the [s2Member-Profile /] shortcode, updates the user_url field, then you’ll need to use the ws_plugin__s2member_after_handle_profile_modifications hook instead.

The code might look like this:

Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
( these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins )

<?php
add_action('ws_plugin__s2member_after_handle_profile_modifications', 'my_profile_function');
function my_profile_function($vars = array())
{
	$user = $vars['user']; // A WP_User object instance.
	update_user_option($user->ID, 'user_url', $_POST['my_value']);
}
?>

You’ll need to change $_POST[‘my_value’] to match the name of the s2Member Custom Registration Field that you added for website.

Posted: Friday Jun 29th, 2012 at 1:17 pm #17872
Pete Piper
Username: Jubille

Hi,

I have followed the instructions from Raam above, and created the file suggested.

I have stuck with my forms from the free version as you suggested there was no need to do any different.

I called the custom registration field ‘website’. I copied the text exactly as entered above, except I edited the $_POST[‘my_value’] to read $_POST[‘website’].

Unfortunately it doesn’t work!

Am I missing something really obvious?

Thanks for your continued help.

Pete

Posted: Saturday Jun 30th, 2012 at 7:03 am #17939
Raam Dev
Username: Raam
Staff Member

Hi Pete,

There were a few problems with my code. Please try the updated version below:

<?php
add_action('ws_plugin__s2member_after_handle_profile_modifications', 'update_user_url');
function update_user_url($vars = array())
{
	$user = $vars&#91;'user'&#93;; // A WP_User object instance.
	wp_update_user( array ('ID' => $user->ID, 'user_url' => $_POST['ws_plugin__s2member_profile_website']) ) ;
}
?>

This code uses the wp_update_user() function instead of update_user_option(). Also note that s2Member dynamically adds the prefix ws_plugin__s2member_profile_ to the name of your custom registration field.

Posted: Saturday Jun 30th, 2012 at 8:09 am #17949
Pete Piper
Username: Jubille

Raam,

Thanks, but the code you have provided does not copy into notepad.

When I click paste in notepad, the code appears all on one long line, and it also has numbers inserted into it.

Am I doing something wrong?

Also – I presume I do not need to edit this code at all, but just insert it exactly as provided?

Many thanks

Pete

Posted: Saturday Jun 30th, 2012 at 6:49 pm #17990
Pete Piper
Username: Jubille

Raam,

I formated the code in notepad by hitting return in the right place etc, and it works like a dream.

Well done.

Many thanks for all your support – it has been much appreciated.

Keep up the great work,

Pete

Posted: Tuesday Jul 3rd, 2012 at 3:37 am #18134
Raam Dev
Username: Raam
Staff Member

Pete,

You’re welcome. In the future, you can click on the little magnifying glass icon in the top right of the code box. That will open a new window with just the code and you can copy and paste that.

Posted: Tuesday Jul 3rd, 2012 at 12:23 pm #18197
Pete Piper
Username: Jubille

Hi Raam,

Many thanks.

As a slight aside, when you click on the username in wordpress, it does not open the users website in a new window, but in the same window that you are currently using. I have had comments from users requesting the website to open in a new window when someone clicks on a username.

Do you know how to do this? I assume because I am using S2Member it maybe effects the required code?

Many thanks

Pete

Posted: Wednesday Jul 4th, 2012 at 8:30 am #18285
Raam Dev
Username: Raam
Staff Member

Hi Pete,

This is not an s2Member thing: you’d need to modify your theme template (probably comments.php) and add target=”_new” to the anchor tag that surrounds the PHP code that outputs the users name.

Viewing 11 replies - 1 through 11 (of 11 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.