Articles of attachment fields to edit

Saving attachment custom fields

I want to establish a relationship between individual post attachments and Users. So far I’ve got my users listing just fine, but it isn’t saving/updating. add_filter(“attachment_fields_to_edit”, “my_image_attachment_fields_to_edit”, null, 2); function my_image_attachment_fields_to_edit($form_fields, $post) { $form_fields[“belongs_to”][“label”] = ‘Belongs to’; $form_fields[“belongs_to”][“input”] = “html”; $form_fields[“belongs_to”][“html”] = ”; $wp_user_query = new WP_User_Query( array( ‘orderby’ => ‘display_name’ ) ); $authors = […]

$form_fields from attachment_fields_to_edit returning empty array

I’m trying to remove the caption field from non-images attachments’ edit page, which should be a simple matter of unset($post[‘post_excerpt’]), but I can’t unset a non-existent value… Looking at the core, this Array being empty should mean that no fields exist on the attachment page, but all the expected fields are there (plus custom ones […]

What is the way to add additional fields to attachments in 3.5+?

I used to use attachment_fields_to_edit filter, but it seems that in 3.5+ it has been dropped. What is the new way of adding additional attachment fields? UPDATE: It seems that it wasn’t dropped, but – deprecated. In 3.6 it operates in compatibility mode. To make a new field appear in media popup, one should set […]

Can't display errors in attachment_fields_to_save

I am writing a plugin for adding a custom field to the image attachment dialogue box, the plugin works for storing valid input data. I have a problem for showing the error message “This is not a valid URL”. I think that I followed the documentation correctly but maybe there is something that I still […]

Official documentation for attachment form fields

I’m trying to use the attachment_fields_to_edit hook to create new fields on media attachments. According to the new documentation, one of the parameters is an “array of attachment form fields”. I can’t find, however, where on the documentation are the specs on how to build this array. I found this page on the Codex, but […]

Is there a native wp.media way to detect who “opened” wp.media.frame

I added few custom fields via attachment_fields_to_edit and would like to show them only when certain theme or page builder image option opens the wp.media.iframe. Currently they are visible regardless what button opens the uploader for example post “Add media” would not have any use for this option So I am kinda trying to find […]

How can I remove the image attachment ALT field?

I’ve been using the technique described in this post to remove the caption and description fields in the uploads modal window, thus eliminating unused clutter for users. Since the title field is already required when uploading images in WordPress, it’s easiest for my users to dispense with the alt field altogether and just pull the […]

How to set default value for 'Alt text' on image upload dialog?

I’m using WP 4.1.1 and trying to create a default value for the ‘Alt text’ when uploading an image (dropping it straight into post and dialog appears). I’ve tried doing this with this hook https://codex.wordpress.org/Plugin_API/Filter_Reference/attachment_fields_to_edit and while I seem to be able to ADD a new field (it appears on the dialog form), I cannot […]

Add custom field to media attachment image attribute in post editor

I have the following filter, but do not know how to add custom attributes to image field, when attaching media to post. example <img data-ext-link-title=”” data-ext-link-url=””> functions.php function pp_external_link_edit( $form_fields, $post ) { $form_fields[‘pp-external-link-title’] = array( ‘label’ => ‘External Link Title’, ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘pp_external_link_title’, true ), ‘helps’ => ‘Link for […]

Saving Custom Field in Attachment Window in WordPress 3.5

I’m using the code below to add a custom text field in WP 3.5 Attachment Window (from this question # Expanding new Media Uploader in WordPress 3.5) … add_filter( ‘attachment_fields_to_edit’, ‘xf_attachment_fields’, 10, 2 ); function xf_attachment_fields( $fields, $post ) { $meta = get_post_meta($post->ID, ‘meta_link’, true); $fields[‘meta_link’] = array( ‘label’ => ‘More Media Management’, ‘input’ => […]