delete_usermeta

Remove user meta data.

Description

delete_usermeta( (int) $user_id, (string) $meta_key, (string) $meta_value = '' ); 

Parameters (3)

0. $user_id (int)
The user id.
1. $meta_key (string)
The meta key.
2. $meta_value — Optional. (string) => ''
The meta value.

Usage

  1. if ( !function_exists( 'delete_usermeta' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // The meta key. 
  8. $meta_key = ''; 
  9.  
  10. // The meta value. 
  11. $meta_value = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = delete_usermeta($user_id, $meta_key, $meta_value); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/deprecated.php  
  1. function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) { 
  2. _deprecated_function( __FUNCTION__, '3.0.0', 'delete_user_meta()' ); 
  3. global $wpdb; 
  4. if ( !is_numeric( $user_id ) ) 
  5. return false; 
  6. $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); 
  7.  
  8. if ( is_array($meta_value) || is_object($meta_value) ) 
  9. $meta_value = serialize($meta_value); 
  10. $meta_value = trim( $meta_value ); 
  11.  
  12. $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); 
  13.  
  14. if ( $cur && $cur->umeta_id ) 
  15. do_action( 'delete_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); 
  16.  
  17. if ( ! empty($meta_value) ) 
  18. $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s AND meta_value = %s", $user_id, $meta_key, $meta_value) ); 
  19. else 
  20. $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); 
  21.  
  22. clean_user_cache( $user_id ); 
  23. wp_cache_delete( $user_id, 'user_meta' ); 
  24.  
  25. if ( $cur && $cur->umeta_id ) 
  26. do_action( 'deleted_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); 
  27.  
  28. return true;