WordPress filter hook · part of WordPress core
attachment_fields_to_save
A WordPress core filter that 15 plugins also fire themselves, running on 298K+ sites between them.
“This filter is documented in wp-admin/includes/media.php”
How to use attachment_fields_to_save
It's a filter: your callback receives the value and 1 more argument, and must return the (changed) value.
Add this to your theme's functions.php or a small custom plugin:
add_filter( 'attachment_fields_to_save', function( $post, $attachment_data ) {
// Change $post here.
return $post;
}, 10, 2 );Argument names come from Responsive Lightbox & Gallery's source. Other plugins may pass different values: check the call in the plugin you're targeting below.
This hook is fired by WordPress core too. Official reference on developer.wordpress.org →
15 plugins that fire attachment_fields_to_save
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
Secure Custom Fields100,000+ installs
apply_filters( 'attachment_fields_to_save', $post, $changes )includes/fields/class-acf-field-gallery.php:201 -
Responsive Lightbox & Gallery100,000+ installs
apply_filters( 'attachment_fields_to_save', $post, $attachment_data )includes/class-folders.php:1034 -
Enhanced Media Library60,000+ installs
apply_filters( 'attachment_fields_to_save', $post, $attachment_data )core/taxonomies.php:962 -
Media Library Categories20,000+ installs
apply_filters( 'attachment_fields_to_save', $post, $attachment_data )index.php:593 -
Powerkit10,000+ installs
apply_filters( 'attachment_fields_to_save', $post, $changes )modules/post-format-ui/admin/class-powerkit-post-format-ui-admin.php:326 -
WP Media Category Management6,000+ installs
apply_filters( 'attachment_fields_to_save', $post, $attachment_data )include/taxonomy/class-WP_MCM_Taxonomy_Admin.php:445 -
Categorify1,000+ installs
apply_filters( 'attachment_fields_to_save', $post, $attachmentData )inc/category.php:138 -
WP Media Categories800+ installs
apply_filters( 'attachment_fields_to_save', $post, $attachment_data )wp-media-categories/includes/ajax.php:121 -
WPScreens300+ installs
apply_filters( 'attachment_fields_to_save', $post, $changes )includes/acf/pro/fields/class-acf-field-gallery.php:193 -
OVM Picture Organizer100+ installs
apply_filters( 'attachment_fields_to_save', $post, $attachment_data )index.php:589 -
toolbox百宝箱100+ installs
apply_filters( 'attachment_fields_to_save', $post, $attachment_data )inc/media.php:73 -
Flexblocks80+ installs
apply_filters( 'attachment_fields_to_save', $post, $changes )inc/acf/pro/fields/class-acf-field-gallery.php:197 -
Contact Form 7 AnalyticsFewer than 10 installs
apply_filters( 'attachment_fields_to_save', $post, $changes )acf/pro/fields/gallery.php:193 -
NavThemes Gutenberg BlocksFewer than 10 installs
apply_filters( 'attachment_fields_to_save', $post, $changes )admin/pro/fields/class-acf-field-gallery.php:195 -
White Label Megapack BrandingFewer than 10 installs
apply_filters( 'attachment_fields_to_save', $post, $attachment_data )include/functions/media/classes/includes/ajax.php:120
Need a customisation built on this hook?
Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.