Skip to content

Instantly share code, notes, and snippets.

@DrewAPicture
Created February 22, 2014 22:50
Show Gist options
  • Save DrewAPicture/9163579 to your computer and use it in GitHub Desktop.
Save DrewAPicture/9163579 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'attachment_fields_to_edit', 'attachment_fields_to_edit', 10, 2 );
add_filter( 'attachment_fields_to_save', 'attachment_fields_to_save', 10, 2 );
function attachment_fields_to_edit( $form_fields, $post ) {
$form_fields["client_test_input"] = array(
"label" => __( 'Test Input URL' , 'client' ),
"value" => get_post_meta( $post->ID, "_client_test_input", true ),
"helps" => __( 'Test Input Field', 'client' )
);
return $form_fields;
}
function attachment_fields_to_save( $post, $attachment ) {
if( empty( $attachment['client_test_input'] ) )
delete_post_meta( $post['ID'], '_client_test_input' );
else
update_post_meta( $post['ID'], '_client_test_input', esc_url( $attachment['client_test_input'] ) );
return $post;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment