Using Gravity Forms ‘gform_advancedpostcreation_file_fields_choices’ PHP filter

The gform_advancedpostcreation_file_fields_choices Gravity Forms PHP filter allows you to override the available choices for media settings on the feed configuration page.

Usage

add_filter('gform_advancedpostcreation_file_fields_choices', 'your_function_name', 10, 3);

Parameters

  • $choices (array): The file fields as choices.
  • $form (Form Object): The current form.
  • $single_file (bool): Indicates if only single file upload fields should be returned.

More information

See Gravity Forms Docs: gform_advancedpostcreation_file_fields_choices

Examples

Remove a specific choice from the list

This example removes any choice with the label ‘Not For Media’ from the available choices.

add_filter('gform_advancedpostcreation_file_fields_choices', 'filter_choices', 10, 3);

function filter_choices($choices, $form, $single_file) {
    $filtered_choices = array();
    foreach ($choices as $choice) {
        if ($choice['label'] == 'Not For Media') {
            continue;
        }
        $filtered_choices[] = $choice;
    }
    return $filtered_choices;
}

Only allow image file upload fields

This example only allows image file upload fields to be returned as choices.

add_filter('gform_advancedpostcreation_file_fields_choices', 'filter_image_choices', 10, 3);

function filter_image_choices($choices, $form, $single_file) {
    $filtered_choices = array();
    foreach ($choices as $choice) {
        if ($choice['inputType'] == 'image') {
            $filtered_choices[] = $choice;
        }
    }
    return $filtered_choices;
}

Exclude file upload fields with specific form ID

This example excludes file upload fields from forms with a specific form ID.

add_filter('gform_advancedpostcreation_file_fields_choices', 'filter_form_choices', 10, 3);

function filter_form_choices($choices, $form, $single_file) {
    if ($form['id'] == 5) { // Replace 5 with your desired form ID
        return array();
    }
    return $choices;
}

Add custom choices to the list

This example adds a custom choice to the list of available choices.

add_filter('gform_advancedpostcreation_file_fields_choices', 'add_custom_choice', 10, 3);

function add_custom_choice($choices, $form, $single_file) {
    $choices[] = array(
        'text' => 'Custom Choice',
        'value' => 'custom_choice'
    );
    return $choices;
}

Change the order of choices based on custom logic

This example sorts the choices alphabetically by their labels.

add_filter('gform_advancedpostcreation_file_fields_choices', 'sort_choices', 10, 3);

function sort_choices($choices, $form, $single_file) {
    usort($choices, function($a, $b) {
        return strcmp($a['label'], $b['label']);
    });
    return $choices;
}