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

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
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

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.