bp_attachments_uploads_dir_get

Get the Attachments Uploads dir data.

Description

(string|array) bp_attachments_uploads_dir_get( (string) $data = '' ); 

Returns (string|array)

The needed Upload dir data.

Parameters (1)

0. $data — Optional. (string) => ''
The data to get. Possible values are: dir,, basedir & baseurl.. Leave empty to get all datas.

Usage

  1. if ( !function_exists( 'bp_attachments_uploads_dir_get' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-attachments.php'; 
  3.  
  4. // The data to get. Possible values are: 'dir', 'basedir' & 'baseurl'. 
  5. // Leave empty to get all datas. 
  6. $data = ''; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_attachments_uploads_dir_get($data); 
  10.  

Defined (1)

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

/bp-core/bp-core-attachments.php  
  1. function bp_attachments_uploads_dir_get( $data = '' ) { 
  2. $attachments_dir = buddypress; 
  3. $retval = ''; 
  4.  
  5. if ( 'dir' === $data ) { 
  6. $retval = $attachments_dir; 
  7. } else { 
  8. $upload_data = bp_upload_dir(); 
  9.  
  10. // Return empty string, if Uploads data are not available. 
  11. if ( ! $upload_data ) { 
  12. return $retval; 
  13.  
  14. // Build the Upload data array for BuddyPress attachments. 
  15. foreach ( $upload_data as $key => $value ) { 
  16. if ( 'basedir' === $key || 'baseurl' === $key ) { 
  17. $upload_data[ $key ] = trailingslashit( $value ) . $attachments_dir; 
  18.  
  19. // Fix for HTTPS. 
  20. if ( 'baseurl' === $key && is_ssl() ) { 
  21. $upload_data[ $key ] = str_replace( 'http://', 'https://', $upload_data[ $key ] ); 
  22. } else { 
  23. unset( $upload_data[ $key ] ); 
  24.  
  25. // Add the dir to the array. 
  26. $upload_data['dir'] = $attachments_dir; 
  27.  
  28. if ( empty( $data ) ) { 
  29. $retval = $upload_data; 
  30. } elseif ( isset( $upload_data[ $data ] ) ) { 
  31. $retval = $upload_data[ $data ]; 
  32.  
  33. /** 
  34. * Filter here to edit the Attachments upload dir data. 
  35. * @since 2.4.0 
  36. * @param string|array $retval The needed Upload dir data or the full array of data 
  37. * @param string $data The data requested 
  38. */ 
  39. return apply_filters( 'bp_attachments_uploads_dir_get', $retval, $data );