0

似乎 Wordpress 使用 exif 标题来填充标题字段,但我需要它来使用 exif 版权数据,而不是自动将功劳归功于摄影师。我应该使用什么代码,请帮助我,因为我找不到该操作的明确示例。

<?php

add_action( 'add_attachment', 'my_set_image_meta_upon_image_upload' );

function my_set_image_meta_upon_image_upload( $post_ID ) {


    if ( wp_attachment_is_image( $post_ID ) ) {

        $my_image_title = get_post( $post_ID )->post_title;

        // Both give illegal string offset 'image_meta' 
        $meta_data = wp_read_image_metadata( $post_ID )['image_meta'];
        $meta_data = wp_get_attachment_metadata( $post_ID )['image_meta'];

        $my_image_meta = array(
            'ID'        => $post_ID,            
            'post_excerpt'  => $meta_data['copyright'],     
            'post_content'  => $meta_data['copyright'],     
        );


        update_post_meta( $post_ID, '_wp_attachment_image_alt', $meta_data );


        wp_update_post( $my_image_meta );

    } 
}
4

1 回答 1

0
function filter_wp_generate_attachment_copyright( $metadata, $attachment_id ) { 

    $cpr = $metadata[image_meta][copyright];

    $my_image_meta = array(
        'ID'        => $attachment_id,          // Specify the image (ID) to be updated
        'post_excerpt'  => 'Photo © ' . $cpr,       // Set image Caption (Excerpt) to copyright
    );  

    wp_update_post( $my_image_meta );
    return $metadata; 
}; 
add_filter( 'wp_generate_attachment_metadata', 'filter_wp_generate_attachment_copyright', 10, 2 );
于 2018-06-04T15:05:12.533 回答