WordPress的附件(多媒体)默认已经有一些对应的属性了,我们还可以再添加一些信息。
[caption id="attachment_3523" align="aligncenter" width="399"]
![wp_attachment_field](https://static.oschina.net/uploads/img/201612/31204510_KwBW.png)
wp_attachment_field[/caption]
[codesyntax lang="php"]
add_filter('attachment_fields_to_edit', 'suren_attachment_fields_to_edit', 10, 2);
add_action('edit_attachment', 'suren_edit_attachment');
function suren_attachment_fields_to_edit($form_fields, $post)
{
$field_value = get_post_meta($post->ID, 'license', true);
$form_fields['license'] = array(
'value' => $field_value ? $field_value : '',
'label' => __('License'),
'helps' => __('Specify the license type used for the image')
);
return $form_fields;
}
function suren_edit_attachment($attachment_id)
{
$license = $_REQUEST['attachments'][$attachment_id]['license'];
if(isset($license))
{
update_post_meta($attachment_id, 'license', $license);
}
}
[/codesyntax]