gravityflow_editable_fields

The gravityflow_editable_fields filter allows the set of editable fields for a step to be customized in general or per step type within Gravity Flow:

  • gravityflow_editable_fields
  • gravityflow_editable_fields_user_input
  • gravityflow_editable_fields_approval

Any custom steps which use the Editable_Fields trait will also have a step type named version of this filter run (example: gravityflow_editable_fields_custom_type)

Parameters

Parameter Type Definition
$editable_fields array The set of editable fields.
$step Gravity_Flow_Step The current step.

Examples

Example 1: Modify the editable fields

add_filter( 'gravityflow_editable_fields', 'sh_gravityflow_user_input_fields', 10, 2 );
function sh_gravityflow_user_input_fields( $editable_fields, $step ) {
	//Modify with the field IDs you want to be allowed to edit
	$editable_fields = array('2', '3', '7');
  	return $editable_fields;  
}

Example 2: Modify the editable fields for a user input step based on Step ID / user role

add_filter( 'gravityflow_editable_fields_user_input', 'sh_gravityflow_user_input_fields', 10, 2 );
function sh_gravityflow_user_input_fields( $editable_fields, $step ) {

    if ( $step && $step->get_id() == 91 ) {
        $user = wp_get_current_user();
        if ( in_array( 'administrator', (array) $user->roles ) ) {
		//Modify with the field IDs you want to be allowed to edit
		$editable_fields = array( '2', '3' );
        }
    }
    return $editable_fields;
}

Example 3: Modify the editable fields for an approval step based on form ID

add_filter( 'gravityflow_editable_fields_approval', 'sh_gravityflow_user_input_fields', 10, 2 );
function sh_gravityflow_user_input_fields( $editable_fields, $step ) {
    if ( $step ) {
        $entry = $step->get_entry();
        //Modify with the array of form IDs you want to customize the editable fields for.
        if( $entry && in_array( $entry['form_id'], array( '1', '3,', '17' ) ) ) {
		//Modify with the field IDs you want to be allowed to edit
        	$editable_fields = array( '2', '3' );
        }
    }
    return $editable_fields;
}

Example 4: Remove any editable fields that have the Gravity Perks Read Only setting active.

add_filter( 'gravityflow_editable_fields', 'gflow_gperks_read_only_user_input', 10, 2 );
function gflow_gperks_read_only_user_input( $editable_fields, $step ) {
	$form = GFAPI::get_form( $step->get_form_id() );
	$remove_read_only_ids = array();
	//Loop through the form fields to identify ones which are both selected as editable and have the perk setting active
	foreach ( $form['fields'] as $field ) {
		if ( in_array( $field['id'], $editable_fields ) && rgar( $field, 'gwreadonly_enable' ) ) {
			$remove_read_only_ids[] = $field['id'];
		}
	}
	//Remove any that had overlapping settings. Result is that display fields setting in step will apply to the "removed" fields.
	if ( ! empty( $remove_read_only_ids ) ) {
		$editable_fields = array_diff( $editable_fields, $remove_read_only_ids );
	}

	return $editable_fields;
}

Placement

This code should be placed in the functions.php file of your active theme