WordPress at a glance
function is not described

update_attached_file() WP 2.1.0

Update attachment file path based on attachment ID.

Used to update the file path of the attachment, which uses post meta name '_wp_attached_file' to store the path of the attachment.

Hooks in function

true/false. True on success, false on failure.


update_attached_file( $attachment_id, $file );
$attachment_id(int) (required)
Attachment ID.
$file(string) (required)
File path for the attachment.

Code of update attached file: wp-includes/post.php VER 5.0.3

function update_attached_file( $attachment_id, $file ) {
	if ( !get_post( $attachment_id ) )
		return false;

	 * Filters the path to the attached file to update.
	 * @since 2.1.0
	 * @param string $file          Path to the attached file to update.
	 * @param int    $attachment_id Attachment ID.
	$file = apply_filters( 'update_attached_file', $file, $attachment_id );

	if ( $file = _wp_relative_upload_path( $file ) )
		return update_post_meta( $attachment_id, '_wp_attached_file', $file );
		return delete_post_meta( $attachment_id, '_wp_attached_file' );