xprofile_avatar_upload_dir( string $directory = 'avatars', int $user_id )

Setup the avatar upload directory for a user.

Description

Parameters

$directory

(string) (Optional) The root directory name. Optional.

Default value: 'avatars'

$user_id

(int) (Required) The user ID. Optional.

Return

(array) Array containing the path, URL, and other helpful settings.

Source

File: bp-xprofile/bp-xprofile-functions.php

function xprofile_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) {

	// Use displayed user if no user ID was passed.
	if ( empty( $user_id ) ) {
		$user_id = bp_displayed_user_id();
	}

	// Failsafe against accidentally nooped $directory parameter.
	if ( empty( $directory ) ) {
		$directory = 'avatars';
	}

	$path      = bp_core_avatar_upload_path() . '/' . $directory. '/' . $user_id;
	$newbdir   = $path;
	$newurl    = bp_core_avatar_url() . '/' . $directory. '/' . $user_id;
	$newburl   = $newurl;
	$newsubdir = '/' . $directory. '/' . $user_id;

	/**
	 * Filters the avatar upload directory for a user.
	 *
	 * @since BuddyPress 1.1.0
	 *
	 * @param array $value Array containing the path, URL, and other helpful settings.
	 */
	return apply_filters( 'xprofile_avatar_upload_dir', array(
		'path'    => $path,
		'url'     => $newurl,
		'subdir'  => $newsubdir,
		'basedir' => $newbdir,
		'baseurl' => $newburl,
		'error'   => false
	) );
}

Changelog

Changelog
Version Description
BuddyPress 1.0.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.