/** * The constuctor * * @since 2.4.0 */ public function __construct() { // Allowed cover image types & upload size $allowed_types = bp_attachments_get_allowed_types('cover_image'); $max_upload_file_size = bp_attachments_get_max_upload_file_size('cover_image'); parent::__construct(array('action' => 'bp_cover_image_upload', 'file_input' => 'file', 'original_max_filesize' => $max_upload_file_size, 'base_dir' => bp_attachments_uploads_dir_get('dir'), 'required_wp_files' => array('file', 'image'), 'upload_error_strings' => array(11 => sprintf(__('That image is too big. Please upload one smaller than %s', 'buddypress'), size_format($max_upload_file_size)), 12 => sprintf(_n('Please upload only this file type: %s.', 'Please upload only these file types: %s.', count($allowed_types), 'buddypress'), self::get_cover_image_types($allowed_types))))); }
/** * Get allowed avatar types. * * @since 2.3.0 */ function bp_core_get_allowed_avatar_types() { $allowed_types = bp_attachments_get_allowed_types('avatar'); /** * Filters the list of allowed image types. * * @since 2.3.0 * * @param array $allowed_types List of image types. */ $avatar_types = (array) apply_filters('bp_core_get_allowed_avatar_types', $allowed_types); if (empty($avatar_types)) { $avatar_types = $allowed_types; } else { $avatar_types = array_intersect($allowed_types, $avatar_types); } return array_values($avatar_types); }
/** * Get allowed attachment mime types. * * @since 2.4.0 * * @param string $type The extension types to get (Optional). * @param array $allowed_types List of allowed extensions * @return array List of allowed mime types */ function bp_attachments_get_allowed_mimes($type = '', $allowed_types = array()) { if (empty($allowed_types)) { $allowed_types = bp_attachments_get_allowed_types($type); } $validate_mimes = wp_match_mime_types(join(',', $allowed_types), wp_get_mime_types()); $allowed_mimes = array_map('implode', $validate_mimes); /** * Include jpg type if jpeg is set */ if (isset($allowed_mimes['jpeg']) && !isset($allowed_mimes['jpg'])) { $allowed_mimes['jpg'] = $allowed_mimes['jpeg']; } return $allowed_mimes; }
/** * @group bp_attachments */ public function test_bp_attachments_get_allowed_types() { $supported = array('jpeg', 'gif', 'png'); $avatar = bp_attachments_get_allowed_types('avatar'); $this->assertSame($supported, $avatar); $cover_image = bp_attachments_get_allowed_types('cover_image'); $this->assertSame($supported, $cover_image); $images = bp_attachments_get_allowed_types('image/'); foreach ($images as $image) { if ('image' !== wp_ext2type($image)) { $not_image = $image; } } $this->assertTrue(empty($not_image)); }