bp_get_groups_action_link

Get a URL for a group component action.

Description

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

Returns (string)

Parameters (3)

0. $action — Optional. (string) => ''
The action.
1. $query_args — Optional. (string) => ''
The query args.
2. $nonce — Optional. (bool) => false
The nonce.

Usage

  1. if ( !function_exists( 'bp_get_groups_action_link' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-groups/bp-groups-template.php'; 
  3.  
  4. // The action. 
  5. $action = ''; 
  6.  
  7. // The query args. 
  8. $query_args = ''; 
  9.  
  10. // The nonce. 
  11. $nonce = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_get_groups_action_link($action, $query_args, $nonce); 
  15.  

Defined (1)

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

/bp-groups/bp-groups-template.php  
  1. function bp_get_groups_action_link( $action = '', $query_args = '', $nonce = false ) { 
  2.  
  3. $current_group = groups_get_current_group(); 
  4. $url = ''; 
  5.  
  6. // Must be a group. 
  7. if ( ! empty( $current_group->id ) ) { 
  8.  
  9. // Append $action to $url if provided 
  10. if ( !empty( $action ) ) { 
  11. $url = bp_get_group_permalink( $current_group ) . $action; 
  12. } else { 
  13. $url = bp_get_group_permalink( $current_group ); 
  14.  
  15. // Add a slash at the end of our user url. 
  16. $url = trailingslashit( $url ); 
  17.  
  18. // Add possible query args. 
  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. /** 
  29. * Filters a URL for a group component action. 
  30. * @since 2.1.0 
  31. * @param string $url URL for a group component action. 
  32. * @param string $action Action being taken for the group. 
  33. * @param string $query_args Query arguments being passed. 
  34. * @param bool $nonce Whether or not to add a nonce. 
  35. */ 
  36. return apply_filters( 'bp_get_groups_action_link', $url, $action, $query_args, $nonce );