Filter hook 'update_attached_file'

in WP Core File wp-includes/post.php at line 878

View Source

update_attached_file

Filter Hook
Description
Filters the path to the attached file to update.

Hook Information

File Location wp-includes/post.php View on GitHub
Hook Type Filter
Line Number 878

Hook Parameters

Type Name Description
string $file Path to the attached file to update.
int $attachment_id Attachment ID.

Usage Examples

Basic Usage
<?php
// Hook into update_attached_file
add_filter('update_attached_file', 'my_custom_filter', 10, 2);

function my_custom_filter($file, $attachment_id) {
    // Your custom filtering logic here
    return $file;
}

Source Code Context

wp-includes/post.php:878 - How this hook is used in WordPress core
<?php
 873  	 * @since 2.1.0
 874  	 *
 875  	 * @param string $file          Path to the attached file to update.
 876  	 * @param int    $attachment_id Attachment ID.
 877  	 */
 878  	$file = apply_filters( 'update_attached_file', $file, $attachment_id );
 879  
 880  	$file = _wp_relative_upload_path( $file );
 881  	if ( $file ) {
 882  		return update_post_meta( $attachment_id, '_wp_attached_file', $file );
 883  	} else {

PHP Documentation

<?php
/**
	 * 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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/post.php
Related Hooks

Related hooks will be displayed here in future updates.