Here 是一个教程,介绍如何将自定义字段添加到附件/媒体库/thickbox/iframe/您称之为覆盖的内容。
我已经成功地使用了它,但还没有进一步添加单选按钮/复选框等,也没有将更改限制在特定的帖子类型上,但这一切看起来也是完全可行的。
以下是上面链接中的代码,以防有一天它消失:
1) “attachment\\u fields\\u to\\u edit”:我们将在此挂钩上附加一个函数,用于向媒体库添加自定义字段。
/* For adding custom field to gallery popup */
function rt_image_attachment_fields_to_edit($form_fields, $post) {
    // $form_fields is a an array of fields to include in the attachment form
    // $post is nothing but attachment record in the database
    //     $post->post_type == \'attachment\'
    // attachments are considered as posts in WordPress. So value of post_type in wp_posts table will be attachment
    // now add our custom field to the $form_fields array
    // input type="text" name/id="attachments[$attachment->ID][custom1]"
    $form_fields["rt-image-link"] = array(
        "label" => __("Custom Link"),
        "input" => "text", // this is default if "input" is omitted
        "value" => get_post_meta($post->ID, "_rt-image-link", true),
                "helps" => __("To be used with special slider added via [rt_carousel] shortcode."),
    );
   return $form_fields;
}
 2)“attachment\\u fields\\u to\\u save”:这将依次接受并保存用户输入。
// now attach our function to the hook
add_filter("attachment_fields_to_edit", "rt_image_attachment_fields_to_edit", null, 2);
    function rt_image_attachment_fields_to_save($post, $attachment) {
    // $attachment part of the form $_POST ($_POST[attachments][postID])
        // $post[\'post_type\'] == \'attachment\'
    if( isset($attachment[\'rt-image-link\']) ){
        // update_post_meta(postID, meta_key, meta_value);
        update_post_meta($post[\'ID\'], \'_rt-image-link\', $attachment[\'rt-image-link\']);
    }
    return $post;
}
// now attach our function to the hook.
add_filter("attachment_fields_to_save", "rt_image_attachment_fields_to_save", null , 2);