Skip to content

Instantly share code, notes, and snippets.

@trepmal trepmal/alfred-quick-gist Secret
Created Jan 2, 2015

Embed
What would you like to do?
<?php
/**
* Insert two test fields. One standard input, one textarea.
*/
add_filter( 'attachment_fields_to_edit', function( $form_fields, $post ) {
$form_fields['testing-input-field'] = array(
'label' => 'input test',
'input' => 'html',
'value' => get_post_meta( $post->ID, 'testing-input-field', true ),
);
$form_fields['testing-textarea-field'] = array(
'label' => 'textarea test',
'input' => 'textarea',
'value' => get_post_meta( $post->ID, 'testing-textarea-field', true ),
);
return $form_fields;
}, 10, 2 );
/**
* Save fields for sanity during testing
*/
add_filter( 'attachment_fields_to_save', function( $post, $attachment ) {
if ( isset( $attachment['testing-input-field'] ) ) {
update_post_meta($post['ID'], 'testing-input-field', $attachment['testing-input-field']);
}
if ( isset( $attachment['testing-textarea-field'] ) ) {
update_post_meta($post['ID'], 'testing-textarea-field', $attachment['testing-textarea-field']);
}
return $post;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.