attachment_fields_to_edit
Filter HookDescription
$args = apply_filters( 'get_media_item_args', $args ); $form_fields = array(); if ( $args['in_modal'] ) { foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { $t = (array) get_taxonomy( $taxonomy ); if ( ! $t['public'] || ! $t['show_ui'] ) { continue; } if ( empty( $t['label'] ) ) { $t['label'] = $taxonomy; } if ( empty( $t['args'] ) ) { $t['args'] = array(); } $terms = get_object_term_cache( $post->ID, $taxonomy ); if ( false === $terms ) { $terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] ); } $values = array(); foreach ( $terms as $term ) { $values[] = $term->slug; } $t['value'] = implode( ', ', $values ); $t['taxonomy'] = true; $form_fields[ $taxonomy ] = $t; } } /* Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default. The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing )Hook Information
File Location |
wp-admin/includes/media.php
View on GitHub
|
Hook Type | Filter |
Line Number | 1935 |
Hook Parameters
This hook doesn't accept any parameters.
Usage Examples
Basic Usage
<?php
// Hook into attachment_fields_to_edit
add_filter('attachment_fields_to_edit', 'my_custom_filter');
function my_custom_filter() {
// Your custom filtering logic here
return 'modified_value';
}
Source Code Context
wp-admin/includes/media.php:1935
- How this hook is used in WordPress core
<?php
1930 * foreach ( (array) $things as $thing )
1931 */
1932 $form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] );
1933
1934 /** This filter is documented in wp-admin/includes/media.php */
1935 $form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
1936
1937 unset(
1938 $form_fields['image-size'],
1939 $form_fields['align'],
1940 $form_fields['image_alt'],
PHP Documentation
<?php
/** This filter is documented in wp-admin/includes/media.php */
$args = apply_filters( 'get_media_item_args', $args );
$form_fields = array();
if ( $args['in_modal'] ) {
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
$t = (array) get_taxonomy( $taxonomy );
if ( ! $t['public'] || ! $t['show_ui'] ) {
continue;
}
if ( empty( $t['label'] ) ) {
$t['label'] = $taxonomy;
}
if ( empty( $t['args'] ) ) {
$t['args'] = array();
}
$terms = get_object_term_cache( $post->ID, $taxonomy );
if ( false === $terms ) {
$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
}
$values = array();
foreach ( $terms as $term ) {
$values[] = $term->slug;
}
$t['value'] = implode( ', ', $values );
$t['taxonomy'] = true;
$form_fields[ $taxonomy ] = $t;
}
}
/*
* Merge default fields with their errors, so any key passed with the error
* (e.g. 'error', 'helps', 'value') will replace the default.
* The recursive merge is easily traversed with array casting:
* foreach ( (array) $things as $thing )
*/
Quick Info
- Hook Type: Filter
- Parameters: 0
- File: wp-admin/includes/media.php
Related Hooks
Related hooks will be displayed here in future updates.