/** * Retrieve the file type based on the extension name. * * @since 2.5.0 * * @param string $ext The extension to search. * @return string|void The file type, example: audio, video, document, spreadsheet, etc. */ function wp_ext2type($ext) { $ext = strtolower($ext); $ext2type = wp_get_ext_types(); foreach ($ext2type as $type => $exts) { if (in_array($ext, $exts)) { return $type; } } }
/** * @ticket 35987 */ public function test_wp_ext2type() { $extensions = wp_get_ext_types(); foreach ($extensions as $type => $extensionList) { foreach ($extensionList as $extension) { $this->assertEquals($type, wp_ext2type($extension)); $this->assertEquals($type, wp_ext2type(strtoupper($extension))); } } $this->assertNull(wp_ext2type('unknown_format')); }