Add delete_usermeta(). fixes #1992

git-svn-id: http://svn.automattic.com/wordpress/trunk@3247 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-11-30 19:19:47 +00:00
parent 548ef114e8
commit d9c7e8ff0d
1 changed files with 19 additions and 0 deletions

View File

@ -2147,6 +2147,25 @@ function update_usermeta( $user_id, $meta_key, $meta_value ) {
// FIXME: Need to delete username keyed cache object. // FIXME: Need to delete username keyed cache object.
} }
function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) {
global $wpdb;
if ( !is_numeric( $user_id ) )
return false;
$meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
if ( is_array($meta_value) || is_object($meta_value) )
$meta_value = serialize($meta_value);
$meta_value = trim( $meta_value );
if ( ! empty($meta_value) )
$wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key' AND meta_value = '$meta_value'");
else
$wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'");
wp_cache_delete($user_id, 'users');
// FIXME: Need to delete username keyed cache object.
}
function register_activation_hook($file, $function) { function register_activation_hook($file, $function) {
$file = plugin_basename($file); $file = plugin_basename($file);