bp_core_get_upload_dir( string $type = 'upload_path' )
Fetch data from the BP root blog’s upload directory.
Description
Parameters
- $type
-
(Optional) The variable we want to return from the $bp->avatars object. Only 'upload_path' and 'url' are supported. Default: 'upload_path'.
Default value: 'upload_path'
Return
(string) The avatar upload directory path.
Source
File: bp-core/bp-core-avatars.php
function bp_core_get_upload_dir( $type = 'upload_path' ) { $bp = buddypress(); switch ( $type ) { case 'upload_path' : $constant = 'BP_AVATAR_UPLOAD_PATH'; $key = 'basedir'; break; case 'url' : $constant = 'BP_AVATAR_URL'; $key = 'baseurl'; break; default : return false; break; } // See if the value has already been calculated and stashed in the $bp global. if ( isset( $bp->avatar->$type ) ) { $retval = $bp->avatar->$type; } else { // If this value has been set in a constant, just use that. if ( defined( $constant ) ) { $retval = constant( $constant ); } else { // Use cached upload dir data if available. if ( ! empty( $bp->avatar->upload_dir ) ) { $upload_dir = $bp->avatar->upload_dir; // No cache, so query for it. } else { // Get upload directory information from current site. $upload_dir = bp_upload_dir(); // Stash upload directory data for later use. $bp->avatar->upload_dir = $upload_dir; } // Directory does not exist and cannot be created. if ( ! empty( $upload_dir['error'] ) ) { $retval = ''; } else { $retval = $upload_dir[$key]; // If $key is 'baseurl', check to see if we're on SSL // Workaround for WP13941, WP15928, WP19037. if ( $key == 'baseurl' && is_ssl() ) { $retval = str_replace( 'http://', 'https://', $retval ); } } } // Stash in $bp for later use. $bp->avatar->$type = $retval; } return $retval; }
Changelog
Version | Description |
---|---|
BuddyPress 1.8.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.