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™

Extra registration field question

s2Member Plugin. A Membership plugin for WordPress®.

Extra registration field question

Postby ngentile » November 2nd, 2011, 1:20 am

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!
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Cristián Lávaque » November 2nd, 2011, 2:49 am

Code: Select all
$s2_custom_fields get_user_option('wp_s2member_custom_fields'$user_id); 


I hope that helps. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Extra registration field question

Postby ngentile » November 2nd, 2011, 12:42 pm

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.
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Cristián Lávaque » November 2nd, 2011, 8:16 pm

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. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Extra registration field question

Postby ngentile » November 2nd, 2011, 8:25 pm

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?
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Cristián Lávaque » November 2nd, 2011, 11:28 pm

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. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Extra registration field question

Postby ngentile » November 3rd, 2011, 12:03 am

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.
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Cristián Lávaque » November 3rd, 2011, 12:04 am

:)

Do the print_r($s2_custom_fields) to see the array and then you'll know how to get the fields you want.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Extra registration field question

Postby ngentile » November 3rd, 2011, 12:18 am

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?
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Cristián Lávaque » November 3rd, 2011, 12:31 am

Have you used PHP arrays before?

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

Thanks. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Extra registration field question

Postby ngentile » November 3rd, 2011, 12:58 am

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.
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Cristián Lávaque » November 3rd, 2011, 1:21 am

Got ya. Could you quote here the output of that print_r x'ing any private info? :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Extra registration field question

Postby ngentile » November 3rd, 2011, 2:21 am

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
Last edited by Cristián Lávaque on November 4th, 2011, 12:15 am, edited 1 time in total.
Reason: Improve code readability. http://www.primothemes.com/forums/viewtopic.php?f=36&t=2780
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby ngentile » November 3rd, 2011, 1:43 pm

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.
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Cristián Lávaque » November 4th, 2011, 12:17 am

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. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Extra registration field question

Postby ngentile » November 4th, 2011, 12:49 am

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.
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby ngentile » November 4th, 2011, 12:52 am

User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Cristián Lávaque » November 4th, 2011, 1:21 am

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?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Extra registration field question

Postby ngentile » November 4th, 2011, 1:29 am

nope...
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Eduan » November 4th, 2011, 10:17 am

@ngentile
Do you have the Exec-PHP plugin installed?
Now officially accepting Professional s2Member installations along with Bruce C (a.k.a. Ace).

If you're interested in a Professional s2Member Installation, or a Custom Coding Job, you can send your request here.
User avatar
Eduan
Experienced User
Experienced User
 
Posts: 1154
Joined: August 27, 2011
Location: Taxco de Alarcón, Guerrero, México.

Re: Extra registration field question

Postby ngentile » November 4th, 2011, 11:44 am

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.
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Eduan » November 4th, 2011, 11:46 am

Try doing it in Exec-PHP it's the best I've seen that allows that function.
Now officially accepting Professional s2Member installations along with Bruce C (a.k.a. Ace).

If you're interested in a Professional s2Member Installation, or a Custom Coding Job, you can send your request here.
User avatar
Eduan
Experienced User
Experienced User
 
Posts: 1154
Joined: August 27, 2011
Location: Taxco de Alarcón, Guerrero, México.

Re: Extra registration field question

Postby ngentile » November 4th, 2011, 12:01 pm

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?
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Re: Extra registration field question

Postby Eduan » November 4th, 2011, 12:07 pm

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.
Now officially accepting Professional s2Member installations along with Bruce C (a.k.a. Ace).

If you're interested in a Professional s2Member Installation, or a Custom Coding Job, you can send your request here.
User avatar
Eduan
Experienced User
Experienced User
 
Posts: 1154
Joined: August 27, 2011
Location: Taxco de Alarcón, Guerrero, México.

Re: Extra registration field question

Postby ngentile » November 4th, 2011, 3:42 pm

<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" /]
User avatar
ngentile
Registered User
Registered User
 
Posts: 32
Joined: October 6, 2011

Next

Return to s2Member Plugin

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 1 guest

cron