update_attached_file()
update_attached_file( int $attachment_id, string $file …
update_attached_file( int $attachment_id, string $file )
根据附件ID更新附件文件路径。
Update attachment file path based on attachment ID.
根据附件ID更新附件文件路径。
Update attachment file path based on attachment ID.
目录锚点:#说明#参数#源码
说明(Description)
用于更新附件的文件路径,该路径使用post meta name“_wp_attached_file”存储附件的路径。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $attachment_id | (int) | 附件ID。 |
| $file | (string) | 附件的文件路径。 |
源码(Source)
/**
* Update attachment file path based on attachment ID.
*
* Used to update the file path of the attachment, which uses post meta name
* '_wp_attached_file' to store the path of the attachment.
*
* @since 2.1.0
*
* @param int $attachment_id Attachment ID.
* @param string $file File path for the attachment.
* @return bool True on success, false on failure.
*/
function update_attached_file( $attachment_id, $file ) {
if ( !get_post( $attachment_id ) )
return false;
/**
* Filter 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' );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.1.0 | wp-includes/post.php | 16 | 3 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!