bp_get_members_component_link

Generate a link to a members component subpage.

Description

(string) bp_get_members_component_link( (string) $component, (string) $action = '', (string) $query_args = '', (bool) $nonce = false ); 

Returns (string)

Parameters (4)

0. $component (string)
ID of the component (eg friends).
1. $action — Optional. (string) => ''
action slug (eg invites).
2. $query_args — Optional. (string) => ''
The query args.
3. $nonce — Optional. (bool) => false
If provided, the URL will be passed through wp_nonce_url() with $nonce as the action string.

Usage

  1. if ( !function_exists( 'bp_get_members_component_link' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-template.php'; 
  3.  
  4. // ID of the component (eg 'friends'). 
  5. $component = ''; 
  6.  
  7. // Optional. 'action' slug (eg 'invites'). 
  8. $action = ''; 
  9.  
  10. // The query args. 
  11. $query_args = ''; 
  12. $nonce = false; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = bp_get_members_component_link($component, $action, $query_args, $nonce); 
  16.  

Defined (1)

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

/bp-members/bp-members-template.php  
  1. function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) { 
  2.  
  3. // Must be displayed user. 
  4. if ( !bp_displayed_user_id() ) 
  5. return; 
  6.  
  7. $bp =buddypress); 
  8.  
  9. // Append $action to $url if there is no $type. 
  10. if ( !empty( $action ) ) 
  11. $url = bp_displayed_user_domain() . $bp->{$component}->slug . '/' . $action; 
  12. else 
  13. $url = bp_displayed_user_domain() . $bp->{$component}->slug; 
  14.  
  15. // Add a slash at the end of our user url. 
  16. $url = trailingslashit( $url ); 
  17.  
  18. // Add possible query arg. 
  19. if ( !empty( $query_args ) && is_array( $query_args ) ) 
  20. $url = add_query_arg( $query_args, $url ); 
  21.  
  22. // To nonce, or not to nonce... 
  23. if ( true === $nonce ) 
  24. $url = wp_nonce_url( $url ); 
  25. elseif ( is_string( $nonce ) ) 
  26. $url = wp_nonce_url( $url, $nonce ); 
  27.  
  28. // Return the url, if there is one. 
  29. if ( !empty( $url ) ) 
  30. return $url;