I'd like to add two custom text fields for image attachments to posts (images inserted into the content of a post). Second I'd also like to remote some of the default fields like caption and description.
I've managed to add fields like so:
add_filter('attachment_fields_to_edit', array($this, 'applyFilter'), 1, 2);
public function applyFilter( $form_fields, $post = null ) {
$form_fields['someCustom'] = array(
'label' => 'Image credit',
'input' => 'text',
'helps' => 'Photographer / bureau',
'application' => 'image',
'exclusions' => array( 'audio', 'video' ),
'required' => true,
'error_text' => 'Credit field required',
);
return $form_fields;
}
This adds the field within the media library modal, but only when inserting new images - not when editing existing images. Also the required
parameter doesn't seem to prevent inserting images even when the field is empty.
No matter how I set the priority of the filter (tried everything from null, to 1, to 100) it seems to run before the default fields are added to form_fields
, making it impossible to remove any default fields.
I'd very much appreciate any help in the matter.
value
field is missing and that could prevent it from showing up when re-editing? hope that helps.value
field for an initial saved value it could be the reason for it not showing up later on the edit screen?