Definition:
function get_attached_file( $attachment_id, $unfiltered = false ) {}
Retrieve attached file path based on attachment ID.
You can optionally send it through the ‘get_attached_file’ filter, but by default it will just return the file path unfiltered.
Parameters
- int $attachment_id: Attachment ID.
- bool $unfiltered: Whether to apply filters.
Return values
returns:The file path to the attached file.
Defined filters
- get_attached_file
apply_filters( 'get_attached_file', $file, $attachment_id )
Source code
function get_attached_file( $attachment_id, $unfiltered = false ) {
$file = get_post_meta( $attachment_id, '_wp_attached_file', true );
// If the file is relative, prepend upload dir
if ( 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
$file = $uploads['basedir'] . "/$file";
if ( $unfiltered )
return $file;
return apply_filters( 'get_attached_file', $file, $attachment_id );
}
1150

February 11, 2011 


No comments yet... Be the first to leave a reply!