wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
get_attached_file › WordPress Function
Seit2.0.0
Veraltetn/v
› get_attached_file ( $attachment_id, $unfiltered = false )
| Parameter: (2) |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Retrieves attached file path based on attachment ID.
By default the path will go through the {@see 'get_attached_file'} filter, but passingtrue to the $unfiltered argument will return the file path unfiltered.
The function works by retrieving the _wp_attached_file post meta value.
This is a convenience function to prevent looking up the meta name and provide
a mechanism for sending the attached filename through a filter.Ähnliche Funktionen: update_attached_file, get_attached_media, get_the_title, get_attachment_link, get_attachment_icon
Quellcode
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 && ! str_starts_with( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) ) {
$uploads = wp_get_upload_dir();
if ( false === $uploads['error'] ) {
$file = $uploads['basedir'] . "/$file";
}
}
if ( $unfiltered ) {
return $file;
}
/**
* Filters the attached file based on the given ID.
*
* @since 2.1.0
*
* @param string|false $file The file path to where the attached file should be, false otherwise.
* @param int $attachment_id Attachment ID.
*/
return apply_filters( 'get_attached_file', $file, $attachment_id );
}