get_usermeta() fixes.

git-svn-id: http://svn.automattic.com/wordpress/trunk@2721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-07-17 19:55:19 +00:00
parent 1e5d0b0736
commit 8226fb2239
1 changed files with 10 additions and 8 deletions

View File

@ -1952,21 +1952,23 @@ function get_usermeta( $user_id, $meta_key = '') {
if ( !empty($meta_key) ) { if ( !empty($meta_key) ) {
$meta_key = preg_replace('|a-z0-9_|i', '', $meta_key); $meta_key = preg_replace('|a-z0-9_|i', '', $meta_key);
$metas = $wpdb->get_results("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$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 { } else {
$metas = $wpdb->get_results("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id'"); $metas = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id'");
} }
foreach ($metas as $index => $meta) { foreach ($metas as $index => $meta) {
@ $value = unserialize($meta->meta_key); @ $value = unserialize($meta->meta_value);
if ($value !== FALSE) if ($value === FALSE)
$metas[$index]->meta_key = $value; $value = $meta->meta_value;
$values[] = $value;
} }
if ( !empty($meta_key) ) if ( count($values) == 1 )
return $metas[0]; return $values[0];
else else
return $metas; return $values;
} }
function update_usermeta( $user_id, $meta_key, $meta_value ) { function update_usermeta( $user_id, $meta_key, $meta_value ) {