根据附件ID更新附件文件路径。
原型
update_attached_file( int $attachment_id, string $file )
描述
用于更新附件的文件路径,该路径使用后元名称’_wp_attached_file’来存储附件的路径。
参数
$attachment_id
(int)
(Required)
附件ID。
$file
(string)
(Required)
附件的文件路径。
返回值
(bool)
成功时是真的,失败时是假的。
源文件
路径:wp-includes/post.php
<?php
...
function update_attached_file( $attachment_id, $file ) {
if ( !get_post( $attachment_id ) )
return false;
/**
* Filters the path to the attached file to update.
*
* @since 2.1.0
*
* @param string $file Path to the attached file to update.
* @param int $attachment_id Attachment ID.
*/
$file = apply_filters( 'update_attached_file', $file, $attachment_id );
if ( $file = _wp_relative_upload_path( $file ) )
return update_post_meta( $attachment_id, '_wp_attached_file', $file );
else
return delete_post_meta( $attachment_id, '_wp_attached_file' );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/update_attached_file/