Last active
February 15, 2016 13:07
-
-
Save twentyfortysix/d7dcdc931aed3f2529a9 to your computer and use it in GitHub Desktop.
WP - register custom field for media
This file contains hidden or 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 | |
function be_attachment_field_credit( $form_fields, $post ) { | |
// | |
// ---- CS --- | |
// | |
$form_fields['media_date'] = array( | |
'label' => 'Datum', | |
'input' => 'text', | |
'value' => get_post_meta( $post->ID, 'media_date', true ), | |
// 'helps' => 'datace', | |
); | |
return $form_fields; | |
} | |
add_filter( 'attachment_fields_to_edit', 'be_attachment_field_credit', 10, 2 ); | |
/** | |
* Save media values | |
* | |
* @param $post array, the post data for database | |
* @param $attachment array, attachment fields from $_POST form | |
* @return $post array, modified post data | |
*/ | |
function be_attachment_field_credit_save( $post, $attachment ) { | |
if( isset( $attachment['media_date'] ) ) | |
update_post_meta( $post['ID'], 'media_date', esc_attr( $attachment['media_date'] ) ); | |
return $post; | |
} | |
add_filter( 'attachment_fields_to_save', 'be_attachment_field_credit_save', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment