Hack Description
If you're looking for a way to show Users what they (or other users) have selected within one of your Multi-Checkbox Custom Profile Fields, you may be running into issues. The following should help you do this.
Hack Instructions
1. Move the Code
Put the following code into a Must-Use Plugin file (if you don't have a /wp-content/mu-plugin directory, create it):
'Virginia', 'GA', 'Georgia', 'AK' => 'Alaska'))
*/
function s2hack_get_user_checkboxes($field_ids, $id = null)
{
global $wpdb;
global $current_user;
/**/
$field_ids = (array)$field_ids;
/**/
if($id === NULL)
$id = $current_user->ID;
/**/
$values = array();
/**/
$sel_fields = get_user_meta($id, $wpdb->prefix.'s2member_custom_fields', true);
$all_fields = get_s2member_custom_fields();
/**/
foreach($field_ids as $f):
$pos = $all_fields[$f]['config']['options'];
$sel = $sel_fields[$f];
$values[$f] = array();
/**/
$pos = explode("n", $pos);
foreach($pos as $key => $str)
{
$str = explode('|', $str);
$pos[$str[0]] = $str[1];
unset($pos[$key]);
}
/**/
foreach($sel as $sf)
{
if($pos[$sf] !== NULL)
$values[$f][$sf] = $pos[$sf];
}
endforeach;
/**/
return $values;
}
2. Use the Function Created
Use the function we created within the Must-Use plugin to get the user's selected fields. This can be accomplished like this:
<?php
$selected_fields = s2hack_get_user_checkboxes('countries');
$countries = $selected_fields['countries'];
echo '<ul>';
foreach($countries as $id => $country):
echo '<li>'.$country.'</li>';
endforeach;
echo '</ul>';
The above code will output the selected checkboxes for the s2Member field countries as a list.