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
183  * @return string|bool The file path to where the attached file should be, false otherwise.
184  */
185 function get_attached_file( $attachment_id, $unfiltered = false ) {
186      $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
187      // If the file is relative, prepend upload dir
188      if ( $file && 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
189           $file = $uploads['basedir'] . "/$file";
190      if ( $unfiltered )
191           return $file;
192      return apply_filters( 'get_attached_file', $file, $attachment_id );
193 }
194
195 /**
196  * Update attachment file path based on attachment ID.
197  *
198  * Used to update the file path of the attachment, which uses post meta name
199  * '_wp_attached_file' to store the path of the attachment.
200  *
201  * @since 2.1.0