-
-
Save trepmal/1e9f5ec4f37b92576279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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