示例#1
0
 /**
  * @group bp_core_check_avatar_type
  * @group bp_core_get_allowed_avatar_mimes
  */
 public function test_bp_core_get_allowed_avatar_mimes()
 {
     $mimes = bp_core_get_allowed_avatar_mimes();
     $this->assertEquals(array('jpeg', 'gif', 'png', 'jpg'), array_keys($mimes));
     $this->assertEquals(array('image/jpeg', 'image/gif', 'image/png', 'image/jpeg'), array_values($mimes));
     add_filter('bp_core_get_allowed_avatar_types', array($this, 'avatar_types_filter_add_type'));
     $this->assertEquals(array('image/jpeg', 'image/gif', 'image/png', 'image/jpeg'), array_values(bp_core_get_allowed_avatar_mimes()));
     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('image/gif', 'image/png'), array_values(bp_core_get_allowed_avatar_mimes()));
     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('image/jpeg', 'image/gif', 'image/png', 'image/jpeg'), array_values(bp_core_get_allowed_avatar_mimes()));
     remove_filter('bp_core_get_allowed_avatar_types', '__return_empty_array');
 }
示例#2
0
/**
 * Does the current avatar upload have an allowed file type?
 *
 * Permitted file types are JPG, GIF and PNG.
 *
 * @param array $file The $_FILES array.
 *
 * @return bool True if the file extension is permitted, otherwise false.
 */
function bp_core_check_avatar_type($file)
{
    return bp_attachments_check_filetype($file['file']['tmp_name'], $file['file']['name'], bp_core_get_allowed_avatar_mimes());
}
示例#3
0
/**
 * Does the current avatar upload have an allowed file type?
 *
 * Permitted file types are JPG, GIF and PNG.
 *
 * @param array $file The $_FILES array.
 * @return bool True if the file extension is permitted, otherwise false.
 */
function bp_core_check_avatar_type($file)
{
    $avatar_filetype = wp_check_filetype_and_ext($file['file']['tmp_name'], $file['file']['name'], bp_core_get_allowed_avatar_mimes());
    if (!empty($avatar_filetype['ext']) && !empty($avatar_filetype['type'])) {
        return true;
    }
    return false;
}