/*image hopper populate for gift all slides*/
add_action( 'gform_pre_render', function( $form ) {
/* Only run on form ID 41 */
if ( (int) $form['id'] !== 41 ) {
return $form;
}
if ( ! isset( \GFFormsModel::$uploaded_files[ $form['id'] ] ) ) {
\GFFormsModel::$uploaded_files[ $form['id'] ] = [];
}
$gift_id = $_GET['gift_id'];
$img_id_1 = get_field('gift_image', $gift_id );
$img_url_1 = wp_get_attachment_image_url( $img_id_1, 'full' );
$img_id_2 = get_field('gift_image_2', $gift_id );
$img_url_2 = wp_get_attachment_image_url( $img_id_2, 'full' );
$img_id_3 = get_field('gift_image_3', $gift_id );
$img_url_3 = wp_get_attachment_image_url( $img_id_3, 'full' );
$img_id_4 = get_field('gift_image_4', $gift_id );
$img_url_4 = wp_get_attachment_image_url( $img_id_4, 'full' );
if (!empty($img_url_1)) {
/* Pre-populate Image Hopper field ID#1 with image */
\GFFormsModel::$uploaded_files[ $form['id'] ]['input_1'] = [
[
'temp_filename' => '',
'uploaded_filename' => $img_url_1,
],
];
}
if (!empty($img_url_2)) {
/* Pre-populate Image Hopper field ID#1 with image */
\GFFormsModel::$uploaded_files[ $form['id'] ]['input_10'] = [
[
'temp_filename' => '',
'uploaded_filename' => $img_url_2,
],
];
}
if (!empty($img_url_3)) {
/* Pre-populate Image Hopper field ID#1 with image */
\GFFormsModel::$uploaded_files[ $form['id'] ]['input_13'] = [
[
'temp_filename' => '',
'uploaded_filename' => $img_url_3,
],
];
}
if (!empty($img_url_4)) {
/* Pre-populate Image Hopper field ID#1 with image */
\GFFormsModel::$uploaded_files[ $form['id'] ]['input_16'] = [
[
'temp_filename' => '',
'uploaded_filename' => $img_url_4,
],
];
}
return $form;
} );
Comments