bp_insert_activity_meta

Attach metadata about an activity item to the activity content.

Description

(string) bp_insert_activity_meta( (string) $content = '' ); 

This metadata includes the time since the item was posted (which will appear as a link to the item's permalink).

Returns (string)

The activity content with the metadata string attached.

Parameters (1)

0. $content — Optional. (string) => ''
The activity content.

Usage

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

Defined (1)

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

/bp-activity/bp-activity-template.php  
  1. function bp_insert_activity_meta( $content = '' ) { 
  2. global $activities_template; 
  3.  
  4. // Strip any legacy time since placeholders from BP 1.0-1.1. 
  5. $new_content = str_replace( '<span class="time-since">%s</span>', '', $content ); 
  6.  
  7. // Get the time since this activity was recorded. 
  8. $date_recorded = bp_core_time_since( $activities_template->activity->date_recorded ); 
  9.  
  10. // Set up 'time-since' <span>. 
  11. $time_since = sprintf( 
  12. '<span class="time-since" data-livestamp="%1$s">%2$s</span>',  
  13. bp_core_get_iso8601_date( $activities_template->activity->date_recorded ),  
  14. $date_recorded 
  15. ); 
  16.  
  17. /** 
  18. * Filters the activity item time since markup. 
  19. * @since 1.2.0 
  20. * @param array $value Array containing the time since markup and the current activity component. 
  21. */ 
  22. $time_since,  
  23. &$activities_template->activity 
  24. ) ); 
  25.  
  26. // Insert the permalink. 
  27. if ( ! bp_is_single_activity() ) { 
  28.  
  29. // Setup variables for activity meta. 
  30. $activity_permalink = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 
  31. $activity_meta = sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>',  
  32. $new_content,  
  33. $activity_permalink,  
  34. esc_attr__( 'View Discussion', buddypress ),  
  35. $time_since 
  36. ); 
  37.  
  38. /** 
  39. * Filters the activity permalink to be added to the activity content. 
  40. * @since 1.2.0 
  41. * @param array $value Array containing the html markup for the activity permalink, after being parsed by 
  42. * sprintf and current activity component. 
  43. */ 
  44. $activity_meta,  
  45. &$activities_template->activity 
  46. ) ); 
  47. } else { 
  48. $new_content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH ); 
  49.  
  50. /** 
  51. * Filters the activity content after activity metadata has been attached. 
  52. * @since 1.2.0 
  53. * @param string $content Activity content with the activity metadata added. 
  54. */ 
  55. return apply_filters( 'bp_insert_activity_meta', $new_content, $content );