Skip to:
Content

BuddyPress.org

Changeset 8809


Ignore:
Timestamp:
08/12/2014 01:10:44 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Clean up xprofile_avatar_upload_dir():

  • Brackets
  • Inline documentation
  • Allow use of the $directory parameter (for a custom avatar path)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r8799 r8809  
    614614 * Setup the avatar upload directory for a user.
    615615 *
     616 * @since BuddyPress (1.0.0)
     617 *
    616618 * @package BuddyPress Core
     619 *
    617620 * @param string $directory The root directory name. Optional.
    618  * @param int $user_id The user ID. Optional.
    619  * @return array() containing the path and URL plus some other settings.
    620  */
    621 function xprofile_avatar_upload_dir( $directory = false, $user_id = 0 ) {
    622 
    623     if ( empty( $user_id ) )
     621 * @param int    $user_id   The user ID. Optional.
     622 *
     623 * @return array() Array containing the path, URL, and other helpful settings.
     624 */
     625function xprofile_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) {
     626
     627    // Use displayed user if no user ID was passed
     628    if ( empty( $user_id ) ) {
    624629        $user_id = bp_displayed_user_id();
    625 
    626     if ( empty( $directory ) )
     630    }
     631
     632    // Failsafe against accidentally nooped $directory parameter
     633    if ( empty( $directory ) ) {
    627634        $directory = 'avatars';
    628 
    629     $path    = bp_core_avatar_upload_path() . '/avatars/' . $user_id;
     635    }
     636
     637    $path    = bp_core_avatar_upload_path() . '/' . $directory. '/' . $user_id;
    630638    $newbdir = $path;
    631639
    632     if ( !file_exists( $path ) )
     640    if ( ! file_exists( $path ) ) {
    633641        @wp_mkdir_p( $path );
    634 
    635     $newurl    = bp_core_avatar_url() . '/avatars/' . $user_id;
     642    }
     643
     644    $newurl    = bp_core_avatar_url() . '/' . $directory. '/' . $user_id;
    636645    $newburl   = $newurl;
    637     $newsubdir = '/avatars/' . $user_id;
     646    $newsubdir = '/' . $directory. '/' . $user_id;
    638647
    639648    return apply_filters( 'xprofile_avatar_upload_dir', array(
Note: See TracChangeset for help on using the changeset viewer.