Page 1 of 2

Extra registration field question

PostPosted: November 2nd, 2011, 1:20 am
by ngentile
The extra fields added to the user registration via s2member's interface are stored in a serialized array from what I have heard in another forum. Is there anyway to access this array for another plugin? I am trying to make a membership directory and want to be able to display the custom fields in the directory. I am using another plugin called 'member list' and it makes the connection but it only shows the word 'Array'. Thanks for any help!

Re: Extra registration field question

PostPosted: November 2nd, 2011, 2:49 am
by Cristián Lávaque
Code: Select all
$s2_custom_fields get_user_option('wp_s2member_custom_fields'$user_id); 


I hope that helps. :)

Re: Extra registration field question

PostPosted: November 2nd, 2011, 12:42 pm
by ngentile
It does help but I need some more detail. How do I reference specific fields in that array? There are really only two fields of about 6 that I have added that I want to show.

Re: Extra registration field question

PostPosted: November 2nd, 2011, 8:16 pm
by Cristián Lávaque
With that line you get all the custom registration fields as an array. From it you can use the ones you want only.

There's a function to get only a specific field, but I find it more comfortable to work with the full array if I need more than one field. :)

Re: Extra registration field question

PostPosted: November 2nd, 2011, 8:25 pm
by ngentile
Awesome. I appreciate you telling me. I know you have already helped alot but I need to know how to use that function you sent me earlier to access the array items?

$s2_custom_fields2 = get_user_option('wp_s2member_custom_fields[2]', $user_id);

Would it be something like that?

Re: Extra registration field question

PostPosted: November 2nd, 2011, 11:28 pm
by Cristián Lávaque
No. Here's an example:

Code: Select all
$user_id 1// Change this for a valid user ID in your blog.
$s2_custom_fields get_user_option('wp_s2member_custom_fields'$user_id);
print_r($s2_custom_fields); 


That should give an idea of what the array looks like and how to work with it. With the Member List plugin, you'd get the user ID variable from the loop when you're listing the members.

Here's a function I wrote that uses get_user_option. It should also help you see what you can do with it. viewtopic.php?f=4&t=6546&p=16582#p16582

I hope that helps. :)

Re: Extra registration field question

PostPosted: November 3rd, 2011, 12:03 am
by ngentile
Oh, I see! So basically you load the entire array for the given user into $s2_customfields variable.

Ok, so I have the array loaded into the variable but I still am unclear how to extract just the two fields I want. I know I have the correct user by using the user ID. I added 5 fields so I know the array has 5 fields. I just need to specify which to print. How can I say print element #4 from array? Thanks for your help. I know I am almost there.

Re: Extra registration field question

PostPosted: November 3rd, 2011, 12:04 am
by Cristián Lávaque
:)

Do the print_r($s2_custom_fields) to see the array and then you'll know how to get the fields you want.

Re: Extra registration field question

PostPosted: November 3rd, 2011, 12:18 am
by ngentile
Ok, so now I know that I need element 2 and 3, so I started with 2

<div class="tern_wp_members_wp_s2member_custom_fields[2]">%value%</div>

It loads the word array into the table it creates. Should I load the array into a separate variable and then place it in the markup?

Re: Extra registration field question

PostPosted: November 3rd, 2011, 12:31 am
by Cristián Lávaque
Have you used PHP arrays before?

Could you quote here the output of that print_r x'ing any private info?

Thanks. :)

Re: Extra registration field question

PostPosted: November 3rd, 2011, 12:58 am
by ngentile
Yes, but only in small scripts I have written and I'm really new to wordpress. So the interaction between the script and plugins is kicking my butt. I'm just really lost. I know I have access to the array but I don't know how to access the individual elements to plug into member list. Thank you for your help with this.

Re: Extra registration field question

PostPosted: November 3rd, 2011, 1:21 am
by Cristián Lávaque
Got ya. Could you quote here the output of that print_r x'ing any private info? :)

Re: Extra registration field question

PostPosted: November 3rd, 2011, 2:21 am
by ngentile
Everytime I try to print thr array i get this error:
coding Parse error: syntax error, unexpected $end in C:\Sites\Lodge\wp-content\plugins\allow-php-in-posts-and-pages\allowphp.php(77) : eval()'d code on line 3

where I ran this code: print_r($s2_custom_fields);

But I was able to use echo get_user_field("user_hobby"); to return the value successfully. I just don't know how to integrate that into the member list markup that looks like this:

Code: Select all
<li>
    <
div class="tern_wp_member_info">
        <
