get_attached_file
函数
get_attached_file ( $attachment_id, $unfiltered = false )
- 参数
-
-
(int)
$attachment_id
Attachment ID.- Required: 是
-
(bool)
$unfiltered
Optional. Whether to apply filters. Default false.- Required: 否
- Default: false
-
(int)
- 返回值
-
- (string|false) The file path to where the attached file should be, false otherwise.
- 定义位置
-
-
wp-includes/post.php
, line 723
-
wp-includes/post.php
- 引入
- 2.0.0
- 弃用
- –
Retrieves attached file path based on attachment ID.
By default the path will go through the ‘get_attached_file’ filter, but
passing a true to the $unfiltered argument of get_attached_file() will
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.
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 ) { $uploads = wp_get_upload_dir(); if ( false === $uploads['error'] ) { $file = path_join( $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 ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。