функция
since 2.1.0
update_attached_file()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
update_attached_file( int $attachment_id, string $file ): int|bool
Описание
Используется для обновления пути к файлу вложения; путь хранится в метаполе записи _wp_attached_file.
Оригинал (английский)
Used to update the file path of the attachment, which uses post meta name _wp_attached_file to store the path of the attachment.
Параметры
$attachment_id
int
обязательный
Идентификатор вложения.
$file
string
обязательный
Путь к файлу вложения.
Возвращаемое значение
int|bool
_wp_attached_file $file
Исходный код
wp-includes/post.php:885
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' );
}
}
История изменений
| Версия | Описание |
|---|---|
| 2.1.0 | Introduced. |

