Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
add_action( 'gform_after_create_post_1', 'lc_gp_media_library_attach_to_post', 10, 3 );
/**
* Attach the uploaded images to the created post.
*
* @param int $post_id The Post ID for the post created with the form.
* @param array $lead The Lead Object.
* @param array $form The Form Object for the form used to create the post.
*/
function lc_gp_media_library_attach_to_post( $post_id, $lead, $form ) {
// Is the gp_media_library perk activated?
if ( ! function_exists( 'gp_media_library' ) )
return;
$file_ids = gp_media_library()->get_file_ids( rgar( $lead, 'id' ), 2 );
foreach ( $file_ids as $id ) {
$args = array(
'ID' => $id,
'post_parent' => $post_id,
);
wp_update_post( $args );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.