bb_delete_meta

Deletes meta data from the database.

Description

bb_delete_meta( $object_id, $meta_key, $meta_value, $type, (bool) $global = false ); 

Parameters (5)

0. $object_id
The object id.
1. $meta_key
The meta key.
2. $meta_value
The meta value.
3. $type
The type.
4. $global — Optional. (bool) => false
The global.

Usage

  1. if ( !function_exists( 'bb_delete_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-meta.php'; 
  3.  
  4. // The object id. 
  5. $object_id = null; 
  6.  
  7. // The meta key. 
  8. $meta_key = null; 
  9.  
  10. // The meta value. 
  11. $meta_value = null; 
  12.  
  13. // The type. 
  14. $type = null; 
  15.  
  16. // The global. 
  17. $global = false; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = bb_delete_meta($object_id, $meta_key, $meta_value, $type, $global); 
  21.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-meta.php  
  1. function bb_delete_meta( $object_id = 0, $meta_key, $meta_value, $type, $global = false ) 
  2. global $bbdb; 
  3. if ( !is_numeric( $object_id ) || empty( $object_id ) && !$global ) { 
  4. return false; 
  5. $cache_object_id = $object_id = (int) $object_id; 
  6. switch ( $type ) { 
  7. case 'option': 
  8. $object_type = 'bb_option'; 
  9. break; 
  10. case 'user': 
  11. global $wp_users_object; 
  12. $id = $object_id; 
  13. return $wp_users_object->delete_meta( compact( 'id', 'meta_key', 'meta_value' ) ); 
  14. break; 
  15. case 'forum': 
  16. $object_type = 'bb_forum'; 
  17. break; 
  18. case 'topic': 
  19. $object_type = 'bb_topic'; 
  20. break; 
  21. case 'post': 
  22. $object_type = 'bb_post'; 
  23. break; 
  24. default: 
  25. $object_type = $type; 
  26. break; 
  27.  
  28. $meta_key = bb_sanitize_meta_key( $meta_key ); 
  29.  
  30. $meta_tuple = compact( 'object_type', 'object_id', 'meta_key', 'meta_value', 'type' ); 
  31. $meta_tuple = apply_filters( 'bb_delete_meta', $meta_tuple ); 
  32. extract( $meta_tuple, EXTR_OVERWRITE ); 
  33.  
  34. $meta_value = maybe_serialize( $meta_value ); 
  35.  
  36. if ( empty( $meta_value ) ) { 
  37. $meta_sql = $bbdb->prepare( "SELECT `meta_id` FROM `$bbdb->meta` WHERE `object_type` = %s AND `object_id` = %d AND `meta_key` = %s", $object_type, $object_id, $meta_key ); 
  38. } else { 
  39. $meta_sql = $bbdb->prepare( "SELECT `meta_id` FROM `$bbdb->meta` WHERE `object_type` = %s AND `object_id` = %d AND `meta_key` = %s AND `meta_value` = %s", $object_type, $object_id, $meta_key, $meta_value ); 
  40.  
  41. if ( !$meta_id = $bbdb->get_var( $meta_sql ) ) { 
  42. return false; 
  43.  
  44. $bbdb->query( $bbdb->prepare( "DELETE FROM `$bbdb->meta` WHERE `meta_id` = %d", $meta_id ) ); 
  45.  
  46. if ( $object_type == 'bb_option' ) { 
  47. $cache_object_id = $meta_key; 
  48. wp_cache_delete( $cache_object_id, 'bb_option_not_set' ); 
  49. wp_cache_delete( $cache_object_id, $object_type ); 
  50. return true;