The attachment_fields_to_save
filter allows you to modify the associated data of an attachment.
It is evaluated in:
wp_ajax_save_attachment_compat()
in the wp-admin/includes/ajax-actions.php filemedia_upload_form_handler()
in the wp-admin/includes/media.php fileedit_post()
in the wp-admin/includes/post.php file
attachment_fields_to_save
accepts 2 arguments:
- array
$post
The attachment attributes. - array
$attachment_data
An array of attachment fields.
Example:
The following shows how you might go about saving a custom attachment field — we’ll say, a field with the id of image_editor_name
— implemented via the attachment_fields_to_edit
filter.
View the code example on Gist.
Have a suggested improvement? You can fork the Gist and comment back with the link. If all is agreeable, I’ll merge in your changes. Crowd-sourced documentation FTW!