Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




get_attached_file [ WordPress Function ]

get_attached_file ( $attachment_id, $unfiltered = false )
Parameters:
  • (int) $attachment_id Attachment ID.
  • (bool) $unfiltered Whether to apply filters.
Uses:
Returns:
  • (string|bool) The file path to the attached file, or false if the attachment does not exist.
Defined at:



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.

The function works by getting the single post meta name, named '_wp_attached_file' and returning it. This is a convenience function to prevent looking up the meta name and provide a mechanism for sending the attached filename through a filter.

Source


<?php
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 ( $file && !== 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 );
}
?>

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics