Last active
April 29, 2020 19:42
-
-
Save joshuadavidnelson/51d32ee04578b438a44d90c26924614d to your computer and use it in GitHub Desktop.
Create a media file on upload, requires the JDN_Create_Media_File class from https://gist.github.com/joshuadavidnelson/164a0a0744f0693d5746
This file contains 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 | |
/** | |
* 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, [email protected] | |
*/ | |
$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 ); | |
} | |
} |
This file contains 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 | |
/** | |
* 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, [email protected] | |
*/ | |
$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