bp_attachments_get_allowed_types

Get allowed types for any attachment.

Description

(array) bp_attachments_get_allowed_types( (string) $type = 'avatar' ); 

Returns (array)

The list of allowed extensions for attachments.

Parameters (1)

0. $type — Optional. (string) => 'avatar'
The extension types to get. Default: avatar..

Usage

  1. if ( !function_exists( 'bp_attachments_get_allowed_types' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-attachments.php'; 
  3.  
  4. // The extension types to get. 
  5. // Default: 'avatar'. 
  6. $type = 'avatar'; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_attachments_get_allowed_types($type); 
  10.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-attachments.php  
  1. function bp_attachments_get_allowed_types( $type = 'avatar' ) { 
  2. // Defaults to BuddyPress supported image extensions. 
  3. $exts = array( 'jpeg', 'gif', 'png' ); 
  4.  
  5. /** 
  6. * It's not a BuddyPress feature, get the allowed extensions 
  7. * matching the $type requested. 
  8. */ 
  9. if ( 'avatar' !== $type && 'cover_image' !== $type ) { 
  10. // Reset the default exts. 
  11. $exts = array(); 
  12.  
  13. switch ( $type ) { 
  14. case 'video' : 
  15. $exts = wp_get_video_extensions(); 
  16. break; 
  17.  
  18. case 'audio' : 
  19. $exts = wp_get_video_extensions(); 
  20. break; 
  21.  
  22. default: 
  23. $allowed_mimes = get_allowed_mime_types(); 
  24.  
  25. /** 
  26. * Search for allowed mimes matching the type. 
  27. * Eg: using 'application/vnd.oasis' as the $type 
  28. * parameter will get all OpenOffice extensions supported 
  29. * by WordPress and allowed for the current user. 
  30. */ 
  31. if ( '' !== $type ) { 
  32. $allowed_mimes = preg_grep( '/' . addcslashes( $type, '/.+-' ) . '/', $allowed_mimes ); 
  33.  
  34. $allowed_types = array_keys( $allowed_mimes ); 
  35.  
  36. // Loop to explode keys using '|'. 
  37. foreach ( $allowed_types as $allowed_type ) { 
  38. $t = explode( '|', $allowed_type ); 
  39. $exts = array_merge( $exts, (array) $t ); 
  40. break; 
  41.  
  42. /** 
  43. * Filter here to edit the allowed extensions by attachment type. 
  44. * @since 2.4.0 
  45. * @param array $exts List of allowed extensions. 
  46. * @param string $type The requested file type. 
  47. */