Created
August 9, 2013 20:36
-
-
Save joshcanhelp/6196972 to your computer and use it in GitHub Desktop.
Add and save media attachment custom fields in WordPress
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
/* | |
* @param array $form_fields | |
* @param object $post | |
* | |
* @return array | |
*/ | |
function tenup_attachment_fields_to_edit ( $form_fields, $post ) | |
{ | |
$form_fields[ "use_as_header_img" ] = array( | |
'label' => __ ( "Use as header", '10up' ), | |
'input' => 'text', | |
'value' => get_post_meta ( $post->ID, 'use_as_header_img', TRUE ), | |
'helps' => 'Enter "left" for the left header image, "right" for a right one, | |
or leave blank to not use this image in the header.' | |
); | |
return $form_fields; | |
} | |
add_filter ( "attachment_fields_to_edit", "tenup_attachment_fields_to_edit", NULL, 2 ); | |
/* | |
* @param array $post | |
* @param array $attachment | |
* | |
* @return array | |
*/ | |
function tenup_attachment_fields_to_save ( $post, $attachment ) | |
{ | |
if ( isset( $attachment[ 'use_as_header_img' ] ) ) | |
update_post_meta ( $post[ 'ID' ], 'use_as_header_img', $attachment[ 'use_as_header_img' ] ); | |
return $post; | |
} | |
add_filter ( 'attachment_fields_to_save', 'tenup_attachment_fields_to_save', NULL, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment