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:

functions.php
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.

  1. Secure Custom Fields icon Secure Custom Fields100,000+ installs apply_filters( 'attachment_fields_to_save', $post, $changes ) includes/fields/class-acf-field-gallery.php:201
  2. Responsive Lightbox & Gallery icon Responsive Lightbox & Gallery100,000+ installs apply_filters( 'attachment_fields_to_save', $post, $attachment_data ) includes/class-folders.php:1034
  3. Enhanced Media Library icon Enhanced Media Library60,000+ installs apply_filters( 'attachment_fields_to_save', $post, $attachment_data ) core/taxonomies.php:962
  4. Media Library Categories icon Media Library Categories20,000+ installs apply_filters( 'attachment_fields_to_save', $post, $attachment_data ) index.php:593
  5. Powerkit icon Powerkit10,000+ installs apply_filters( 'attachment_fields_to_save', $post, $changes ) modules/post-format-ui/admin/class-powerkit-post-format-ui-admin.php:326
  6. WP Media Category Management icon WP Media Category Management6,000+ installs apply_filters( 'attachment_fields_to_save', $post, $attachment_data ) include/taxonomy/class-WP_MCM_Taxonomy_Admin.php:445
  7. Categorify icon Categorify1,000+ installs apply_filters( 'attachment_fields_to_save', $post, $attachmentData ) inc/category.php:138
  8. WP Media Categories icon WP Media Categories800+ installs apply_filters( 'attachment_fields_to_save', $post, $attachment_data ) wp-media-categories/includes/ajax.php:121
  9. WPScreens icon WPScreens300+ installs apply_filters( 'attachment_fields_to_save', $post, $changes ) includes/acf/pro/fields/class-acf-field-gallery.php:193
  10. OVM Picture Organizer icon OVM Picture Organizer100+ installs apply_filters( 'attachment_fields_to_save', $post, $attachment_data ) index.php:589
  11. toolbox百宝箱 icon toolbox百宝箱100+ installs apply_filters( 'attachment_fields_to_save', $post, $attachment_data ) inc/media.php:73
  12. Flexblocks icon Flexblocks80+ installs apply_filters( 'attachment_fields_to_save', $post, $changes ) inc/acf/pro/fields/class-acf-field-gallery.php:197
  13. Contact Form 7 Analytics icon Contact Form 7 AnalyticsFewer than 10 installs apply_filters( 'attachment_fields_to_save', $post, $changes ) acf/pro/fields/gallery.php:193
  14. NavThemes Gutenberg Blocks icon NavThemes Gutenberg BlocksFewer than 10 installs apply_filters( 'attachment_fields_to_save', $post, $changes ) admin/pro/fields/class-acf-field-gallery.php:195
  15. White Label Megapack Branding icon 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.