attachment_fields_to_save WordPress Filter Hook

The attachment_fields_to_save hook is called when saving an attachment. It gives you the opportunity to modify the attachment data before it is saved to the database.

apply_filters( 'attachment_fields_to_save', array $post, array $attachment ) #

Filters the attachment fields to be saved.


Description

Top ↑

See also


Top ↑

Parameters

$post

(array)An array of post data.

$attachment

(array)An array of attachment metadata.


Top ↑

More Information

The attachment_fields_to_save filter is used to filter the associated data of images.

By default, it receives the input from the Media Upload screen and provides default values to the post_title, in case the user hasn’t done so.

It returns the $post array to be handled by the media_upload_form_handler function.

A plugin (or theme) can register as a content filter with the code:

<?php add_filter( 'attachment_fields_to_save', 'filter_function_name', 10, 2 ) ?>

Where ‘filter_function_name’ is the function WordPress should call when an attachment is being saved.

Note that the filter function must return the $post array after it is finished processing.

NOTE: per ticket #30687, any validation errors passed in via $post['errors'] array are silently unset and the attachment is processed without notifying the user


Top ↑

Source

File: wp-admin/includes/media.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More