bp_attachments_get_allowed_types( string $type = 'avatar' )
Get allowed types for any attachment.
Description
Parameters
- $type
-
(Optional) The extension types to get. Default: 'avatar'.
Default value: 'avatar'
Return
(array) The list of allowed extensions for attachments.
Source
File: bp-core/bp-core-attachments.php
function bp_attachments_get_allowed_types( $type = 'avatar' ) { // Defaults to BuddyPress supported image extensions. $exts = array( 'jpeg', 'gif', 'png' ); /** * It's not a BuddyPress feature, get the allowed extensions * matching the $type requested. */ if ( 'avatar' !== $type && 'cover_image' !== $type ) { // Reset the default exts. $exts = array(); switch ( $type ) { case 'video' : $exts = wp_get_video_extensions(); break; case 'audio' : $exts = wp_get_video_extensions(); break; default: $allowed_mimes = get_allowed_mime_types(); /** * Search for allowed mimes matching the type. * * Eg: using 'application/vnd.oasis' as the $type * parameter will get all OpenOffice extensions supported * by WordPress and allowed for the current user. */ if ( '' !== $type ) { $allowed_mimes = preg_grep( '/' . addcslashes( $type, '/.+-' ) . '/', $allowed_mimes ); } $allowed_types = array_keys( $allowed_mimes ); // Loop to explode keys using '|'. foreach ( $allowed_types as $allowed_type ) { $t = explode( '|', $allowed_type ); $exts = array_merge( $exts, (array) $t ); } break; } } /** * Filter here to edit the allowed extensions by attachment type. * * @since BuddyPress 2.4.0 * * @param array $exts List of allowed extensions. * @param string $type The requested file type. */ return apply_filters( 'bp_attachments_get_allowed_types', $exts, $type ); }
Changelog
Version | Description |
---|---|
BuddyPress 2.4.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.