Created
April 18, 2013 05:36
-
-
Save facelordgists/5410381 to your computer and use it in GitHub Desktop.
PHP: Wordpress function to add a field to the media uploader
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
/** | |
* Add URL link field to media uploader | |
*/ | |
function slide_attachment_field_link( $form_fields, $post ) { | |
$form_fields['rsmm-photo-url'] = array( | |
'label' => 'Slide URL', | |
'input' => 'text', | |
'value' => get_post_meta( $post->ID, 'slide_url', true ), | |
'helps' => 'Add URL that this slide will link to, if used in a gallery', | |
); | |
return $form_fields; | |
} | |
add_filter( 'attachment_fields_to_edit', 'slide_attachment_field_link', 10, 2 ); | |
/** | |
* Save values in media uploader | |
*/ | |
function slide_attachment_field_credit_save( $post, $attachment ) { | |
if( isset( $attachment['rsmm-photo-url'] ) ) | |
update_post_meta( $post['ID'], 'slide_url', esc_url( $attachment['rsmm-photo-url'] ) ); | |
return $post; | |
} | |
add_filter( 'attachment_fields_to_save', 'slide_attachment_field_credit_save', 10, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment