bp_core_get_upload_dir

Fetch data from the BP root blog's upload directory.

Description

(string) bp_core_get_upload_dir( (string) $type = 'upload_path' ); 

Returns (string)

The avatar upload directory path.

Parameters (1)

0. $type — Optional. (string) => 'upload_path'
The variable we want to return from the $bp->avatars object. Only upload_path and url. are supported. Default: upload_path .

Usage

  1. if ( !function_exists( 'bp_core_get_upload_dir' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-avatars.php'; 
  3.  
  4. // The variable we want to return from the $bp->avatars object. 
  5. // Only 'upload_path' and 'url' are supported. Default: 'upload_path'. 
  6. $type = 'upload_path'; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_core_get_upload_dir($type); 
  10.  

Defined (1)

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

/bp-core/bp-core-avatars.php  
  1. function bp_core_get_upload_dir( $type = 'upload_path' ) { 
  2. $bp =buddypress); 
  3.  
  4. switch ( $type ) { 
  5. case 'upload_path' : 
  6. $constant = 'BP_AVATAR_UPLOAD_PATH'; 
  7. $key = 'basedir'; 
  8.  
  9. break; 
  10.  
  11. case 'url' : 
  12. $constant = 'BP_AVATAR_URL'; 
  13. $key = 'baseurl'; 
  14.  
  15. break; 
  16.  
  17. default : 
  18. return false; 
  19.  
  20. break; 
  21.  
  22. // See if the value has already been calculated and stashed in the $bp global. 
  23. if ( isset( $bp->avatar->$type ) ) { 
  24. $retval = $bp->avatar->$type; 
  25. } else { 
  26. // If this value has been set in a constant, just use that. 
  27. if ( defined( $constant ) ) { 
  28. $retval = constant( $constant ); 
  29. } else { 
  30.  
  31. // Use cached upload dir data if available. 
  32. if ( ! empty( $bp->avatar->upload_dir ) ) { 
  33. $upload_dir = $bp->avatar->upload_dir; 
  34.  
  35. // No cache, so query for it. 
  36. } else { 
  37.  
  38. // Get upload directory information from current site. 
  39. $upload_dir = bp_upload_dir(); 
  40.  
  41. // Stash upload directory data for later use. 
  42. $bp->avatar->upload_dir = $upload_dir; 
  43.  
  44. // Directory does not exist and cannot be created. 
  45. if ( ! empty( $upload_dir[error] ) ) { 
  46. $retval = ''; 
  47.  
  48. } else { 
  49. $retval = $upload_dir[$key]; 
  50.  
  51. // If $key is 'baseurl', check to see if we're on SSL 
  52. // Workaround for WP13941, WP15928, WP19037. 
  53. if ( $key == 'baseurl' && is_ssl() ) { 
  54. $retval = str_replace( 'http://', 'https://', $retval ); 
  55.  
  56.  
  57. // Stash in $bp for later use. 
  58. $bp->avatar->$type = $retval; 
  59.  
  60. return $retval;