Created
November 27, 2011 20:14
-
-
Save billerickson/1398077 to your computer and use it in GitHub Desktop.
Multilinqual - Add Photographer Name and URL fields to media uploader
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
<?php | |
/** | |
* Add Photographer Name and URL fields to media uploader | |
* | |
* @param $form_fields array, fields to include in attachment form | |
* @param $post object, attachment record in database | |
* @return $form_fields, modified form fields | |
*/ | |
function be_attachment_field_credit( $form_fields, $post ) { | |
$form_fields['be-photographer-name'] = array( | |
'label' => __( 'Photographer Name', 'my-plugin-name' ), | |
'input' => 'text', | |
'value' => get_post_meta( $post->ID, 'be_photographer_name', true ), | |
'helps' => __( 'If provided, photo credit will be displayed', 'my-plugin-name' ), | |
); | |
$form_fields['be-photographer-url'] = array( | |
'label' => __( 'Photographer URL', 'my-plugin-name' ), | |
'input' => 'text', | |
'value' => get_post_meta( $post->ID, 'be_photographer_url', true ), | |
'helps' => __( 'If provided, photographer name will link here', 'my-plugin-name' ), | |
); | |
return $form_fields; | |
} | |
add_filter( 'attachment_fields_to_edit', 'be_attachment_field_credit', 10, 2 ); | |
/** | |
* Save values of Photographer Name and URL in media uploader | |
* | |
* @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['be-photographer-name'] ) ) | |
update_post_meta( $post['ID'], 'be_photographer_name', $attachment['be-photographer-name'] ); | |
if( isset( $attachment['be-photographer-url'] ) ) | |
update_post_meta( $post['ID'], 'be_photographer_url', $attachment['be-photographer-url'] ); | |
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