bp_upload_dir()

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

Description

Handy for multisite instances because all uploads are made on the BP root blog and we need to query the BP root blog for the upload directory data.

This function ensures that we only need to use switch_to_blog() once to get what we need.

Return

(bool|array)

Source

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

3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
function bp_upload_dir() {
    $bp = buddypress();
 
    if ( empty( $bp->upload_dir ) ) {
        $need_switch = (bool) ( is_multisite() && ! bp_is_root_blog() );
 
        // Maybe juggle to root blog.
        if ( true === $need_switch ) {
            switch_to_blog( bp_get_root_blog_id() );
        }
 
        // Get the upload directory (maybe for root blog).
        $wp_upload_dir = wp_upload_dir();
 
        // Maybe juggle back to current blog.
        if ( true === $need_switch ) {
            restore_current_blog();
        }
 
        // Bail if an error occurred.
        if ( ! empty( $wp_upload_dir['error'] ) ) {
            return false;
        }
 
        $bp->upload_dir = $wp_upload_dir;
    }
 
    return $bp->upload_dir;
}

Changelog

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