Skip to content

Instantly share code, notes, and snippets.

@elpuas
Last active September 2, 2021 19:15
Show Gist options
  • Save elpuas/e92bcd494cda12486ebcfa2404103f90 to your computer and use it in GitHub Desktop.
Save elpuas/e92bcd494cda12486ebcfa2404103f90 to your computer and use it in GitHub Desktop.
Update Forms Everywhere
function twentytwentyone_gf_add_placeholder() {
$forms = GFAPI::get_forms();
foreach ( $forms as $form ) {
if ( $form['id'] !== 1 ) { // Or Any Form ID
return;
}
$fields = $form['fields'];
foreach( $fields as $field ) {
if ( $field->type === 'select' && $field->label === 'State' ) {
$field->placeholder = 'Choose a State';
$field->isRequired = true;
}
}
$result = GFAPI::update_form( $form );
}
return $result;
}
twentytwentyone_gf_add_placeholder();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment