WP_REST_Attachments_Controller::get_sideloaded_file_names( int $attachment_id, bool $include_provenance = true ): string[]
- Since
- 7.1.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:3138
Description
The set is the file names the sideload endpoint recorded as it produced them (ref. self::META_KEY_SIDELOAD_FILE_NAME), plus the attachment's own attached file - accepted in both its uploads-relative and basename form so a scaled main-file pointer validates regardless of which the client echoes - plus the names already stored in the attachment's own metadata.
Compatibility
- WordPress
- since 7.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$attachment_idint- The attachment being finalized.
$include_provenancebooloptional- Whether to include the sideload provenance rows.
Pass false to get only the names recoverable from the attached file and stored metadata, e.g. to decide whether a provenance row is still needed. Default true.Default:true
Return value
string[]- File names that may appear in the finalize submission.
Performance profile
How much work a call to WP_REST_Attachments_Controller::get_sideloaded_file_names() 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
- 26–79
- Plugin surface
- None
- 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 109.
Nothing here hands control to plugin code.
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()one call below WP_REST_Attachments_Controller::get_sideloaded_file_names() - hookthird-party callbacks
apply_filters()one call below WP_REST_Attachments_Controller::get_sideloaded_file_names()
Further down the call graph this can also reach cache, serialize, option 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 WP_REST_Attachments_Controller::get_sideloaded_file_names() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 26–63 | get_post_meta(), wp_get_attachment_metadata(), array_unique(), array_values() |
| always | 34–72 | get_post_meta(), get_post_meta(), wp_get_attachment_metadata(), array_unique(), array_values() |
is_string($attached_file) | 36–70 | get_post_meta(), wp_basename(), wp_get_attachment_metadata(), array_unique(), array_values() |
is_string($attached_file) | 44–79 | get_post_meta(), get_post_meta(), wp_basename(), wp_get_attachment_metadata(), array_unique(), array_values() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 109 | 26–79 | 23 | |
| 8.5 | 109 | 26–79 | 23 | |
| 8.4 | 109 | 26–79 | 23 | |
| 8.3 | 109 | 26–79 | 23 | |
| 8.2 | 109 | 26–79 | 23 | |
| 8.1 | 109 | 26–79 | 23 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 110 | 27–80 | 23 |
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.
Uses · 3
- get_post_meta()Retrieves a post meta field for the given post ID.
- wp_basename()i18n-friendly version of basename().
- wp_get_attachment_metadata()Retrieves attachment metadata for attachment ID.
Used by · 2
- WP_REST_Attachments_Controller::finalize_item()Finalizes an attachment after client-side media processing.
- WP_REST_Attachments_Controller::validate_sub_size_provenance()Validates the `sub_sizes` file names against what this attachment produced.
Source code
protected function get_sideloaded_file_names( int $attachment_id, bool $include_provenance = true ): array { $allowed = array(); if ( $include_provenance ) { foreach ( (array) get_post_meta( $attachment_id, self::META_KEY_SIDELOAD_FILE_NAME ) as $name ) { if ( is_string( $name ) && '' !== $name ) { $allowed[] = $name; } } } $attached_file = get_post_meta( $attachment_id, '_wp_attached_file', true ); if ( is_string( $attached_file ) && strlen( $attached_file ) > 0 ) { $allowed[] = $attached_file; $allowed[] = wp_basename( $attached_file ); } /* * Names already stored in this attachment's metadata passed this same * check when they were written, so accepting them again introduces * nothing new. */ $metadata = wp_get_attachment_metadata( $attachment_id, true ); if ( is_array( $metadata ) ) { $stored = array( $metadata['file'] ?? null, $metadata['original_image'] ?? null, $metadata[ self::META_KEY_SOURCE_IMAGE ] ?? null, $metadata['animated_video'] ?? null, $metadata['animated_video_poster'] ?? null, ); if ( ! empty( $metadata['sizes'] ) && is_array( $metadata['sizes'] ) ) { foreach ( $metadata['sizes'] as $size ) { $stored[] = is_array( $size ) ? ( $size['file'] ?? null ) : null; } } foreach ( $stored as $name ) { if ( is_string( $name ) && '' !== $name ) { $allowed[] = $name; $allowed[] = wp_basename( $name ); } } } return array_values( array_unique( $allowed ) ); }Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.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.