bbp_get_user_profile_url

Return URL to the profile page of a user.

Description

(string) bbp_get_user_profile_url( (int) $user_id = 0, (string) $user_nicename = '' ); 

Returns (string)

User profile url

Parameters (2)

0. $user_id — Optional. (int)
User id
1. $user_nicename — Optional. (string) => ''
User nicename

Usage

  1. if ( !function_exists( 'bbp_get_user_profile_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/template.php'; 
  3.  
  4. // Optional. User id 
  5. $user_id = -1; 
  6.  
  7. // Optional. User nicename 
  8. $user_nicename = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_get_user_profile_url($user_id, $user_nicename); 
  12.  

Defined (1)

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

/includes/users/template.php  
  1. function bbp_get_user_profile_url( $user_id = 0, $user_nicename = '' ) { 
  2. global $wp_rewrite; 
  3.  
  4. // Use displayed user ID if there is one, and one isn't requested 
  5. $user_id = bbp_get_user_id( $user_id ); 
  6. if ( empty( $user_id ) ) 
  7. return false; 
  8.  
  9. // Allow early overriding of the profile URL to cut down on processing 
  10. $early_profile_url = apply_filters( 'bbp_pre_get_user_profile_url', (int) $user_id ); 
  11. if ( is_string( $early_profile_url ) ) 
  12. return $early_profile_url; 
  13.  
  14. // Pretty permalinks 
  15. if ( $wp_rewrite->using_permalinks() ) { 
  16. $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%'; 
  17.  
  18. // Get username if not passed 
  19. if ( empty( $user_nicename ) ) { 
  20. $user_nicename = bbp_get_user_nicename( $user_id ); 
  21.  
  22. $url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url ); 
  23. $url = home_url( user_trailingslashit( $url ) ); 
  24.  
  25. // Unpretty permalinks 
  26. } else { 
  27. $url = add_query_arg( array( bbp_get_user_rewrite_id() => $user_id ), home_url( '/' ) ); 
  28.  
  29. return apply_filters( 'bbp_get_user_profile_url', $url, $user_id, $user_nicename );