Integrate the Free Registration Form (Pro)

Hi there!
In order to show dedicated portfolio items to each user, I released a simple function which is automatically creating a portfolio category named “tips_username” when a user registers on the website. This is the function I use:

add_action('user_register', 'auto_create_traveltip_category');
function auto_create_traveltip_category($user_id) {
	$tip_category_name = 'tips_' . $_POST['user_login'];
	wp_insert_term($tip_category_name, 'portfolio_entries', array(
			'description' => 'Travel Tips ' . $_POST['user_login'],
			'slug'        => 'tips-' . $_POST['user_login'],
			'parent'      =>  '324',
			)
	);
}

I would like to make it work with the Free Registration Form too.
I tried to create the file s2-hacks.php in the folder mu-plugin with the following code, but it’s not working.

add_action('ws_plugin__s2member_during_configure_user_registration', 's2m_auto_create_traveltip_category');
function s2m_auto_create_traveltip_category($user_id) {
	$tip_category_name = 'tips_' . $_POST['user_login'];
	wp_insert_term($tip_category_name, 'portfolio_entries', array(
			'description' => 'Travel Tips ' . $_POST['user_login'],
			'slug'        => 'tips-' . $_POST['user_login'],
			'parent'      =>  '313',
			)
	);
}

I suppose that I’m hacking the wrong function.
Can anybody help with this?
Thanks in advance :slightly_smiling:

add_action('user_register', is a hook that fires after registration. So I’m guessing that the s2Member hook you need should work in analogous fashion. So try changing your s2Member hack so that it starts like this:

add_action('ws_plugin__s2member_after_configure_user_registration', 's2m_auto_create_traveltip_category');

Thanks for your suggestion Tim. I tried to put the following code in the s2-hacks.php but it’s still not creating the categories… any other idea?

add_action('ws_plugin__s2member_after_configure_user_registration', 's2m_auto_create_traveltip_category');
function s2m_auto_create_traveltip_category($user_id) {
	$tip_category_name = 'tips_' . $_POST['user_login'];
	wp_insert_term($tip_category_name, 'portfolio_entries', array(
			'description' => 'Travel Tips ' . $_POST['user_login'],
			'slug'        => 'tips-' . $_POST['user_login'],
			'parent'      =>  '313',
			)
	);
}

since I’m on a multisite wp installation I also tried

ws_plugin__s2member_after_configure_user_on_ms_user_activation

without success

How about simply ws_plugin__s2member_after_register ?

Just tried. Still not working…
Maybe s2m is not using $_POST[‘user_login’] but something else instead?
I’m really struggling here…

@claudiosinopoli: It’s possible to create a notification URL with some “label” of you (and all other need info like username), then tie your function to “init” hook and if your label is in $_GET, do your job.

Thank you Krum for your answer.
I’m not very advanced with php so I didn’t quite understand your suggestion.
Can you please make an example based on my code?

This is the notification URL, put it in “Registration Notification”:
http://your.site/?create_traveltip=%%user_login%%

Code in “mu-plugin/s2-hacks.php”:

add_action('init', 'auto_create_traveltip_category');
function auto_create_traveltip_category() {
    if(isset($_GET['create_traveltip'])) {
	    $tip_category_name = 'tips_' . $_GET['create_traveltip'];
	    wp_insert_term($tip_category_name, 'portfolio_entries', array(
			'description' => 'Travel Tips ' . $_GET['create_traveltip'],
			'slug'        => 'tips-' . $_GET['create_traveltip'],
			'parent'      =>  '324',
			)
        );
        exit();
    }
}

Try this and tell me the result, please.