Advertisements

get_attached_file

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

Advertisements

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: