Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Add extra fields in media attachment */
- /**
- * 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 custom_image_class_field( $form_fields, $post ) {
- $form_fields['image-class-name'] = array(
- 'label' => 'Image Class',
- 'input' => 'text',
- 'value' => get_post_meta( $post->ID, 'image_class_name', true ),
- 'helps' => 'Please provide image class eg. icons, coupons etc.',
- );
- /*$form_fields['be-photographer-url'] = array(
- 'label' => 'Photographer URL',
- 'input' => 'text',
- 'value' => get_post_meta( $post->ID, 'be_photographer_url', true ),
- 'helps' => 'Add Photographer URL',
- );*/
- return $form_fields;
- }
- add_filter( 'attachment_fields_to_edit', 'custom_image_class_field', 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['image-class-name'] ) )
- update_post_meta( $post['ID'], 'image_class_name', $attachment['image-class-name'] );
- /*if( isset( $attachment['be-photographer-url'] ) )
- update_post_meta( $post['ID'], 'be_photographer_url', esc_url( $attachment['be-photographer-url'] ) );*/
- return $post;
- }
- add_filter( 'attachment_fields_to_save', 'be_attachment_field_credit_save', 10, 2 );
- /* Add extra fields in media attachment end */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement