bp_activity_akismet_delete_old_metadata

Delete old spam activity meta data.

Description

bp_activity_akismet_delete_old_metadata(); 

This is done as a clean-up mechanism, as _bp_akismet_submission meta can grow to be quite large.


Usage

  1. if ( !function_exists( 'bp_activity_akismet_delete_old_metadata' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-akismet.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_activity_akismet_delete_old_metadata(); 
  7.  

Defined (1)

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

/bp-activity/bp-activity-akismet.php  
  1. function bp_activity_akismet_delete_old_metadata() { 
  2. global $wpdb; 
  3.  
  4. $bp =buddypress); 
  5.  
  6. /** 
  7. * Filters the threshold for how many days old Akismet metadata needs to be before being automatically deleted. 
  8. * @since 1.6.0 
  9. * @param integer 15 How many days old metadata needs to be. 
  10. */ 
  11.  
  12. // Enforce a minimum of 1 day. 
  13. $interval = max( 1, absint( $interval ) ); 
  14.  
  15. // _bp_akismet_submission meta values are large, so expire them after $interval days regardless of the activity status 
  16. $sql = $wpdb->prepare( "SELECT a.id FROM {$bp->activity->table_name} a LEFT JOIN {$bp->activity->table_name_meta} m ON a.id = m.activity_id WHERE m.meta_key = %s AND DATE_SUB(%s, INTERVAL {$interval} DAY) > a.date_recorded LIMIT 10000", '_bp_akismet_submission', current_time( 'mysql', 1 ) ); 
  17. $activity_ids = $wpdb->get_col( $sql ); 
  18.  
  19. if ( ! empty( $activity_ids ) ) { 
  20. foreach ( $activity_ids as $activity_id ) 
  21. bp_activity_delete_meta( $activity_id, '_bp_akismet_submission' );