/** * Get allowed avatar mime types. * * @since 2.3.0 */ function bp_core_get_allowed_avatar_mimes() { $allowed_types = bp_core_get_allowed_avatar_types(); return bp_attachments_get_allowed_mimes('avatar', $allowed_types); }
/** * @group bp_core_check_avatar_type * @group bp_core_get_allowed_avatar_types */ public function test_bp_core_get_allowed_avatar_types_filter() { add_filter('bp_core_get_allowed_avatar_types', array($this, 'avatar_types_filter_add_type')); $this->assertEquals(array('jpeg', 'gif', 'png'), bp_core_get_allowed_avatar_types()); remove_filter('bp_core_get_allowed_avatar_types', array($this, 'avatar_types_filter_add_type')); add_filter('bp_core_get_allowed_avatar_types', array($this, 'avatar_types_filter_remove_type')); $this->assertEquals(array('gif', 'png'), bp_core_get_allowed_avatar_types()); remove_filter('bp_core_get_allowed_avatar_types', array($this, 'avatar_types_filter_remove_type')); add_filter('bp_core_get_allowed_avatar_types', '__return_empty_array'); $this->assertEquals(array('jpeg', 'gif', 'png'), bp_core_get_allowed_avatar_types()); remove_filter('bp_core_get_allowed_avatar_types', '__return_empty_array'); }
/** * Construct Upload parameters. * * @since 2.3.0 * * @see BP_Attachment::__construct() for list of parameters * @uses bp_core_avatar_original_max_filesize() * @uses BP_Attachment::__construct() */ public function __construct() { // Allowed avatar types. $allowed_types = bp_core_get_allowed_avatar_types(); parent::__construct(array('action' => 'bp_avatar_upload', 'file_input' => 'file', 'original_max_filesize' => bp_core_avatar_original_max_filesize(), 'upload_error_strings' => array(9 => sprintf(__('That photo is too big. Please upload one smaller than %s', 'buddypress'), size_format(bp_core_avatar_original_max_filesize())), 10 => sprintf(_n('Please upload only this file type: %s.', 'Please upload only these file types: %s.', count($allowed_types), 'buddypress'), self::get_avatar_types($allowed_types))))); }
/** * Get allowed avatar mime types * * @since BuddyPress (2.3.0) */ function bp_core_get_allowed_avatar_mimes() { $allowed_types = bp_core_get_allowed_avatar_types(); $validate_mimes = wp_match_mime_types(join(',', $allowed_types), wp_get_mime_types()); $allowed_mimes = array_map('implode', $validate_mimes); /** * Include jpg type if needed so that bp_core_check_avatar_type() * will check for jpeg and jpg extensions. */ if (isset($allowed_mimes['jpeg'])) { $allowed_mimes['jpg'] = $allowed_mimes['jpeg']; } return $allowed_mimes; }