Created
August 11, 2017 12:58
-
-
Save spivurno/f17d5a4d60ea969b03e18774882bc542 to your computer and use it in GitHub Desktop.
Gravity Perks // GP Media Library // Auto-add Custom Field for File ID
This file contains hidden or 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 | |
/** | |
* 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