bp_activity_heartbeat_last_recorded

Use WordPress Heartbeat API to check for latest activity update.

Description

(array) bp_activity_heartbeat_last_recorded( (array) $response = array(), (array) $data = array() ); 

Returns (array)

$response

Parameters (2)

0. $response — Optional. (array) => array()
Array containing Heartbeat API response.
1. $data — Optional. (array) => array()
Array containing data for Heartbeat API response.

Usage

  1. if ( !function_exists( 'bp_activity_heartbeat_last_recorded' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-filters.php'; 
  3.  
  4. // Array containing Heartbeat API response. 
  5. $response = array(); 
  6.  
  7. // Array containing data for Heartbeat API response. 
  8. $data = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_activity_heartbeat_last_recorded($response, $data); 
  12.  

Defined (1)

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

/bp-activity/bp-activity-filters.php  
  1. function bp_activity_heartbeat_last_recorded( $response = array(), $data = array() ) { 
  2. if ( empty( $data['bp_activity_last_recorded'] ) ) { 
  3. return $response; 
  4.  
  5. // Use the querystring argument stored in the cookie (to preserve 
  6. // filters), but force the offset to get only new items. 
  7. $activity_latest_args = bp_parse_args
  8. bp_ajax_querystring( 'activity' ),  
  9. array( 'since' => date( 'Y-m-d H:i:s', $data['bp_activity_last_recorded'] ) ),  
  10. 'activity_latest_args' 
  11. ); 
  12.  
  13. if ( ! empty( $data['bp_activity_last_recorded_search_terms'] ) && empty( $activity_latest_args['search_terms'] ) ) { 
  14. $activity_latest_args['search_terms'] = addslashes( $data['bp_activity_last_recorded_search_terms'] ); 
  15.  
  16. $newest_activities = array(); 
  17. $last_activity_recorded = 0; 
  18.  
  19. // Temporarily add a just-posted class for new activity items. 
  20.  
  21. ob_start(); 
  22. if ( bp_has_activities( $activity_latest_args ) ) { 
  23. while ( bp_activities() ) { 
  24.  
  25. $atime = strtotime( bp_get_activity_date_recorded() ); 
  26. if ( $last_activity_recorded < $atime ) { 
  27. $last_activity_recorded = $atime; 
  28.  
  29. bp_get_template_part( 'activity/entry' ); 
  30.  
  31. $newest_activities['activities'] = ob_get_contents(); 
  32. $newest_activities['last_recorded'] = $last_activity_recorded; 
  33. ob_end_clean(); 
  34.  
  35. // Remove the temporary filter. 
  36.  
  37. if ( ! empty( $newest_activities['last_recorded'] ) ) { 
  38. $response['bp_activity_newest_activities'] = $newest_activities; 
  39.  
  40. return $response;