wppaste
WordPress

wp_prepare_attachment_for_js( int|WP_Post $attachment ): array|null

Since
3.5.0
Source
wp-includes/media.php:4648
Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model.

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

$attachmentint|WP_Post
Attachment ID or object.

Return value

array|null
Array of attachment details, or null if the parameter does not correspond to an attachment.
  • $altstring

    Alt text of the attachment.
  • $authorstring

    ID of the attachment author, as a string.
  • $authorNamestring

    Name of the attachment author.
  • $captionstring

    Caption for the attachment.
  • $compatarray

    Containing item and meta.
  • $contextstring

    Context, whether it's used as the site icon for example.
  • $dateint

    Uploaded date, timestamp in milliseconds.
  • $dateFormattedstring

    Formatted date (e.g. June 29, 2018).
  • $descriptionstring

    Description of the attachment.
  • $editLinkstring

    URL to the edit page for the attachment.
  • $filenamestring

    File name of the attachment.
  • $filesizeHumanReadablestring

    Filesize of the attachment in human readable format (e.g. 1 MB).
  • $filesizeInBytesint

    Filesize of the attachment in bytes.
  • $heightint

    If the attachment is an image, represents the height of the image in pixels.
  • $iconstring

    Icon URL of the attachment (e.g. /wp-includes/images/media/archive.png).
  • $idint

    ID of the attachment.
  • $linkstring

    URL to the attachment.
  • $menuOrderint

    Menu order of the attachment post.
  • $metaarray

    Meta data for the attachment.
  • $mimestring

    Mime type of the attachment (e.g. image/jpeg or application/zip).
  • $modifiedint

    Last modified, timestamp in milliseconds.
  • $namestring

    Name, same as title of the attachment.
  • $noncesarray

    Nonces for update, delete and edit.
  • $orientationstring

    If the attachment is an image, represents the image orientation (landscape or portrait).
  • $sizesarray

    If the attachment is an image, contains an array of arrays for the images sizes: thumbnail, medium, large, and full.
  • $statusstring

    Post status of the attachment (usually 'inherit').
  • $subtypestring

    Mime subtype of the attachment (usually the last part, e.g. jpeg or zip).
  • $titlestring

    Title of the attachment (usually slugified file name without the extension).
  • $typestring

    Type of the attachment (usually first part of the mime type, e.g. image).
  • $uploadedToint

    Parent post to which the attachment was uploaded.
  • $uploadedToLinkstring

    URL to the edit page of the parent post of the attachment.
  • $uploadedToTitlestring

    Post title of the parent of the attachment.
  • $urlstring

    Direct URL to the attachment file (from wp-content).
  • $widthint

    If the attachment is an image, represents the width of the image in pixels.

Performance profile

How much work a call to wp_prepare_attachment_for_js() 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

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
190–325

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

Plugin surface
3 hooks

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

Called by
7

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

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below wp_prepare_attachment_for_js()
  • cacheobject cachewp_cache_get()one call below wp_prepare_attachment_for_js()

Further down the call graph this can also reach 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 · 48 distinct outcomes

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

