PriMoThemes — now s2Member® (official notice)
This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™
<?php
$fields_configured = json_decode($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true);
print_r($fields_configured);
?>
Array
(
[0] => Array
(
[section] => no
[sectitle] =>
[id] => country_code
[label] => Choose Country
[type] => text
[deflt] =>
[options] =>
[expected] =>
[required] => yes
[levels] => all
[editable] => yes
[classes] =>
[styles] =>
[attrs] =>
)
[1] => Array
(
[section] => no
[sectitle] =>
[id] => street_address
[label] => Street Address
[type] => text
[deflt] =>
[options] =>
[expected] =>
[required] => yes
[levels] => all
[editable] => yes
[classes] =>
[styles] =>
[attrs] =>
)
)
<?php
$user_id = 123; /* A specific User ID. */
$street_address = get_user_field ("street_address", $user_id); /* Value of Custom Field: street_address */
$street_address_label = my_s2_custom_field_label ("street_address"); /* Might return: Street Address */
/*
Custom utility function to pull Labels.
*/
function my_s2_custom_field_label ($field_id)
{
foreach ((array)json_decode ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_fields"], true) as $field_configured)
{
if ($field_configured["id"] == $field_id)
{
return $field_configured["label"];
}
}
}
?>
s2member_get_custom_field($value)
s2member_get_custom_field('favorite_color');
// outputs array('Favorite Color' => 'yellow')
function get_s2member_custom_fields($user_id = '') {
$custom_fields = array();
$values = get_user_option('s2member_custom_fields', $user_id);
foreach ((array)json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], true) as $field)
$custom_fields[$field['label']] = isset($values[$field['id']]) ? $values[$field['id']] : '';
return $custom_fields;
}
function get_s2member_custom_fields($user_id = '') {
$values = get_user_option('s2member_custom_fields', $user_id);
foreach ((array)json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], true) as $field)
$custom_fields[$field['id']] = array(
'label' => $field['label'],
'value' => isset($values[$field['id']]) ? $values[$field['id']] : '',
);
return $custom_fields;
}
$custom_fields = get_s2member_custom_fields();
echo 'My ', $custom_fields['favorite_color']['label'], ' is ', $custom_fields['favorite_color']['value'], '.';
<?php
echo get_user_field("street_address"); // Value of Custom Field with ID "street_address", for the current User.
?>
<?php
$user_id = 123;
echo get_user_field("street_address", $user_id); // Value of Custom Field with ID "street_address".
?>
function get_s2member_custom_fields($user_id = '') {
$return = array();
$user = get_user_option('s2member_custom_fields', $user_id);
foreach ((array)json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], true) as $field) {
if (isset($user[$field['id']])) {
$return[$field['id']]['label'] = $field['label'];
if (empty($field['options']))
$return[$field['id']]['value'] = $user[$field['id']];
else {
$field['options'] = strpos($field['options'], "\n") ? explode("\n", $field['options']) : (array)$field['options'];
foreach ($field['options'] as $option) {
$option = explode('|', $option);
$options[$option[0]] = $option[1];
}
foreach ((array)$user[$field['id']] as $choice)
$return[$field['id']]['options'][] = array (
'label' => $options[$choice],
'value' => $choice,
);
}
}
}
return $return;
}
$var = get_s2member_custom_fields($user_id = 1);
echo $var['user_preference']['options'][0]['label'];
$s2_custom_fields = get_s2member_custom_fields(1);
function get_s2member_custom_fields($user_id = '') {
$return = array();
$user = get_user_option('s2member_custom_fields', $user_id);
foreach ((array)json_decode($GLOBALS['WS_PLUGIN__']['s2member']['o']['custom_reg_fields'], true) as $field) {
if (isset($user[$field['id']])) {
$return[$field['id']]['label'] = $field['label'];
if (empty($field['options']))
$return[$field['id']]['value'] = $user[$field['id']];
else {
$field['options'] = strpos($field['options'], "\n") ? explode("\n", $field['options']) : (array)$field['options'];
foreach ($field['options'] as $option) {
$option = explode('|', $option);
$options[$option[0]] = $option[1];
}
foreach ((array)$user[$field['id']] as $choice)
$return[$field['id']]['options'][$choice] = $options[$choice];
}
}
}
return $return;
}
$s2_custom_fields = get_s2member_custom_fields($user_id);
$option_label = $s2_custom_fields[$field_name]['options'][$option_value];
$option_value = array_search($option_label, $s2_custom_fields[$field_name]['options']);
foreach ($s2_custom_fields[$field_name]['options'] as $option_value => $option_label) {
// ...
}
Users browsing this forum: No registered users and 8 guests