Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2. /* Add extra fields in media attachment */
  3. /**
  4. * Add Photographer Name and URL fields to media uploader
  5. *
  6. * @param $form_fields array, fields to include in attachment form
  7. * @param $post object, attachment record in database
  8. * @return $form_fields, modified form fields
  9. */
  10.  
  11. function custom_image_class_field( $form_fields, $post ) {
  12. $form_fields['image-class-name'] = array(
  13. 'label' => 'Image Class',
  14. 'input' => 'text',
  15. 'value' => get_post_meta( $post->ID, 'image_class_name', true ),
  16. 'helps' => 'Please provide image class eg. icons, coupons etc.',
  17. );
  18.  
  19. /*$form_fields['be-photographer-url'] = array(
  20. 'label' => 'Photographer URL',
  21. 'input' => 'text',
  22. 'value' => get_post_meta( $post->ID, 'be_photographer_url', true ),
  23. 'helps' => 'Add Photographer URL',
  24. );*/
  25.  
  26. return $form_fields;
  27. }
  28.  
  29. add_filter( 'attachment_fields_to_edit', 'custom_image_class_field', 10, 2 );
  30.  
  31. /**
  32. * Save values of Photographer Name and URL in media uploader
  33. *
  34. * @param $post array, the post data for database
  35. * @param $attachment array, attachment fields from $_POST form
  36. * @return $post array, modified post data
  37. */
  38.  
  39. function be_attachment_field_credit_save( $post, $attachment ) {
  40. if( isset( $attachment['image-class-name'] ) )
  41. update_post_meta( $post['ID'], 'image_class_name', $attachment['image-class-name'] );
  42.  
  43. /*if( isset( $attachment['be-photographer-url'] ) )
  44. update_post_meta( $post['ID'], 'be_photographer_url', esc_url( $attachment['be-photographer-url'] ) );*/
  45.  
  46. return $post;
  47. }
  48.  
  49. add_filter( 'attachment_fields_to_save', 'be_attachment_field_credit_save', 10, 2 );
  50. /* Add extra fields in media attachment end */
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement