Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a media file on upload, requires the JDN_Create_Media_File class from https://gist.github.com/joshuadavidnelson/164a0a0744f0693d5746
<?php
/**
* Create a new media library entry with a file upload on gravity form submission.
* @see https://joshuadnelson.com/connect-gravity-forms-file-upload-to-acf-gallery-field/
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
$gravity_form_id = 1; // gravity form id, or replace {$gravity_form_id} below with this number
add_filter( "gform_after_submission_{$gravity_form_id}", 'jdn_add_image_to_media_library', 10, 2 );
function jdn_add_image_to_media_library( $entry, $form ) {
$gf_images_field_id = 7; // the upload field id
// Clean up images upload and add to the ACF field
if( isset( $entry[ $gf_images_field_id ] ) ) {
$image_url = esc_url( $entry[ $gf_images_field_id ] );
$create_image = new JDN_Create_Media_File( $image_url );
}
}
<?php
/**
* Create a new media library entries with a multi-file upload field on gravity form submission.
* @see https://joshuadnelson.com/connect-gravity-forms-file-upload-to-acf-gallery-field/
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
$gravity_form_id = 1; // gravity form id, or replace {$gravity_form_id} below with this number
add_filter( "gform_after_submission_{$gravity_form_id}", 'jdn_add_image_to_media_library', 10, 2 );
function jdn_add_image_to_media_library( $entry, $form ) {
$gf_images_field_id = 7; // the upload field id
if( ! isset( $entry[ $gf_images_field_id ] ) )
return;
// Create Media File for gallery of images
$gallery_images = json_decode( $entry[ $gf_images_field_id ] );
if( is_array( $gallery_images ) ) {
foreach( $gallery_images as $image ) {
$image_id = new JDN_Create_Media_File( esc_url( $image ) );
}
}
}
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.