Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: get_attached_file

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

Line Code
170  * @return string The file path to the attached file.
171  */
172 function get_attached_file( $attachment_id, $unfiltered = false ) {
173      $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
174      // If the file is relative, prepend upload dir
175      if ( 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
176           $file = $uploads['basedir'] . "/$file";
177      if ( $unfiltered )
178           return $file;
179      return apply_filters( 'get_attached_file', $file, $attachment_id );
180 }
181
182 /**
183  * Update attachment file path based on attachment ID.
184  *
185  * Used to update the file path of the attachment, which uses post meta name
186  * '_wp_attached_file' to store the path of the attachment.
187  *
188  * @since 2.1.0