Retrieve User ID in 2.0 RC1
-
Howdy all,
I’ve got a blog in which I need to allow certain functionality for users depending on their role in WP 2.0. I know that the permissions system has moved the user level to the wp_usermeta table, so I’m wondering if there is still an easy way for me to retrieve the current users ID number in my PHP, therefore allowing me to look up their user level.
Alternatively, I don’t suppose there’s a quick and easy way to simply return subscriber, contributor, editor, etc is there? That’d be perfect…
??
[edit]
I found this get_usermeta(); function in the functions.php file:
function get_usermeta( $user_id, $meta_key = '') {
global $wpdb;
$user_id = (int) $user_id;if ( !empty($meta_key) ) {
$meta_key = preg_replace('|a-z0-9_|i', '', $meta_key);
$metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
} else {
$metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
}if ( empty($metas) ) {
if ( empty($meta_key) )
return array();
else
return '';
}foreach ($metas as $index => $meta) {
@ $value = unserialize($meta->meta_value);
if ( $value === FALSE )
$value = $meta->meta_value;$values[] = $value;
}if ( count($values) == 1 )
return $values[0];
else
return $values;
}This looks like it’s capable of returning the user level that I need, if I can feed it the current user’s ID. I’m not sure how to get the values out that it returns though: I hard-coded my user ID and meta key in, but obviously it doesn’t return anything if I don’t make a reference to it’s returned variables. Any ideas?
- The topic ‘Retrieve User ID in 2.0 RC1’ is closed to new replies.