Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spivurno/f17d5a4d60ea969b03e18774882bc542 to your computer and use it in GitHub Desktop.
Save spivurno/f17d5a4d60ea969b03e18774882bc542 to your computer and use it in GitHub Desktop.
Gravity Perks // GP Media Library // Auto-add Custom Field for File ID
<?php
/**
* Gravity Perks // GP Media Library // Auto-add Custom Field for File ID
* http://gravitywiz.com/documentation/gp-media-library/
*/
add_filter( 'gform_post_data', function( $data, $form, $entry ) {
if( ! is_callable( 'gp_media_library' ) ) {
return $data;
}
foreach( $form['fields'] as &$field ) {
if( $field->type == 'post_custom_field' && gp_media_library()->is_applicable_field( $field ) ) {
$meta_key = $field->postCustomFieldName;
$id_meta_key = "{$meta_key}_id";
$file_id = gp_media_library()->get_file_ids( $entry['id'], $field->id, 0 );
$data['post_custom_fields'][ $id_meta_key ] = $file_id;
}
}
return $data;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment