wppaste
WordPress

get_post_mime_types(): array

Since
2.9.0, 5.3.0
Source
wp-includes/post.php:3540
Gets default post mime types.

Compatibility

WordPress
since 5.3.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Return value

array
List of post mime types.

Performance profile

How much work a call to get_post_mime_types() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
101–102

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 134.

Plugin surface
1 hook

Third-party callbacks on 'post_mime_types' run inside this call, and their cost is not bounded by anything here.

Called by
4

4 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost get_post_mime_types() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always101–102__(), __(), _n_noop(), _x(), __(), _n_noop(), _x(), __(), _n_noop(), __(), __(), _n_noop(), __(), __(), _n_noop(), _x(), __(), _n_noop(), wp_get_ext_types(), wp_get_mime_types(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev134101–1029
8.5134101–1029
8.4134101–10296 fewer instructions than PHP 8.3
8.3140101–1029
8.2140101–1029
8.1140101–1029
7.4140101–1029

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while get_post_mime_types() runs, in this order:

  1. apply_filters( post_mime_types )filterline 3633 (+93 into the body)

    Filters the default list of post mime types.

Uses · 6

  • __()Retrieves the translation of $text.
  • _n_noop()Registers plural strings in POT file, but does not translate them.
  • _x()Retrieves translated string with gettext context.
  • wp_get_ext_types()Retrieves the list of common file extensions and their types.
  • wp_get_mime_types()Retrieves the list of mime types and file extensions.
  • apply_filters()Calls the callback functions that have been added to a filter hook.

Used by · 4

Source code

function get_post_mime_types() {	$post_mime_types = array(   // array( adj, noun )		'image'       => array(			__( 'Images' ),			__( 'Manage Images' ),			/* translators: %s: Number of images. */			_n_noop(				'Image <span class="count">(%s)</span>',				'Images <span class="count">(%s)</span>'			),		),		'audio'       => array(			_x( 'Audio', 'file type group' ),			__( 'Manage Audio' ),			/* translators: %s: Number of audio files. */			_n_noop(				'Audio <span class="count">(%s)</span>',				'Audio <span class="count">(%s)</span>'			),		),		'video'       => array(			_x( 'Video', 'file type group' ),			__( 'Manage Video' ),			/* translators: %s: Number of video files. */			_n_noop(				'Video <span class="count">(%s)</span>',				'Video <span class="count">(%s)</span>'			),		),		'document'    => array(			__( 'Documents' ),			__( 'Manage Documents' ),			/* translators: %s: Number of documents. */			_n_noop(				'Document <span class="count">(%s)</span>',				'Documents <span class="count">(%s)</span>'			),		),		'spreadsheet' => array(			__( 'Spreadsheets' ),			__( 'Manage Spreadsheets' ),			/* translators: %s: Number of spreadsheets. */			_n_noop(				'Spreadsheet <span class="count">(%s)</span>',				'Spreadsheets <span class="count">(%s)</span>'			),		),		'archive'     => array(			_x( 'Archives', 'file type group' ),			__( 'Manage Archives' ),			/* translators: %s: Number of archives. */			_n_noop(				'Archive <span class="count">(%s)</span>',				'Archives <span class="count">(%s)</span>'			),		),	); 	$ext_types  = wp_get_ext_types();	$mime_types = wp_get_mime_types(); 	foreach ( $post_mime_types as $group => $labels ) {		if ( in_array( $group, array( 'image', 'audio', 'video' ), true ) ) {			continue;		} 		if ( ! isset( $ext_types[ $group ] ) ) {			unset( $post_mime_types[ $group ] );			continue;		} 		$group_mime_types = array();		foreach ( $ext_types[ $group ] as $extension ) {			foreach ( $mime_types as $exts => $mime ) {				if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) {					$group_mime_types[] = $mime;					break;				}			}		}

Changelog

Introduced in 2.9.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.3.0
Added the 'Documents', 'Spreadsheets', and 'Archives' mime type groups.from the docblock
2.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.