Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. function red_silk_attachment_field_data ( $form_fields, $post ) {
  2. $form_fields[ 'rs-horizontal-pos' ] = array(
  3. 'label' => 'Horizontal Position',
  4. 'input' => 'text',
  5. 'value' => get_post_meta( $post->ID, 'rs_horizontal_pos', true ),
  6. 'helps' => 'Far Left is 0, Right is 100.',
  7. );
  8.  
  9. $form_fields[ 'rs-vertical-pos' ] = array(
  10. 'label' => 'Vertical Position',
  11. 'input' => 'text',
  12. 'value' => get_post_meta( $post->ID, 'rs_vertical_pos', true ),
  13. 'helps' => 'Top is 0, bottom is 100.',
  14. );
  15.  
  16. $form_fields[ 'rs-location' ] = array(
  17. 'label' => 'Location',
  18. 'input' => 'text',
  19. 'value' => get_post_meta( $post->ID, 'rs_location', true ),
  20. 'helps' => 'Address or City',
  21. );
  22.  
  23. return $form_fields;
  24. }
  25. add_filter( 'attachment_fields_to_edit', 'red_silk_attachment_field_data', null, 2 );
  26.  
  27. function red_silk_attachment_field_data_save ( $attachment, $post ) {
  28.  
  29. // Horizontal position check and update.
  30. if( isset( $attachment['rs_horizontal_pos' ] ) ) {
  31. update_post_meta( $post['ID'], 'rs_horizontal_pos', sanitize_text_field($attachment[ 'rs_horizontal_pos' ] ) );
  32. } else if ( !isset( $attachment[ 'rs_horizontal_pos'] ) ) {
  33. update_post_meta( $post['ID'], 'rs_horizontal_pos', null );
  34. }
  35.  
  36. // Vertical position check and update
  37. if( isset( $attachment[ 'rs_vertical_pos' ] ) ) {
  38. update_post_meta( $post['ID'], 'rs_vertical_pos', sanitize_text_field($attachment['rs_vertical_pos'] ) );
  39. } else if ( !isset( $attachment[ 'rs_vertical_pos'] ) ) {
  40. update_post_meta( $post['ID'], 'rs_vertical_pos', null );
  41. }
  42.  
  43. if( isset( $attachment[ 'rs_location' ] ) ) {
  44. update_post_meta( $post['ID'], 'rs_location', $attachment[ 'rs_location' ] );
  45. }
  46. }
  47.  
  48. add_filter( 'attachment_fields_to_save', 'red_silk_attachment_field_data_save', null, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement