Filter hook 'attachment_fields_to_save'

in WP Core File wp-admin/includes/media.php at line 792

View Source

attachment_fields_to_save

Filter Hook
Description
Filters the attachment fields to be saved.

Hook Information

File Location wp-admin/includes/media.php View on GitHub
Hook Type Filter
Line Number 792

Hook Parameters

Type Name Description
array $post An array of post data.
array $attachment An array of attachment metadata.

Usage Examples

Basic Usage
<?php
// Hook into attachment_fields_to_save
add_filter('attachment_fields_to_save', 'my_custom_filter', 10, 2);

function my_custom_filter($post, $attachment) {
    // Your custom filtering logic here
    return $post;
}

Source Code Context

wp-admin/includes/media.php:792 - How this hook is used in WordPress core
<?php
 787  			 * @see wp_get_attachment_metadata()
 788  			 *
 789  			 * @param array $post       An array of post data.
 790  			 * @param array $attachment An array of attachment metadata.
 791  			 */
 792  			$post = apply_filters( 'attachment_fields_to_save', $post, $attachment );
 793  
 794  			if ( isset( $attachment['image_alt'] ) ) {
 795  				$image_alt = wp_unslash( $attachment['image_alt'] );
 796  
 797  				if ( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) !== $image_alt ) {

PHP Documentation

<?php
/**
			 * Filters the attachment fields to be saved.
			 *
			 * @since 2.5.0
			 *
			 * @see wp_get_attachment_metadata()
			 *
			 * @param array $post       An array of post data.
			 * @param array $attachment An array of attachment metadata.
			 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-admin/includes/media.php
Related Hooks

Related hooks will be displayed here in future updates.