
如何创建一个有效的WordPress开发流程
update_attached_file ( $attachment_id, $file )
update_attached_file: 更新附加文件的位置: 这个函数更新与一个文章或页面相关的附件文件的位置。
根据附件ID更新附件文件路径。
用于更新附件的文件路径,它使用文章元名称’_wp_attached_file’来存储附件的路径。
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 ); $file = _wp_relative_upload_path( $file ); if ( $file ) { return update_post_meta( $attachment_id, '_wp_attached_file', $file ); } else { return delete_post_meta( $attachment_id, '_wp_attached_file' ); } }