/** This filter is documented in wp-admin/includes/media.php */
$post =
apply_filters( 'attachment_fields_to_save',
$post,
$attachment_data );
if ( isset( $post['errors'
] ) ) { $errors =
$post['errors'
]; // @todo return me and display me!
unset( $post['errors'
] );
} wp_update_post( $post );
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { if ( isset( $attachment_data[ $taxonomy ] ) ) { wp_set_object_terms( $id,
array_map( 'trim',
preg_split( '/,+/',
$attachment_data[ $taxonomy ] ) ),
$taxonomy, false
);
} } $attachment =
wp_prepare_attachment_for_js( $id );
if ( !
$attachment ) { wp_send_json_error();
}