Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/02/2009 07:54:19 PM (16 years ago)
Author:
apeatling
Message:

Added avatar delete to user and group screens. Fixes #411

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-avatars.php

    r1714 r1760  
    140140        'item_id' => false,
    141141        'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
    142         'avatar_path' => false
     142        'avatar_dir' => false
    143143    );
    144144
    145     $r = wp_parse_args( $args, $defaults );
    146     extract( $r, EXTR_SKIP );   
    147    
    148     if ( !$avatar_path )
    149         return false;
     145    $args = wp_parse_args( $args, $defaults );
     146    extract( $args, EXTR_SKIP );   
     147   
     148    if ( !$item_id ) {
     149        if ( 'user' == $object )
     150            $item_id = $bp->displayed_user->id;
     151        else if ( 'group' == $object )
     152            $item_id = $bp->groups->current_group->id;
     153        else if ( 'blog' == $object )
     154            $item_id = $current_blog->id;
     155           
     156        $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
     157   
     158        if ( !$item_id ) return false;
     159    }
     160       
     161    if ( !$avatar_dir ) {
     162        if ( 'user' == $object )
     163            $avatar_dir = 'avatars';
     164        else if ( 'group' == $object )
     165            $avatar_dir = 'group-avatars';
     166        else if ( 'blog' == $object )
     167            $avatar_dir = 'blog-avatars';
     168           
     169        $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
     170       
     171        if ( !$avatar_dir ) return false;       
     172    }
    150173
    151174    if ( 'user' == $object ) {
     
    157180    }
    158181
    159     if ( $av_dir = opendir( $avatar_path ) ) {
     182    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );   
     183
     184    if ( !file_exists( $avatar_folder_dir ) )
     185        return false;
     186
     187    if ( $av_dir = opendir( $avatar_folder_dir ) ) {
    160188        while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
    161189            if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
    162                 @unlink( $avatar_path . '/' . $avatar_file );
     190                @unlink( $avatar_folder_dir . '/' . $avatar_file );             
    163191        }
    164192    }
    165193    closedir($av_dir);
     194
     195    @rmdir( $avatar_folder_dir );
     196
     197    do_action( 'bp_core_delete_existing_avatar', $args );
     198
     199    return true;
    166200}
    167201
Note: See TracChangeset for help on using the changeset viewer.