Skip to content

Instantly share code, notes, and snippets.

@tlovett1
Created February 4, 2013 16:24
Show Gist options
  • Save tlovett1/4707773 to your computer and use it in GitHub Desktop.
Save tlovett1/4707773 to your computer and use it in GitHub Desktop.
function pmc_variety_image_credit( $form_fields, $attachment ) {
$image_credit = array(
'label' => 'Image Credit',
'value' => get_post_meta( $attachment->ID, '_image_credit', true ),
'helps' => 'Image credit, e.g. "Copyright ' . date('Y') . ' Getty Images".',
'show_in_edit' => true,
);
$form_fields['image_credit'] = $image_credit;
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'pmc_variety_image_credit', 10, 2 );
function pmc_variety_image_credit_save( $post, $attachment ) {
if ( isset($attachment['image_credit']) ) {
$image_credit = trim( strip_tags( $attachment['image_credit'] ) );
update_post_meta( $post['ID'], '_image_credit', $image_credit );
}
return $post;
}
add_filter( 'attachment_fields_to_save', 'pmc_variety_image_credit_save', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment