Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GravityView - Modify Field Settings to always have some settings checked
<?php
// Run after 10 priority to make sure all the fields are added
add_filter( 'gravityview_template_field_options', 'gv_modify_field_setting_defaults', 20, 6 );
/**
* Always check "Show Label" and "Visible to Logged-in Viewers" field settings
*
* @param array $field_options Array of field options with `label`, `value`, `type`, `default` keys
* @param string $template_id Table slug
* @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
* @param string $context What context are we in? Example: `single` or `directory`
* @param string $input_type (textarea, list, select, etc.)
* @param int $form_id The form ID. @since develop
*
* @return array Modified field settings
*/
function gv_modify_field_setting_defaults( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) {
if ( isset( $field_options['show_label'] ) ) {
$field_options['show_label']['value'] = true;
}
if ( isset( $field_options['only_loggedin'] ) ) {
$field_options['only_loggedin']['value'] = true;
}
return $field_options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment