Last active
December 20, 2015 15:19
-
-
Save WerdsWords/6153633 to your computer and use it in GitHub Desktop.
#32: attachment_fields_to_save
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 | |
/** | |
* Save custom attachment meta | |
* | |
* @see wp_ajax_save_attachment_compat(), media_upload_form_handler(), edit_post() | |
* | |
* @param array $post The attachment attributes. | |
* @param array $attachment_data An array of attachment fields. | |
* | |
* @return array The attachment attributes. | |
*/ | |
function wpdocs_custom_attachment_meta( $post, $attachment_data ) { | |
// If the field has a value, update post meta | |
if ( isset( $attachment_data['image_editor_name'] ) && ! empty( sanitize_text_field( $attachment_data['image_editor_name'] ) ) ) | |
update_post_meta( $post['ID'], 'image_editor_name', sanitize_text_field( $attachment_data['image_editor_name'] ) ); | |
return $post; | |
} | |
add_filter( 'attachment_fields_to_save', 'wpdocs_custom_attachment_meta', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment