Read s2Member level from database
Posted: July 31st, 2010, 7:38 pm
Hi again Jason,
Here is my code to get the s2Member level out of the database.
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!
Here is my code to get the s2Member level out of the database.
- Code: Select all
$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!