Skip to content

Only the first allowed mime type is in use in filter upload_mimes #77

Open
@kkarpieszuk

Description

@kkarpieszuk

Steps:

  1. add some allowed file type but define it with comma separated mime types when the first one is for sure not correct (for example for XML file add foo/bar,text/xml mime types
  2. try to upload this file

It will be not uploaded because in the FileUploadTypes\Plugin::allowed_types we are removing other mime types and are using only the first one.

This should be rewritten to something like:

	public function allowed_types( $mime_types ): array {

		$mime_types = (array) $mime_types;

		$enabled_types = $this->enabled_types();

		foreach( $enabled_types as $ext => $mime ) {
			if ( is_array( $mime ) ) {
				$i = 1;

				foreach ($mime as $m) {

					if ( $i === 1 ) {
						$enabled_types[$ext] = $m;
						continue;
					}

					$enabled_types[$ext . '_' . $i] = $m;
					$i++;
				}
			}
		}

		return array_replace( $mime_types, $enabled_types );
	}

The risk of this change is high, so it can not be added without caution

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions