bb_get_uri

Return a URI based on the URI setting.

Description

(string) bb_get_uri( (constant) $resource = null, (constant) $query = null, $context = ); 

Returns (string)

The complete URI

Parameters (3)

0. $resource — Optional. (constant) => null
String The directory, may include a querystring
1. $query — Optional. (constant) => null
Mixed The query arguments as a querystring or an associative array
2. $context
Integer The context of the URI, use BB_URI_CONTEXT_*

Usage

  1. if ( !function_exists( 'bb_get_uri' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-core.php'; 
  3.  
  4. // string The directory, may include a querystring 
  5. $resource = null; 
  6.  
  7. // mixed The query arguments as a querystring or an associative array 
  8. $query = null; 
  9.  
  10. // integer The context of the URI, use BB_URI_CONTEXT_* 
  11. $context = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bb_get_uri($resource, $query, $context); 
  15.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-core.php  
  1. function bb_get_uri( $resource = null, $query = null, $context = BB_URI_CONTEXT_A_HREF
  2. // If there is a querystring in the resource then extract it 
  3. if ( $resource && strpos( $resource, '?' ) !== false ) { 
  4. list( $_resource, $_query ) = explode( '?', trim( $resource ), 2 ); 
  5. $resource = $_resource; 
  6. $_query = wp_parse_args( $_query ); 
  7. } else { 
  8. // Make sure $_query is an array for array_merge() 
  9. $_query = array(); 
  10.  
  11. // $query can be an array as well as a string 
  12. if ( $query ) { 
  13. if ( is_string( $query ) ) { 
  14. $query = ltrim( trim( $query ), '?' ); 
  15. $query = wp_parse_args( $query ); 
  16.  
  17. // Make sure $query is an array for array_merge() 
  18. if ( !$query ) { 
  19. $query = array(); 
  20.  
  21. // Merge the queries into a single array 
  22. $query = array_merge( $_query, $query ); 
  23.  
  24. // Make sure context is an integer 
  25. if ( !$context || !is_integer( $context ) ) { 
  26. $context = BB_URI_CONTEXT_A_HREF
  27.  
  28. // Get the base URI 
  29. static $_uri; 
  30. if( !isset( $_uri ) ) { 
  31. $_uri = bb_get_option( 'uri' ); 
  32. $uri = $_uri; 
  33.  
  34. // Use https? 
  35. if ( 
  36. ( ( $context & BB_URI_CONTEXT_BB_USER_FORMS ) && force_ssl_login() ) // Force https when required on user forms 
  37. || 
  38. ( ( $context & BB_URI_CONTEXT_BB_ADMIN ) && force_ssl_admin() ) // Force https when required in admin 
  39. ) { 
  40. static $_uri_ssl; 
  41. if( !isset( $_uri_ssl ) ) { 
  42. $_uri_ssl = bb_get_option( 'uri_ssl' ); 
  43. $uri = $_uri_ssl; 
  44.  
  45. // Add the directory 
  46. $uri .= ltrim( $resource, '/' ); 
  47.  
  48. // Add the query string to the URI 
  49. $uri = add_query_arg( $query, $uri ); 
  50.  
  51. return apply_filters( 'bb_get_uri', $uri, $resource, $context );