Community Support Forums — WordPress® ( Users Helping Users ) — 2011-02-14T21:27:22-05:00 http://www.primothemes.com/forums/feed.php?f=4&t=496 2011-02-14T21:27:22-05:00 http://www.primothemes.com/forums/viewtopic.php?t=496&p=6723#p6723 <![CDATA[Re: Read s2Member level from database]]>
It's been a while - hope you're doing great! :mrgreen:

Congratulations on a fine piece of coding to make a nice interface for configuring arbitrary user-defined select lists and so on - very good stuff.

If a Custom Registration Field has a drop-down list, and we enter data pairs (name|value) for the drop-down list, where in the database do these data pairs get stored?

I found it - JSON encoded data in wp_options.

I need to write a function to swap out the entire list and replace it with a new set of data pairs (for a given Custom Registration Field).

I will write a test procedure to grab the data, decode and dump it - and take it from there. Any pointers on constructing this little function will be greatly appreciated.

Thanks a million, Marty

Statistics: Posted by martonic — February 14th, 2011, 9:27 pm


]]>
2010-08-27T13:39:14-05:00 http://www.primothemes.com/forums/viewtopic.php?t=496&p=2617#p2617 <![CDATA[Re: Read s2Member level from database]]> ~ Thanks for your patience.

That's a great suggestion for an API function. @TODO.
Until there is an API function integrated into s2Member for this, here's how it works:
Code:
global $current_user;
$custom_fields = get_user_option("s2member_custom_fields");

$custom_fields["telephone"] = "999-999-9999";
update_user_option($current_user->ID, "s2member_custom_fields", $custom_fields);

Of course, you could also do this manually through the Dashboard. Go to "Users" in your Dashboard, and just click the "Edit" link, there you can change all of the Custom Fields manually.

Statistics: Posted by Jason Caldwell — August 27th, 2010, 1:39 pm


]]>
2010-08-21T21:01:25-05:00 http://www.primothemes.com/forums/viewtopic.php?t=496&p=2515#p2515 <![CDATA[How to set reg field value?]]>
Thank you very much for the ongoing fixes and improvements. :mrgreen:

What is the code to set a "custom registration field"? That is, if there is a custom registration field called "telephone", what is the php code to set its value? :?:

Statistics: Posted by martonic — August 21st, 2010, 9:01 pm


]]>
2010-08-10T12:02:30-05:00 http://www.primothemes.com/forums/viewtopic.php?t=496&p=2246#p2246 <![CDATA[Re: Read s2Member level from database]]> Statistics: Posted by martonic — August 10th, 2010, 12:02 pm


]]>
2010-08-05T15:26:52-05:00 http://www.primothemes.com/forums/viewtopic.php?t=496&p=2153#p2153 <![CDATA[Re: Read s2Member level from database]]> ~ Sorry for my delayed response.

Here is how I would determine the role of a User:
( this is just some pseudo code to clarify how it's done )
Code:
$user = new WP_User([ existing user ID or a Username is also fine ]);
$role = $user->roles[0]; // subscriber, or s2member_level[1 2,3,4]

Here is an actual example:
Code:
$user = new WP_User(123);
echo $user->roles[0]; // s2member_level1

Now, assigning a new Role is very easy.
Code:
$user = new WP_User(123);
$user->set_role("s2member_level2");

Statistics: Posted by Jason Caldwell — August 5th, 2010, 3:26 pm


]]>
2010-07-31T19:38:49-05:00 http://www.primothemes.com/forums/viewtopic.php?t=496&p=2011#p2011 <![CDATA[Read s2Member level from database]]>
Here is my code to get the s2Member level out of the database.

Code:
   $key = "wp_capabilities";
   $fields = get_user_meta($wp_id, $key, false);
   $level = 0;
   if ($fields != null && is_array($fields)) {
        for ($i = 0;  $level == 0 && $i < sizeof($fields); $i++) {
            if      (array_key_exists("s2member_level4", $fields[$i])) $level = 4;
            else if (array_key_exists("s2member_level3", $fields[$i])) $level = 3;
            else if (array_key_exists("s2member_level2", $fields[$i])) $level = 2;
            else if (array_key_exists("s2member_level1", $fields[$i])) $level = 1;
        }
    }


Is there an easier way to do it?

Also, how do you set it? I need to set it, I am overwriting the wp_capabilites record (since add_usermeta does not work with your strings). Oy! Can you help with this? Thanks!

Statistics: Posted by martonic — July 31st, 2010, 7:38 pm


]]>