div class="tern_wp_members_display_name">admin</div>
        <
div class="tern_wp_members_user_email"><a href="mailto:ngentile@gmail.com">ngentile@gmail.com</a></div>
        <
div class="tern_wp_members_wp_s2member_custom_fields">echo get_user_field("user_hobby");</div>
    </
div>
</
li

Re: Extra registration field question

PostPosted: November 3rd, 2011, 1:43 pm
by ngentile
I know its just how I am trying to extract the element. Users that don't have those fields in their profile don't print that last line in their markup.

Re: Extra registration field question

PostPosted: November 4th, 2011, 12:17 am
by Cristián Lávaque
You need to use the PHP tags.

Code: Select all
        <div class="tern_wp_members_wp_s2member_custom_fields"><?php echo get_user_field('user_hobby'); ?></div>


I hope that helps. :)

Re: Extra registration field question

PostPosted: November 4th, 2011, 12:49 am
by ngentile
Already tried that. That's why I can't figure out what's wrong. I opened that page where the shortcode is embedded and just added the line - echo get_user_field("user_hobby"); after I read what you wrote in the post you directed me to earlier to see what happened. It printed the member list with no custom field included and then added the custom field of the logged in person at the bottom of the page. And not the last line of the memberlist, a separate set of brackets. Copy of my codeblock below:

******************** From Member list markup*****************
<li>
<div class="tern_wp_member_info">
<div class="tern_wp_members_display_name">admin</div>
<div class="tern_wp_members_user_email"><a href="mailto:ngentile@gmail.com">ngentile@gmail.com</a></div>
<div class="tern_wp_members_wp_s2member_custom_fields"><?php echo get_user_field("user_hobby"); ?></div>
</div>
</li>
************************************

************************* Member list page shortcode ********************
[members-list list="Main" search=true alpha=true pagination=true pagination2=true sort=true]


[php]
echo get_user_field("user_hobby");
[/php]

This is what has me stumped.

Re: Extra registration field question

PostPosted: November 4th, 2011, 12:52 am
by ngentile

Re: Extra registration field question

PostPosted: November 4th, 2011, 1:21 am
by Cristián Lávaque
Ah, get_user_field will output the field of the current user if you don't specify another one using an ID.

Code: Select all
echo get_user_field('user_hobby'$user_id); 


Does it help?

Re: Extra registration field question

PostPosted: November 4th, 2011, 1:29 am
by ngentile
nope...

Re: Extra registration field question

PostPosted: November 4th, 2011, 10:17 am
by Eduan
@ngentile
Do you have the Exec-PHP plugin installed?

Re: Extra registration field question

PostPosted: November 4th, 2011, 11:44 am
by ngentile
Thanks for replying. I am not using that particular plug-in but I am using 'Allow php in posts and pages', which does the same. I can execute php code outside of the loop that creates the list, just not in the list, which has me stumped. I don't get any errors or anything, just no output where that line is executed.

Re: Extra registration field question

PostPosted: November 4th, 2011, 11:46 am
by Eduan
Try doing it in Exec-PHP it's the best I've seen that allows that function.

Re: Extra registration field question

PostPosted: November 4th, 2011, 12:01 pm
by ngentile
Just updated it and read the manual. I adjusted all the settings in my wordpress install for the plugin to work and I get this error

Parse error: syntax error, unexpected ‘/’ in C:\Sites\Masonic Lodge\wp-content\plugins\exec-php\includes\runtime.php(42) : eval()’d code on line 5

This is the code it is trying to execute
<?php echo get_user_field("user_hobby"); /?>

What else you got?

Re: Extra registration field question

PostPosted: November 4th, 2011, 12:07 pm
by Eduan
Try this shortcode:
Code: Select all
[s2Get user_field="my_custom_field_id" /]

This doesn't need Exec-PHP or anything of the style.

I found it in WP Admin -> s2Member -> API / Scripting -> s2Member PHP/API Constants, thought maybe this would help.

Re: Extra registration field question

PostPosted: November 4th, 2011, 3:42 pm
by ngentile
<li>
<div class="tern_wp_member_info">
<div class="tern_wp_members_display_name">admin</div>
<div class="tern_wp_members_user_email"><a href="mailto:ngentile@gmail.com">ngentile@gmail.com</a></div>
<div class="tern_wp_members_wp_s2member_custom_fields">[s2Get user_field="user_hobby" /]</div>
</div>
</li>

This is what I input in my markup. It just renders that code as a text string as shown below

Joanna Gentile
test@home.com
[s2Get user_field="user_hobby" /]