Community Support Forums — WordPress® ( Users Helping Users ) — 2011-07-09T21:05:50-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=10414 2011-07-09T21:05:50-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=26330#p26330 <![CDATA[Re: Capture custom registration field during registration pr]]>

Statistics: Posted by Cristián Lávaque — July 9th, 2011, 9:05 pm


]]>
2011-07-09T08:14:58-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=25770#p25770 <![CDATA[Re: Capture custom registration field during registration pr]]>
Here's the code that worked:

Code:
<?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');
     }
?>


I really appreciate your help.

Thank you, both!

Scott

Statistics: Posted by nashvillegeek — July 9th, 2011, 8:14 am


]]>
2011-07-09T02:55:28-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24678#p24678 <![CDATA[Re: Capture custom registration field during registration pr]]>
Code:
<?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');
 }
?>

Statistics: Posted by Cristián Lávaque — July 9th, 2011, 2:55 am


]]>
2011-07-09T02:49:19-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24676#p24676 <![CDATA[Re: Capture custom registration field during registration pr]]> Awesome. Thanks for the follow-ups.

Yes, delete_user_option() does exist, and that's what I would use, as opposed to update_user_option() with an empty value. This function is available, it's just not documented in the Codex yet. I remember I had to dig for this one too.

/wp-includes/user.php
Code:
/**
* 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 )

Statistics: Posted by Jason Caldwell — July 9th, 2011, 2:49 am


]]>
2011-07-09T02:41:35-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24675#p24675 <![CDATA[Re: Capture custom registration field during registration pr]]>
Jason Caldwell wrote:
Nice work. May I suggest the use of "update_user_meta" or "update_user_option" instead of "add_user_meta"?


Great tip! I didn't know about those functions, I had just rearranged the code. Thanks for the lesson. :)

Quick question, though: I didn't find a delete_user_option function, just the delete_option one, which doesn't take a user parameter. Should I then, instead, use update_user_option and give it an empty or false value? E.g.

update_user_option($vars['user_id'], '_tern_wp_member_list', '');
or
update_user_option($vars['user_id'], '_tern_wp_member_list', false);

If so, then the hack could be like this

Code:
<?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.


Cool. :)

Statistics: Posted by Cristián Lávaque — July 9th, 2011, 2:41 am


]]>
2011-07-09T01:49:32-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24672#p24672 <![CDATA[Re: Capture custom registration field during registration pr]]>
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.

Statistics: Posted by nashvillegeek — July 9th, 2011, 1:49 am


]]>
2011-07-09T00:08:39-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24671#p24671 <![CDATA[Re: Capture custom registration field during registration pr]]> Nice work. May I suggest the use of "update_user_meta" or "update_user_option" instead of "add_user_meta"? That way if the meta data does not yet exist, it will be created. If it does, it will be updated. See: http://codex.wordpress.org/Function_Ref ... _user_meta
http://codex.wordpress.org/Function_Ref ... ser_option

Also, just a quick FYI here.
The main distinction between *_user_meta() functions and *_user_option() functions, is that *_user_option() stores data in a way that associates the information with a User on a particular instance of WordPress ( i.e. it's NOT global by default ). Whereas *_user_meta() functions store data that should be associated with all instances of WordPress ( i.e. all Child Blogs of a Multisite Network ). Thus, in practice, it is best to store most data on a per-instance basis, with *_user_option() functions.

Neither way is wrong or right though, it just depends on your preference. In the case of s2Member, almost all s2Member Profile fields are stored on a per-instance basis, with *_user_option() functions.

Statistics: Posted by Jason Caldwell — July 9th, 2011, 12:08 am


]]>
2011-07-08T23:54:24-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24670#p24670 <![CDATA[Re: Capture custom registration field during registration pr]]>

Code:
<?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');
 }
?>

Statistics: Posted by Cristián Lávaque — July 8th, 2011, 11:54 pm


]]>
2011-07-08T23:38:10-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24669#p24669 <![CDATA[Re: Capture custom registration field during registration pr]]>
Cristián Lávaque wrote:
Jason, does 'ws_plugin__s2member_after_handle_profile_modifications' work for both, front and admin modifications?
No, in order to hit the admin side for Profile modifications, you'll need this additional Hook.
Code:
add_action('ws_plugin__s2member_during_users_list_update_cols', 'member_directory_include'); 
$vars['user_id'] is available with this Hook as well.
I'll see if I can get a Hook in there that covers all of these with just one action Hook in a future release.

Statistics: Posted by Jason Caldwell — July 8th, 2011, 11:38 pm


]]>
2011-07-08T23:30:07-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24668#p24668 <![CDATA[Re: Capture custom registration field during registration pr]]> 'ws_plugin__s2member_after_handle_profile_modifications' work for both, front and admin modifications?

Geek, here's the updated hack.

Code:
<?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');
 }
?>


I hope it works. :)

Statistics: Posted by Cristián Lávaque — July 8th, 2011, 11:30 pm


]]>
2011-07-08T23:24:46-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24667#p24667 <![CDATA[Re: Capture custom registration field during registration pr]]>

Statistics: Posted by Cristián Lávaque — July 8th, 2011, 11:24 pm


]]>
2011-07-08T23:13:46-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24664#p24664 <![CDATA[Re: Capture custom registration field during registration pr]]>
Cristián Lávaque wrote:
Thanks! is $vars['user_id'] also available when using the hook 'ws_plugin__s2member_after_handle_profile_modifications'?
Yes, it is also available for the Profile modification Hook.

Statistics: Posted by Jason Caldwell — July 8th, 2011, 11:13 pm


]]>
2011-07-08T23:11:01-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24662#p24662 <![CDATA[Re: Capture custom registration field during registration pr]]> $vars['user_id'] also available when using the hook 'ws_plugin__s2member_after_handle_profile_modifications'?

Statistics: Posted by Cristián Lávaque — July 8th, 2011, 11:11 pm


]]>
2011-07-08T23:07:25-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24660#p24660 <![CDATA[Re: Capture custom registration field during registration pr]]> Ah. Thanks for the help.

Something like this might help.
Create directory and file:
/wp-content/mu-plugins/s2-hacks.php
Code:
<?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.
    }
?>

Statistics: Posted by Jason Caldwell — July 8th, 2011, 11:07 pm


]]>
2011-07-08T22:39:17-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=24631#p24631 <![CDATA[Re: Capture custom registration field during registration pr]]>
Thanks for taking a look. :)

Statistics: Posted by Cristián Lávaque — July 8th, 2011, 10:39 pm


]]>
2011-07-08T21:03:46-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22714#p22714 <![CDATA[Re: Capture custom registration field during registration pr]]> Thanks for pointing out this thread.


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?

Statistics: Posted by Jason Caldwell — July 8th, 2011, 9:03 pm


]]>
2011-07-08T20:25:40-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22709#p22709 <![CDATA[Re: Capture custom registration field during registration pr]]>

I'll ask Jason what hook he'd recommend after the registration.

Statistics: Posted by Cristián Lávaque — July 8th, 2011, 8:25 pm


]]>
2011-07-08T11:37:33-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22654#p22654 <![CDATA[Re: Capture custom registration field during registration pr]]>
You've been a great help, Cristian. Thanks!

Statistics: Posted by nashvillegeek — July 8th, 2011, 11:37 am


]]>
2011-07-07T17:53:46-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22617#p22617 <![CDATA[Re: Capture custom registration field during registration pr]]>

You could probably simplify that, though, since you don't need all the custom fields labels. Here's a suggestion:

Code:
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');
 }
 


Let me know if it works.

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?


Maybe this one? https://codex.wordpress.org/Plugin_API/ ... r_register

Statistics: Posted by Cristián Lávaque — July 7th, 2011, 5:53 pm


]]>
2011-07-07T16:33:31-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22595#p22595 <![CDATA[Re: Capture custom registration field during registration pr]]> Statistics: Posted by nashvillegeek — July 7th, 2011, 4:33 pm


]]>
2011-07-07T15:27:46-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22576#p22576 <![CDATA[Re: Capture custom registration field during registration pr]]>

Code:


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");
 


Thanks again.

Statistics: Posted by nashvillegeek — July 7th, 2011, 3:27 pm


]]>
2011-07-07T14:11:35-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22565#p22565 <![CDATA[Re: Capture custom registration field during registration pr]]>
Code:
$s2_custom_fields = get_user_option('wp_s2member_custom_fields', $user_id);  


viewtopic.php?f=4&t=6546&p=16582#p16582

Statistics: Posted by Cristián Lávaque — July 7th, 2011, 2:11 pm


]]>
2011-07-07T13:50:01-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22561#p22561 <![CDATA[Re: Capture custom registration field during registration pr]]>
Thanks.

Statistics: Posted by nashvillegeek — July 7th, 2011, 1:50 pm


]]>
2011-07-07T02:15:22-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22519#p22519 <![CDATA[Re: Capture custom registration field during registration pr]]> WP Admin -> Member List -> Edit Members

Now, you could add the s2Member custom registration field to give users the choice whether they'll show up in the list or not, then udate the Member List settings above based on that.

Let me see if I can find a hook that could help...

You could try ws_plugin__s2member_after_handle_profile_modifications:

viewtopic.php?f=40&t=9359&p=19397&hilit=ws_plugin__s2member_after_handle_profile_modifications
viewtopic.php?f=40&t=9605&p=19643&hilit=ws_plugin__s2member_after_handle_profile_modifications#

Some comments from Jason on this topic viewtopic.php?f=4&p=2252#p2252

This may be useful too http://codex.wordpress.org/Plugin_API/A ... ile_update

I hope that helps!

Statistics: Posted by Cristián Lávaque — July 7th, 2011, 2:15 am


]]>
2011-07-06T11:51:52-05:00 http://www.primothemes.com/forums/viewtopic.php?t=10414&p=22486#p22486 <![CDATA[Capture custom registration field during registration proces]]>
I'm trying to figure out how to capture a custom registration checkbox or radio button entry from the registration form. The functionality would basically give the member the option to appear in the member list generated by the Members List plugin. To do this, I would need to capture the selection and add it to the users WP usermeta.

Thinking this through, I would also need it to update when that field is updated in the edit profile page.

I've created my s2-hacks.php file and have searched through the classes folder for hooks, etc, but am still struggling a bit.

Any direction would be appreciated.

Thanks

Statistics: Posted by nashvillegeek — July 6th, 2011, 11:51 am


]]>