Description
The gravityflow_editable_fields filter allows the set of editable fields for a step to be customized.
Usage
This filter can be hooked to based on a generic name or step type specific.
1 2 3 | add_filter( 'gravityflow_editable_fields' , 'sh_gravityflow_fields_editable_all_example' , 10, 2 ); add_filter( 'gravityflow_editable_fields_approval' , 'sh_gravityflow_fields_editable_approval_example' , 10, 2 ); add_filter( 'gravityflow_editable_fields_user_input' , 'sh_gravityflow_fields_editable_userinput_example' , 10, 2 ); |
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
Examples
Modify the editable fields
1 2 3 4 5 6 | 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 ; } |
Modify the editable fields for a user input step based on Step ID / user role
1 2 3 4 5 6 7 8 9 10 11 12 | 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 ; } |
Modify the editable fields for an approval step based on form ID
1 2 3 4 5 6 7 8 9 10 11 12 | 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 ; } |
Remove editable fields based on field meta details
This example is specific to the Gravity Perks Read Only setting gwreadonly_enable but similar approach could apply for any field metadata.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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 can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?