WhenInstructionsCalls it makes
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && !function_exists()190get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can()196–199get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can()198get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && function_exists()204–207get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !function_exists()230–241get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value)236–250get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value)238–249get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && function_exists()244–258get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && !is_array($response_image_thumb) && !function_exists()267–274get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && !is_array($response_image_thumb)273–283get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && !is_array($response_image_thumb)275–282get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && empty($id) && !function_exists()276–283get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_mime_type_icon(), compact(), compact(), function_exists(), function_exists(), apply_filters()
36 further outcomes, up to 325 instructions
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && !is_array($response_image_thumb) && !function_exists()277–284get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && !is_array($response_image_thumb) && !function_exists()279–286get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && is_array($response_image_thumb) && !function_exists()280–287get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && !is_array($response_image_thumb) && function_exists()281–291get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && empty($id)282–292get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_mime_type_icon(), compact(), compact(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && !is_array($response_image_thumb)283–293get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && empty($id)284–291get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_mime_type_icon(), compact(), compact(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && !is_array($response_image_thumb)285–295get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && !is_array($response_image_thumb)285–292get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && is_array($response_image_thumb)286–296get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && empty($id) && !function_exists()286–293get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_mime_type_icon(), compact(), compact(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && !is_array($response_image_thumb)287–294get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && is_array($response_image_thumb)288–295get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && !is_array($response_image_thumb) && !function_exists()289–295get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && is_array($response_image_thumb) && !function_exists()290–297get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && empty($id) && function_exists()290–300get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_mime_type_icon(), compact(), compact(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && !is_array($response_image_thumb) && function_exists()291–301get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && is_array($response_image_thumb) && !function_exists()292–299get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && empty($id)292–302get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_mime_type_icon(), compact(), compact(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && !is_array($response_image_thumb) && function_exists()293–303get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && is_array($response_image_thumb) && function_exists()294–304get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && empty($id)294–301get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_mime_type_icon(), compact(), compact(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && !is_array($response_image_thumb)295–304get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && is_array($response_image_thumb)296–305get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && !is_array($response_image_thumb)297–303get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && is_array($response_image_thumb)298–308get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && is_array($response_image_thumb)298–304get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && is_array($response_image_thumb)300–307get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && empty($id) && function_exists()300–310get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_mime_type_icon(), compact(), compact(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && is_array($response_image_thumb) && !function_exists()302–308get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), function_exists(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && !is_array($response_image_thumb) && function_exists()303–312get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && !is_array($response_image_full) && is_array($response_image_thumb) && function_exists()304–313get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !isset($meta) && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && is_array($response_image_thumb) && function_exists()306–316get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && is_array($response_image_thumb)308–317get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), function_exists(), get_media_states(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && is_array($response_image_thumb)310–316get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), get_compat_media_markup(), function_exists(), apply_filters()
!->exists() && !$attachment && !is_string($attached_file) && !current_user_can() && empty($value) && !empty($id) && is_array($response_image_full) && is_array($response_image_thumb) && function_exists()316–325get_post(), wp_get_attachment_metadata(), wp_get_attachment_url(), wp_basename(), get_attached_file(), wp_basename(), esc_url_raw(), get_attachment_link(), get_post_meta(), strtotime(), strtotime(), wp_mime_type_icon(), __(), mysql2date(), id(), ->exists(), __(), get_attached_file(), get_post_meta(), current_user_can(), current_user_can(), __(), __(), __(), __(), thumbnail(), sizes(), human_readable_duration(), wp_get_attachment_id3_keys(), get_post_thumbnail_id(), wp_get_attachment_image_src(), esc_url_raw(), wp_get_attachment_image_src(), esc_url_raw(), function_exists(), get_compat_media_markup(), function_exists(), get_media_states(), apply_filters()

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

PHPCompiledExecutedBranchesNotes
8.6-dev673190–325562 fewer instructions than PHP 8.5
8.5675190–32556
8.4675190–3255611 fewer instructions than PHP 8.3
8.3686196–33456
8.2686196–33456
8.1686196–334564 fewer instructions than PHP 7.4
7.4690197–33556

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 wp_prepare_attachment_for_js() runs, in this order:

  1. apply_filters( image_size_names_choose )filterline 4749 (+101 into the body)

    Filters the names and labels of the default image sizes.

  2. apply_filters( image_downsize )filterline 4769 (+121 into the body)

    Filters whether to preempt the output of image_downsize().

  3. apply_filters( wp_prepare_attachment_for_js )filterline 4904 (+256 into the body)

    Filters the attachment data prepared for JavaScript.

Uses · 30

Show all 30

Used by · 7

Source code

function wp_prepare_attachment_for_js( $attachment ) {	$attachment = get_post( $attachment ); 	if ( ! $attachment ) {		return null;	} 	if ( 'attachment' !== $attachment->post_type ) {		return null;	} 	$meta = wp_get_attachment_metadata( $attachment->ID );	if ( str_contains( $attachment->post_mime_type, '/' ) ) {		list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );	} else {		list( $type, $subtype ) = array( $attachment->post_mime_type, '' );	} 	$attachment_url = wp_get_attachment_url( $attachment->ID );	$base_url       = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); 	$response = array(		'id'            => $attachment->ID,		'title'         => $attachment->post_title,		'filename'      => wp_basename( get_attached_file( $attachment->ID ) ),		'url'           => esc_url_raw( $attachment_url ),		'link'          => get_attachment_link( $attachment->ID ),		'alt'           => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),		'author'        => $attachment->post_author,		'description'   => $attachment->post_content,		'caption'       => $attachment->post_excerpt,		'name'          => $attachment->post_name,		'status'        => $attachment->post_status,		'uploadedTo'    => $attachment->post_parent,		'date'          => strtotime( $attachment->post_date_gmt ) * 1000,		'modified'      => strtotime( $attachment->post_modified_gmt ) * 1000,		'menuOrder'     => $attachment->menu_order,		'mime'          => $attachment->post_mime_type,		'type'          => $type,		'subtype'       => $subtype,		'icon'          => wp_mime_type_icon( $attachment->ID, '.svg' ),		'dateFormatted' => mysql2date( __( 'F j, Y' ), $attachment->post_date ),		'nonces'        => array(			'update' => false,			'delete' => false,			'edit'   => false,		),		'editLink'      => false,		'meta'          => false,	); 	$author = new WP_User( $attachment->post_author ); 	if ( $author->exists() ) {		$author_name            = $author->display_name ? $author->display_name : $author->nickname;		$response['authorName'] = html_entity_decode( $author_name, ENT_QUOTES, get_bloginfo( 'charset' ) );		$response['authorLink'] = get_edit_user_link( $author->ID );	} else {		$response['authorName'] = __( '(no author)' );	} 	if ( $attachment->post_parent ) {		$post_parent = get_post( $attachment->post_parent );		if ( $post_parent && current_user_can( 'read_post', $attachment->post_parent ) ) {			$response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );			$response['uploadedToLink']  = get_edit_post_link( $attachment->post_parent, 'raw' );		}	} 	$attached_file = get_attached_file( $attachment->ID ); 	if ( isset( $meta['filesize'] ) && is_numeric( $meta['filesize'] ) && (int) $meta['filesize'] > 0 ) {		$bytes = (int) $meta['filesize'];	} elseif ( is_string( $attached_file ) && '' !== $attached_file && is_readable( $attached_file ) ) {		$bytes = wp_filesize( $attached_file );	} else {		$bytes = '';	} 	if ( $bytes ) {

Changelog

Introduced in 3.5.0. One change between 6.7.7 and 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.

7.1.0
Return type changed from array|void to array|null.verified against source
3.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-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.