apply_filters( 'attachment_fields_to_edit', array $form_fields , WP_Post $post )
Filters the attachment fields to edit.
Parameters
More Information
- WordPress does not pass standard fields through this filter, though this can still be used for adding attachment form fields.
- Note that the filter function must return an array of attachment form fields after it is finished processing; otherwise, no fields will be displayed when editing an attachment and other plugins also filtering the
$form_fields
array may generate errors.
Source
File: wp-admin/includes/media.php
.
View all references
$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
Changelog
Version | Description |
---|---|
2.5.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
This is the way to add custom fields to attachments:
Example migrated from Codex:
The following example adds a “Location” field for all attachments. This example also uses the “edit_attachment” action hook to save the submitted custom attachment form fields value to the post meta of the post in which the attachment belongs.
If you add a custom field to attachments as described above, the field will be displayed and saved as well. But: There is no complete Ajax feedback to the user: the save icon appears in the top-right corner. “attachment-details” gets the class “save-waiting”, then again “save-ready”. The class “save-complete” is omitted. For the standard fields again this status is displayed. The text “Saved.” appears. This should be displayed for custom fields, too!