WordPress函数wp_update_attachment_metadata()更新一个附件(图片/文件)的信息

描述:

更新一个附件(图片/文件)的信息

用法:

<?php wp_update_attachment_metadata( $post_id, $data ); ?>

参数:

$post_id

(integer) (必填) 附件ID.

默认值: None

$data

(array) (必填) 附件信息.

默认值: None

源文件:

function wp_update_attachment_metadata( $attachment_id, $data ) {
    $attachment_id = (int) $attachment_id;
    $post          = get_post( $attachment_id );
    if ( ! $post ) {
        return false;
    }
 
    /**
     * Filters the updated attachment meta data.
     *
     * @since 2.1.0
     *
     * @param array $data          Array of updated attachment meta data.
     * @param int   $attachment_id Attachment post ID.
     */
    $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
    if ( $data ) {
        return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
    } else {
        return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
    }
}