get_attachment_fields_to_edit( WP_Post $post, array $errors = null ): array
- Since
- 2.5.0
- Source
wp-admin/includes/media.php:1385
Compatibility
- WordPress
- since 2.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
$postWP_Post$errorsarrayoptional- Default:
null
Return value
array
Performance profile
How much work a call to get_attachment_fields_to_edit() 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
- 117–177
- Plugin surface
- 1 hook
- Called by
- 1
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 228.
Third-party callbacks on 'attachment_fields_to_edit' run inside this call, and their cost is not bounded by anything here.
1 place 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 - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below get_attachment_fields_to_edit() - serializeserialisation
maybe_unserialize()one call below get_attachment_fields_to_edit()
Further down the call graph this can also reach transient. That is 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_attachment_fields_to_edit() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_int($post) | 117–123 | wp_get_attachment_url(), sanitize_post(), __(), __(), wp_caption_input_textarea(), __(), __(), get_option(), image_link_input_fields(), __(), __(), __(), esc_attr(), wp_get_attachment_url(), __(), get_attachment_taxonomies(), array_merge_recursive(), apply_filters() |
is_int($post) | 121–127 | get_post(), wp_get_attachment_url(), sanitize_post(), __(), __(), wp_caption_input_textarea(), __(), __(), get_option(), image_link_input_fields(), __(), __(), __(), esc_attr(), wp_get_attachment_url(), __(), get_attachment_taxonomies(), array_merge_recursive(), apply_filters() |
!is_int($post) | 166–173 | wp_get_attachment_url(), sanitize_post(), __(), __(), wp_caption_input_textarea(), __(), __(), get_option(), image_link_input_fields(), __(), __(), __(), esc_attr(), wp_get_attachment_url(), __(), get_attachment_taxonomies(), array_merge_recursive(), get_post_meta(), __(), __(), __(), get_option(), image_align_input_fields(), get_option(), image_size_input_fields(), apply_filters() |
is_int($post) | 170–177 | get_post(), wp_get_attachment_url(), sanitize_post(), __(), __(), wp_caption_input_textarea(), __(), __(), get_option(), image_link_input_fields(), __(), __(), __(), esc_attr(), wp_get_attachment_url(), __(), get_attachment_taxonomies(), array_merge_recursive(), get_post_meta(), __(), __(), __(), get_option(), image_align_input_fields(), get_option(), image_size_input_fields(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 228 | 117–177 | 13 | |
| 8.5 | 228 | 117–177 | 13 | |
| 8.4 | 228 | 117–177 | 13 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 234 | 120–180 | 13 | |
| 8.2 | 234 | 120–180 | 13 | |
| 8.1 | 234 | 120–180 | 13 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 235 | 121–181 | 13 |
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_attachment_fields_to_edit() runs, in this order:
- apply_filters( attachment_fields_to_edit )filterline 1509 (+124 into the body)
Filters the attachment fields to edit.
Uses · 18
- get_post()Retrieves post data given a post ID or post object.
- wp_get_attachment_url()Retrieves the URL for an attachment.
- sanitize_post()Sanitizes every post field.
- __()Retrieves the translation of $text.
- wp_caption_input_textarea()Outputs a textarea element for inputting an attachment caption.
- image_link_input_fields()Retrieves HTML for the Link URL buttons with the default link type as specified.
- get_option()Retrieves an option value based on an option name.
- esc_attr()Escaping for HTML attributes.
- 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.
Show all 18
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- get_post_meta()Retrieves a post meta field for the given post ID.
- image_align_input_fields()Retrieves HTML for the image alignment radio buttons with the specified one checked.
- image_size_input_fields()Retrieves HTML for the size radio buttons with the specified one checked.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Post::__construct()Constructor.
Used by · 1
- get_media_item()Retrieves HTML form for modifying the image attachment.
Source code
function get_attachment_fields_to_edit( $post, $errors = null ) { if ( is_int( $post ) ) { $post = get_post( $post ); } if ( is_array( $post ) ) { $post = new WP_Post( (object) $post ); } $image_url = wp_get_attachment_url( $post->ID ); $edit_post = sanitize_post( $post, 'edit' ); $form_fields = array( 'post_title' => array( 'label' => __( 'Title' ), 'value' => $edit_post->post_title, ), 'image_alt' => array(), 'post_excerpt' => array( 'label' => __( 'Caption' ), 'input' => 'html', 'html' => wp_caption_input_textarea( $edit_post ), ), 'post_content' => array( 'label' => __( 'Description' ), 'value' => $edit_post->post_content, 'input' => 'textarea', ), 'url' => array( 'label' => __( 'Link URL' ), 'input' => 'html', 'html' => image_link_input_fields( $post, get_option( 'image_default_link_type' ) ), 'helps' => __( 'Enter a link URL or click above for presets.' ), ), 'menu_order' => array( 'label' => __( 'Order' ), 'value' => $edit_post->menu_order, ), 'image_url' => array( 'label' => __( 'File URL' ), 'input' => 'html', 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr( $image_url ) . "' /><br />", 'value' => wp_get_attachment_url( $post->ID ), 'helps' => __( 'Location of the uploaded file.' ), ), ); 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 ); $form_fields[ $taxonomy ] = $t; }Changelog
Introduced in 2.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.8.8 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.