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™
$s2_custom_fields = get_user_option('wp_s2member_custom_fields', $user_id);
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;
}
function update_member_directory_preference($curUser,$custom_fields){
//adjust user meta to adapt to preference
if(($custom_fields['member_directory_include']['value'])=="1") {
add_user_meta($curUser,'_tern_wp_member_list','My List');
}
if(($custom_fields['member_directory_include']['value'])!=1){
delete_user_meta($curUser,'_tern_wp_member_list');
}
}
function catch_profile_edit()
{
global $getWP,$tern_wp_members_defaults,$current_user,$wpdb,$profileuser;
$custom_fields = get_s2member_custom_fields();
$curUser = $current_user->ID;
update_member_directory_preference($curUser,$custom_fields);
}
add_action("ws_plugin__s2member_after_handle_profile_modifications", "catch_profile_edit");
add_action('ws_plugin__s2member_after_handle_profile_modifications', 'catch_profile_edit');
function catch_profile_edit() {
global $current_user;
$s2_custom_fields = get_user_field('s2member_custom_fields', $current_user->ID);
if ($s2_custom_fields['member_directory_include'] === '1')
add_user_meta($current_user->ID, '_tern_wp_member_list', 'My List');
else
delete_user_meta($current_user->ID, '_tern_wp_member_list');
}
nashvillegeek wrote:The only problem I see now is that the 'update_member_directory_preference' script isn't updated after registration. Is there a hook that can handle that?
Sorry, can you please confirm when you're trying to update this data? During/after Registration, or during/after a Profile edit?The only problem I see now is that the 'update_member_directory_preference' script isn't updated after registration. Is there a hook that can handle that?
<?php
add_action ("ws_plugin__s2member_during_configure_user_registration_front_side", "my_handler");
add_action ("ws_plugin__s2member_during_configure_user_registration_admin_side", "my_handler");
function my_handler ($vars = array ())
{
$user_id = $vars["user_id"];
// Do something here.
}
?>
Yes, it is also available for the Profile modification Hook.Cristián Lávaque wrote:Thanks! is $vars['user_id'] also available when using the hook 'ws_plugin__s2member_after_handle_profile_modifications'?
<?php
add_action('ws_plugin__s2member_during_configure_user_registration_front_side', 'member_directory_include');
add_action('ws_plugin__s2member_during_configure_user_registration_admin_side', 'member_directory_include');
add_action('ws_plugin__s2member_after_handle_profile_modifications', 'member_directory_include');
function member_directory_include($vars = array ()) {
$s2_custom_fields = get_user_field('s2member_custom_fields', $vars['user_id']);
if ($s2_custom_fields['member_directory_include'] === '1')
add_user_meta($vars['user_id'], '_tern_wp_member_list', 'My List');
else
delete_user_meta($vars['user_id'], '_tern_wp_member_list');
}
?>
No, in order to hit the admin side for Profile modifications, you'll need this additional Hook.Cristián Lávaque wrote:Jason, does 'ws_plugin__s2member_after_handle_profile_modifications' work for both, front and admin modifications?
add_action('ws_plugin__s2member_during_users_list_update_cols', 'member_directory_include');
<?php
add_action('ws_plugin__s2member_during_configure_user_registration_front_side', 'member_directory_include');
add_action('ws_plugin__s2member_during_configure_user_registration_admin_side', 'member_directory_include');
add_action('ws_plugin__s2member_after_handle_profile_modifications', 'member_directory_include');
add_action('ws_plugin__s2member_during_users_list_update_cols', 'member_directory_include');
function member_directory_include($vars = array ()) {
$s2_custom_fields = get_user_field('s2member_custom_fields', $vars['user_id']);
if ($s2_custom_fields['member_directory_include'] === '1')
add_user_meta($vars['user_id'], '_tern_wp_member_list', 'My List');
else
delete_user_meta($vars['user_id'], '_tern_wp_member_list');
}
?>
Jason Caldwell wrote:Nice work. May I suggest the use of "update_user_meta" or "update_user_option" instead of "add_user_meta"?
<?php
add_action('ws_plugin__s2member_during_configure_user_registration_front_side', 'member_directory_include');
add_action('ws_plugin__s2member_during_configure_user_registration_admin_side', 'member_directory_include');
add_action('ws_plugin__s2member_after_handle_profile_modifications', 'member_directory_include');
add_action('ws_plugin__s2member_during_users_list_update_cols', 'member_directory_include');
function member_directory_include($vars = array ()) {
$fields = get_user_field('s2member_custom_fields', $vars['user_id']);
update_user_option($vars['user_id'], '_tern_wp_member_list', ($fields['member_directory_include'] === '1' ? 'My List' : false));
}
?>
nashvillegeek wrote:Thanks to you both for helping with this. I feel like I've been taken to school. I will try this out tomorrow.
This thread in particular has answered so many looming questions for me. Great information and examples! I imagine others will take alot from this, as well.
Thank you! I'll get back with the results.
/**
* Delete user option with global blog capability.
*
* User options are just like user metadata except that they have support for
* global blog options. If the 'global' parameter is false, which it is by default
* it will prepend the WordPress table prefix to the option name.
*
* @since 3.0.0
* @uses $wpdb WordPress database object for queries
*
* @param int $user_id User ID
* @param string $option_name User option name.
* @param bool $global Optional. Whether option name is global or blog specific. Default false (blog specific).
* @return unknown
*/
function delete_user_option( $user_id, $option_name, $global = false )
<?php
add_action('ws_plugin__s2member_during_configure_user_registration_front_side', 'member_directory_include');
add_action('ws_plugin__s2member_during_configure_user_registration_admin_side', 'member_directory_include');
add_action('ws_plugin__s2member_after_handle_profile_modifications', 'member_directory_include');
add_action('ws_plugin__s2member_during_users_list_update_cols', 'member_directory_include');
function member_directory_include($vars = array ()) {
$s2_custom_fields = get_user_field('s2member_custom_fields', $vars['user_id']);
if ($s2_custom_fields['member_directory_include'] === '1')
update_user_option($vars['user_id'], '_tern_wp_member_list', 'My List');
else
delete_user_option($vars['user_id'], '_tern_wp_member_list');
}
?>
<?php
add_action('ws_plugin__s2member_during_configure_user_registration_front_side', 'member_directory_include');
add_action('ws_plugin__s2member_during_configure_user_registration_admin_side', 'member_directory_include');
add_action('ws_plugin__s2member_after_handle_profile_modifications', 'member_directory_include');
add_action('ws_plugin__s2member_during_users_list_update_cols', 'member_directory_include');
function member_directory_include($vars = array ()) {
$s2_custom_fields = get_user_field('s2member_custom_fields', $vars['user_id']);
if ($s2_custom_fields['member_directory_include'] === '1')
update_user_meta($vars['user_id'], '_tern_wp_member_list', 'Enter List Name');
else
delete_user_meta($vars['user_id'], '_tern_wp_member_list');
}
?>
Users browsing this forum: Bing [Bot], Exabot [Bot] and 0 guests