Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function red_silk_attachment_field_data ( $form_fields, $post ) {
- $form_fields[ 'rs-horizontal-pos' ] = array(
- 'label' => 'Horizontal Position',
- 'input' => 'text',
- 'value' => get_post_meta( $post->ID, 'rs_horizontal_pos', true ),
- 'helps' => 'Far Left is 0, Right is 100.',
- );
- $form_fields[ 'rs-vertical-pos' ] = array(
- 'label' => 'Vertical Position',
- 'input' => 'text',
- 'value' => get_post_meta( $post->ID, 'rs_vertical_pos', true ),
- 'helps' => 'Top is 0, bottom is 100.',
- );
- $form_fields[ 'rs-location' ] = array(
- 'label' => 'Location',
- 'input' => 'text',
- 'value' => get_post_meta( $post->ID, 'rs_location', true ),
- 'helps' => 'Address or City',
- );
- return $form_fields;
- }
- add_filter( 'attachment_fields_to_edit', 'red_silk_attachment_field_data', null, 2 );
- function red_silk_attachment_field_data_save ( $attachment, $post ) {
- // Horizontal position check and update.
- if( isset( $attachment['rs_horizontal_pos' ] ) ) {
- update_post_meta( $post['ID'], 'rs_horizontal_pos', sanitize_text_field($attachment[ 'rs_horizontal_pos' ] ) );
- } else if ( !isset( $attachment[ 'rs_horizontal_pos'] ) ) {
- update_post_meta( $post['ID'], 'rs_horizontal_pos', null );
- }
- // Vertical position check and update
- if( isset( $attachment[ 'rs_vertical_pos' ] ) ) {
- update_post_meta( $post['ID'], 'rs_vertical_pos', sanitize_text_field($attachment['rs_vertical_pos'] ) );
- } else if ( !isset( $attachment[ 'rs_vertical_pos'] ) ) {
- update_post_meta( $post['ID'], 'rs_vertical_pos', null );
- }
- if( isset( $attachment[ 'rs_location' ] ) ) {
- update_post_meta( $post['ID'], 'rs_location', $attachment[ 'rs_location' ] );
- }
- }
- add_filter( 'attachment_fields_to_save', 'red_silk_attachment_field_data_save', null, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement