bp_activity_get_permalink

Get the permalink for a single activity item.

Description

(string) bp_activity_get_permalink( (int) $activity_id, (bool) $activity_obj = false ); 

When only the $activity_id param is passed, BP has to instantiate a new BP_Activity_Activity object. To save yourself some processing overhead, be sure to pass the full $activity_obj parameter as well, if you already have it available.

Returns (string)

$link Permalink for the activity item.

Parameters (2)

0. $activity_id (int)
The unique id of the activity object.
1. $activity_obj — Optional. (bool) => false
The activity object.

Usage

  1. if ( !function_exists( 'bp_activity_get_permalink' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // The unique id of the activity object. 
  5. $activity_id = -1; 
  6.  
  7. // Optional. The activity object. 
  8. $activity_obj = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_activity_get_permalink($activity_id, $activity_obj); 
  12.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_get_permalink( $activity_id, $activity_obj = false ) { 
  2. $bp =buddypress); 
  3.  
  4. if ( empty( $activity_obj ) ) { 
  5. $activity_obj = new BP_Activity_Activity( $activity_id ); 
  6.  
  7. if ( isset( $activity_obj->current_comment ) ) { 
  8. $activity_obj = $activity_obj->current_comment; 
  9.  
  10. $use_primary_links = array( 
  11. 'new_blog_post',  
  12. 'new_blog_comment',  
  13. 'new_forum_topic',  
  14. 'new_forum_post',  
  15. ); 
  16.  
  17. if ( ! empty( $bp->activity->track ) ) { 
  18. $use_primary_links = array_merge( $use_primary_links, array_keys( $bp->activity->track ) ); 
  19.  
  20. if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) { 
  21. $link = $activity_obj->primary_link; 
  22. } else { 
  23. if ( 'activity_comment' == $activity_obj->type ) { 
  24. $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/#acomment-' . $activity_obj->id; 
  25. } else { 
  26. $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->id . '/'; 
  27.  
  28. /** 
  29. * Filters the activity permalink for the specified activity item. 
  30. * @since 1.2.0 
  31. * @param array $array Array holding activity permalink and activity item object. 
  32. */ 
  33. return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) );