Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Last active October 16, 2020 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackkatz/ce64a08a01f7209ff05422f9dcfa4749 to your computer and use it in GitHub Desktop.
Save zackkatz/ce64a08a01f7209ff05422f9dcfa4749 to your computer and use it in GitHub Desktop.
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