14
Apr, 2015
Apr, 2015
Getting/Setting Custom Registration/Profile Fields Configured w/ s2Member
Table of Contents
In this article I'll explain how to get/set Custom Registration/Profile fields through PHP code. Therefore, this tutorial will be targeted at WordPress theme/plugin developers that would like to integrate with s2Member.
Note: With s2Member you can configure Custom Registration/Profile Fields in the Dashboard. See: WordPress Dashboard → s2Member → General Options → Registration/Profile Fields & Options
There is also an [s2Get /]
shortcode that can be used to obtain Custom Registration/Profile Field values and present them in a WordPress Post/Page.
Getting Custom Registration/Profile Fields via PHP
<?php
$user_id = get_current_user_id();
$custom_fields = get_user_option('s2member_custom_fields', $user_id);
print_r($custom_fields);
/*
Array
(
[company] => Acme Incorporated
[phone_number] => 1-555-555-5555
[favorite_color] => beige
[favorite_actor] => Keanu Reeves
)
*/
?>
Setting Custom Registration/Profile Fields via PHP
<?php
$user_id = get_current_user_id();
$custom_fields = get_user_option('s2member_custom_fields', $user_id);
$custom_fields['company'] = 'Biteme International';
$custom_fields['phone_number'] = '1-800-PHP-CODE';
update_user_option($user_id, 's2member_custom_fields', $custom_fields);
?>