WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#36294 closed enhancement (duplicate)

Allow retrieval of WordPress media types and their extensions

Reported by: flixos90 Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5
Component: Media Keywords: has-patch
Focuses: Cc:
PR Number:

Description

There have been a couple of occasions where I needed to access the list of media types and their file extensions that WordPress bundles. Unfortunately this list is only generated within the function wp_ext2type() and cannot be accessed from the outside.

A use-case is when I wanted to create a file upload field in a form builder plugin, I would like the admin to be able to select the required file type, and for that I would like to use the list from that function. Then I could check for the extensions / their MIME types whenever an upload through that field would happen.

I would propose to introduce a separate function that returns this list of media types and their file extensions. This function could then be called in wp_ext2type().

Attachments (1)

36294.diff (3.2 KB) - added by flixos90 4 years ago.
Introduce wp_get_type_extensions() and a corresponding filter

Download all attachments as: .zip

Change History (5)

@flixos90
4 years ago

Introduce wp_get_type_extensions() and a corresponding filter

#1 @flixos90
4 years ago

  • Keywords has-patch dev-feedback added

36294.diff introduces a new function wp_get_type_extensions() that returns the list and calls that function from wp_ext2type().

I also included a new filter to adjust this list. At first I wondered whether we should move the original filter ext2type into the new function, but I felt this would not be appropriate in terms of naming conventions. ext2type would now only adjust the types for the wp_ext2type() function while the filter wp_type_extensions would be applied globally.

#2 @flixos90
4 years ago

  • Keywords close added; dev-feedback removed
  • Resolution set to duplicate
  • Status changed from new to closed

This can be closed as it's partly a duplicate of #35987 and was fixed in 37189.

This ticket was mentioned in Slack in #core by flixos90. View the logs.


4 years ago

#4 @swissspidy
4 years ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.