Skip to content

Instantly share code, notes, and snippets.

@jetsloth
Created October 23, 2022 23:11
Show Gist options
  • Save jetsloth/17fc37cdb9719fd8fbfc01a675ad6fbe to your computer and use it in GitHub Desktop.
Save jetsloth/17fc37cdb9719fd8fbfc01a675ad6fbe to your computer and use it in GitHub Desktop.
Customise the image size used for Image Choices
<?php
add_filter( 'gform_pre_render', 'custom_image_choices_size' );
add_filter( 'gform_pre_validation', 'custom_image_choices_size' );
add_filter( 'gform_pre_submission_filter', 'custom_image_choices_size' );
add_filter( 'gform_admin_pre_render', 'custom_image_choices_size' );
function custom_image_choices_size( $form ) {
foreach ( $form["fields"] as &$field ) {
if ( property_exists($field, "imageChoices_enableImages") && !empty($field->imageChoices_enableImages) ) {
foreach( $field["choices"] as $i => $choice ) {
$id = $choice["imageChoices_imageID"];
$field["choices"][$i]["imageChoices_image"] = wp_get_attachment_image_src($id, 'full');// replace "medium" with whichever size you need
}
}
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment