bp_activity_action_permalink_router

Catch and route requests for single activity item permalinks.

Description

bp_activity_action_permalink_router(); 

Usage

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

Defined (1)

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

/bp-activity/bp-activity-actions.php  
  1. function bp_activity_action_permalink_router() { 
  2.  
  3. // Not viewing activity. 
  4. return false; 
  5.  
  6. // No activity to display. 
  7. if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) ) 
  8. return false; 
  9.  
  10. // Get the activity details. 
  11. $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) ); 
  12.  
  13. // 404 if activity does not exist 
  14. if ( empty( $activity['activities'][0] ) ) { 
  15. bp_do_404(); 
  16. return; 
  17. } else { 
  18. $activity = $activity['activities'][0]; 
  19.  
  20. // Do not redirect at default. 
  21. $redirect = false; 
  22.  
  23. // Redirect based on the type of activity. 
  24. if ( bp_is_active( 'groups' ) && $activity->component ==buddypress)->groups->id ) { 
  25.  
  26. // Activity is a user update. 
  27. if ( ! empty( $activity->user_id ) ) { 
  28. $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 
  29.  
  30. // Activity is something else. 
  31. } else { 
  32.  
  33. // Set redirect to group activity stream. 
  34. if ( $group = groups_get_group( $activity->item_id ) ) { 
  35. $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 
  36.  
  37. // Set redirect to users' activity stream. 
  38. } elseif ( ! empty( $activity->user_id ) ) { 
  39. $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/'; 
  40.  
  41. // If set, add the original query string back onto the redirect URL. 
  42. if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { 
  43. $query_frags = array(); 
  44. wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags ); 
  45. $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect ); 
  46.  
  47. /** 
  48. * Filter the intended redirect url before the redirect occurs for the single activity item. 
  49. * @since 1.2.2 
  50. * @param array $value Array with url to redirect to and activity related to the redirect. 
  51. */ 
  52. if ( ! $redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) ) { 
  53.  
  54. // Redirect to the actual activity permalink page. 
  55. bp_core_redirect( $redirect );