Skip to content

Instantly share code, notes, and snippets.

@BeardedGinger
Created January 29, 2017 05:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BeardedGinger/55696d7f5ace13384cd588b48c101373 to your computer and use it in GitHub Desktop.
Save BeardedGinger/55696d7f5ace13384cd588b48c101373 to your computer and use it in GitHub Desktop.
<?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