bp_core_get_upload_dir( string $type = 'upload_path' )

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


Description Description


Parameters 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'


Top ↑

Return Return

(string) The avatar upload directory path.


Top ↑

Source 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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.