Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dexit/3b67f83725eae361bd564f34ccb5cbaf to your computer and use it in GitHub Desktop.
Save dexit/3b67f83725eae361bd564f34ccb5cbaf to your computer and use it in GitHub Desktop.
Gravity Perks // GP Media Library // Auto-attach Uploaded Files to GF-generated Post
</php
/**
* Gravity Perks // GP Media Library // Auto-attach Uploaded Files to GF-generated Post
* http://gravitywiz.com/documentation/gp-media-library/
*/
add_action( 'gform_after_create_post', function( $post_id, $entry, $form ) {
if( is_callable( 'gp_media_library' ) ) {
$file_ids = gp_media_library()->get_file_ids_by_entry( $entry, $form );
if( $file_ids ) {
foreach( $file_ids as $field_id => $_file_ids ) {
foreach( $_file_ids as $file_id ) {
wp_update_post( array(
'ID' => $file_id,
'post_parent' => $post_id
) );
}
}
}
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment