Skip to content

Instantly share code, notes, and snippets.

@trepmal
Created January 2, 2015 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trepmal/1e9f5ec4f37b92576279 to your computer and use it in GitHub Desktop.
Save trepmal/1e9f5ec4f37b92576279 to your computer and use it in GitHub Desktop.
<?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