get_compat_media_markup( int $attachment_id, array $args = null ): array
- Since
- 3.5.0
- Source
wp-admin/includes/media.php:1874
Compatibility
- WordPress
- since 3.5.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.
Parameters
$attachment_idint$argsarrayoptional- Default:
null
Return value
array
Performance profile
How much work a call to get_compat_media_markup() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 66–91
- Plugin surface
- 3 hooks
- Called by
- 2
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 355.
Third-party callbacks on 'get_media_item_args', 'attachment_fields_to_edit', 'media_meta' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below get_compat_media_markup()
Further down the call graph this can also reach option, 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 · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_compat_media_markup() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$args | 66–73 | get_post(), current_user_can(), wp_parse_args(), apply_filters(), array_merge_recursive(), apply_filters(), apply_filters() |
!$args | 73–80 | get_post(), current_user_can(), wp_parse_args(), apply_filters(), array_merge_recursive(), apply_filters(), apply_filters(), wp_required_field_message() |
!$args | 77–84 | get_post(), current_user_can(), wp_parse_args(), apply_filters(), array_merge_recursive(), apply_filters(), apply_filters(), esc_attr() |
!$args | 84–91 | get_post(), current_user_can(), wp_parse_args(), apply_filters(), array_merge_recursive(), apply_filters(), apply_filters(), wp_required_field_message(), esc_attr() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 355 | 66–91 | 46 | |
| 8.5 | 355 | 66–91 | 46 | |
| 8.4 | 355 | 66–91 | 46 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 361 | 66–91 | 46 | |
| 8.2 | 361 | 66–91 | 46 | |
| 8.1 | 361 | 66–91 | 46 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 362 | 66–91 | 46 |
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 · 3
3 hooks fire while get_compat_media_markup() runs, in this order:
- apply_filters( get_media_item_args )filterline 1887 (+13 into the body)
Filters the arguments used to retrieve an image for the edit image form.
- apply_filters( attachment_fields_to_edit )filterline 1935 (+61 into the body)
Filters the attachment fields to edit.
Uses · 12
- get_post()Retrieves post data given a post ID or post object.
- current_user_can()Returns whether the current user has the specified capability.
- wp_parse_args()Merges user defined arguments into defaults array.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_attachment_taxonomies()Retrieves taxonomies attached to given the attachment.
- get_taxonomy()Retrieves the taxonomy object of $taxonomy.
- get_object_term_cache()Retrieves the cached term objects for the given object ID.
- wp_get_object_terms()Retrieves the terms associated with the given object(s), in the supplied taxonomies.
- wp_required_field_indicator()Assigns a visual indicator for required form fields.
- user_can_richedit()Determines whether the user can access the visual editor.
- esc_attr()Escaping for HTML attributes.
- wp_required_field_message()Creates a message to explain required form fields.
Used by · 2
- edit_form_image_editor()Displays the image and editor in the post editor
- wp_prepare_attachment_for_js()Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model.
Source code
function get_compat_media_markup( $attachment_id, $args = null ) { $post = get_post( $attachment_id ); $default_args = array( 'errors' => null, 'in_modal' => false, ); $user_can_edit = current_user_can( 'edit_post', $attachment_id ); $args = wp_parse_args( $args, $default_args ); /** This filter is documented in wp-admin/includes/media.php */ $args = apply_filters( 'get_media_item_args', $args ); $form_fields = array(); if ( $args['in_modal'] ) { foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { $t = (array) get_taxonomy( $taxonomy ); if ( ! $t['public'] || ! $t['show_ui'] ) { continue; } if ( empty( $t['label'] ) ) { $t['label'] = $taxonomy; } if ( empty( $t['args'] ) ) { $t['args'] = array(); } $terms = get_object_term_cache( $post->ID, $taxonomy ); if ( false === $terms ) { $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); } $values = array(); foreach ( $terms as $term ) { $values[] = $term->slug; } $t['value'] = implode( ', ', $values ); $t['taxonomy'] = true; $form_fields[ $taxonomy ] = $t; } } /* * Merge default fields with their errors, so any key passed with the error * (e.g. 'error', 'helps', 'value') will replace the default. * The recursive merge is easily traversed with array casting: * foreach ( (array) $things as $thing ) */ $form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] ); /** This filter is documented in wp-admin/includes/media.php */ $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post ); unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'], $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'], $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] ); /** This filter is documented in wp-admin/includes/media.php */ $media_meta = apply_filters( 'media_meta', '', $post ); $defaults = array( 'input' => 'text',Changelog
Introduced in 3.5.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
array to array<string,.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-admin/includes/media.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.