bp_activity_generate_action_string

Generate an activity action string for an activity item.

Description

(string|bool) bp_activity_generate_action_string( (object) $activity ); 

Returns (string|bool)

Returns false if no callback is found, otherwise returns the formatted action string.

Parameters (1)

0. $activity (object)
Activity data object.

Usage

  1. if ( !function_exists( 'bp_activity_generate_action_string' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // Activity data object. 
  5. $activity = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_activity_generate_action_string($activity); 
  9.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_generate_action_string( $activity ) { 
  2.  
  3. // Check for valid input. 
  4. if ( empty( $activity->component ) || empty( $activity->type ) ) { 
  5. return false; 
  6.  
  7. // Check for registered format callback. 
  8. $actions = bp_activity_get_actions(); 
  9. if ( empty( $actions->{$activity->component}->{$activity->type}['format_callback'] ) ) { 
  10. return false; 
  11.  
  12. // We apply the format_callback as a filter. 
  13. add_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 ); 
  14.  
  15. /** 
  16. * Filters the string for the activity action being returned. 
  17. * @since 2.0.0 
  18. * @param BP_Activity_Activity $action Action string being requested. 
  19. * @param BP_Activity_Activity $activity Activity item object. 
  20. */ 
  21. $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity ); 
  22.  
  23. // Remove the filter for future activity items. 
  24. remove_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10 ); 
  25.  
  26. return $action;