Title: WP_REST_Attachments_Controller::get_sideloaded_file_names
Published: August 20, 2026

---

# WP_REST_Attachments_Controller::get_sideloaded_file_names( int $attachment_id, bool $include_provenance = true ): string[]

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#wp--skip-link--target)

Returns the file names which a finalize request may store for an attachment.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#description)󠁿

The set is the file names the sideload endpoint recorded as it produced them (ref.
[WP_REST_Attachments_Controller::META_KEY_SIDELOAD_FILE_NAME](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/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.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#parameters)󠁿

 `$attachment_id`intrequired

The attachment being finalized.

`$include_provenance`booloptional

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`

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#return)󠁿

 string[] File names that may appear in the finalize submission.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#source)󠁿

    ```php
    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 ) );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L3138)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php#L3138-L3185)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_get_attachment_metadata/)`wp-includes/post.php` |

Retrieves attachment metadata for attachment ID.

  | 
| [wp_basename()](https://developer.wordpress.org/reference/functions/wp_basename/)`wp-includes/formatting.php` |

i18n-friendly version of basename().

  | 
| [get_post_meta()](https://developer.wordpress.org/reference/functions/get_post_meta/)`wp-includes/post.php` |

Retrieves a post meta field for the given post ID.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#)

| Used by | Description | 
| [WP_REST_Attachments_Controller::validate_sub_size_provenance()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/validate_sub_size_provenance/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Validates the `sub_sizes` file names against what this attachment produced.

  | 
| [WP_REST_Attachments_Controller::finalize_item()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/finalize_item/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Finalizes an attachment after client-side media processing.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/get_sideloaded_file_names/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.1.0](https://developer.wordpress.org/reference/since/7.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_attachments_controller%2Fget_sideloaded_file_names%2F)
before being able to contribute a note or feedback.