bp_activity_delete_meta

Delete a meta entry from the DB for an activity stream item.

Description

bp_activity_delete_meta( (int) $activity_id, (string) $meta_key = '', (string) $meta_value = '', (bool) $delete_all = false ); 

Parameters (4)

0. $activity_id (int)
ID of the activity item whose metadata is being deleted.
1. $meta_key — Optional. (string) => ''
The key of the metadata being deleted. If omitted, all metadata associated with the activity item will be deleted.
2. $meta_value — Optional. (string) => ''
If present, the metadata will only be deleted if the meta_value matches this parameter.
3. $delete_all — Optional. (bool) => false
If true, delete matching metadata entries for all objects, ignoring the specified object_id. Otherwise, only delete matching metadata entries for the specified activity item. Default: false.

Usage

  1. if ( !function_exists( 'bp_activity_delete_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // ID of the activity item whose metadata is being deleted. 
  5. $activity_id = -1; 
  6. $meta_key = ''; 
  7.  
  8. // Optional. If present, the metadata will only be 
  9. // deleted if the meta_value matches this parameter. 
  10. $meta_value = ''; 
  11. $delete_all = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_activity_delete_meta($activity_id, $meta_key, $meta_value, $delete_all); 
  15.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) { 
  2.  
  3. // Legacy - if no meta_key is passed, delete all for the item. 
  4. if ( empty( $meta_key ) ) { 
  5. $all_meta = bp_activity_get_meta( $activity_id ); 
  6. $keys = ! empty( $all_meta ) ? array_keys( $all_meta ) : array(); 
  7.  
  8. // With no meta_key, ignore $delete_all. 
  9. $delete_all = false; 
  10. } else { 
  11. $keys = array( $meta_key ); 
  12.  
  13. $retval = true; 
  14.  
  15. foreach ( $keys as $key ) { 
  16. $retval = delete_metadata( 'activity', $activity_id, $key, $meta_value, $delete_all ); 
  17.  
  18. return $retval;