Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/29/2015 09:43:13 PM (10 years ago)
Author:
imath
Message:

Introduce new functions to the BuddyPress Attachments API

The first benefit of the BuddyPress Cover Images feature is the improvement of the BuddyPress Attachments API. We are introducing new functions to deal with file management. Some of these functions come from functions previously restricted to avatars.

  • is there to get the new attachments features Uploads directory. New Attachments features will now store their files within the directory. Inside this directory we will have subdirectories to organize files according to the object they belong to (eg: members, groups), to the item ID they are attached to and eventually to the BuddyPress attachment type. For the cover image of a user it is looking like
  • , , , are inspired by functions restricted to avatars so far. They will help us to control max upload size, allowed types and mimes for any attachments. The last function will help us to check the uploaded file match the allowed types. Corresponding Avatar functions are now using these new functions.
  • and are there to respectively get the path or the url of any attachment using the new Uploads directory organization (avatars and group-avatars are not concerned so far) and to delete an attachment.

See #6570

File:
1 edited

Legend:

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

    r10135 r10151  
    3333
    3434    if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
    35 
    36         $fileupload_maxk = bp_core_get_root_option( 'fileupload_maxk' );
    37         if ( '' === $fileupload_maxk ) {
    38             define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb
    39         } else {
    40             define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $fileupload_maxk * 1024 );
    41         }
     35        define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', bp_attachments_get_max_upload_file_size( 'avatar' ) );
    4236    }
    4337
     
    13711365 */
    13721366function bp_core_get_allowed_avatar_types() {
    1373     $allowed_types = array( 'jpeg', 'gif', 'png' );
     1367    $allowed_types = bp_attachments_get_allowed_types( 'avatar' );
    13741368
    13751369    /**
     
    13981392function bp_core_get_allowed_avatar_mimes() {
    13991393    $allowed_types  = bp_core_get_allowed_avatar_types();
    1400     $validate_mimes = wp_match_mime_types( join( ',', $allowed_types ), wp_get_mime_types() );
    1401     $allowed_mimes  = array_map( 'implode', $validate_mimes );
    1402 
    1403     /**
    1404      * Include jpg type if needed so that bp_core_check_avatar_type()
    1405      * will check for jpeg and jpg extensions.
    1406      */
    1407     if ( isset( $allowed_mimes['jpeg'] ) ) {
    1408         $allowed_mimes['jpg'] = $allowed_mimes['jpeg'];
    1409     }
    1410 
    1411     return $allowed_mimes;
     1394
     1395    return bp_attachments_get_allowed_mimes( 'avatar', $allowed_types );
    14121396}
    14131397
     
    14221406 */
    14231407function bp_core_check_avatar_type( $file ) {
    1424     $avatar_filetype = wp_check_filetype_and_ext( $file['file']['tmp_name'], $file['file']['name'], bp_core_get_allowed_avatar_mimes() );
    1425 
    1426     if ( ! empty( $avatar_filetype['ext'] ) && ! empty( $avatar_filetype['type'] ) ) {
    1427         return true;
    1428     }
    1429 
    1430     return false;
     1408    return bp_attachments_check_filetype( $file['file']['tmp_name'], $file['file']['name'], bp_core_get_allowed_avatar_mimes() );
    14311409}
    14321410
Note: See TracChangeset for help on using the changeset viewer.