Skip to content

Instantly share code, notes, and snippets.

@AMNDesign
Last active October 10, 2018 17:47
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AMNDesign/6514218 to your computer and use it in GitHub Desktop.
Save AMNDesign/6514218 to your computer and use it in GitHub Desktop.
Dynamically populate Gravity Forms fields with WordPress user info for logged in users using get_currentuserinfo().
<?php
//* Using the Gravity Forms editor, be sure to check "Allow field to be populated dynamically under Advanced Options
//* You will need to set the Field Parameter Name value to work with the filter as follows: gform_field_value_$parameter_name
//* Dynamically populate first name for logged in users
add_filter('gform_field_value_first_name', 'populate_first_name');
function populate_first_name($value){
global $current_user;
get_currentuserinfo();
return $current_user->user_firstname;
}
//* Dynamically populate last name for logged in users
add_filter('gform_field_value_last_name', 'populate_last_name');
function populate_last_name($value){
global $current_user;
get_currentuserinfo();
return $current_user->user_lastname;
}
//* Dynamically populate email for logged in users
add_filter('gform_field_value_email', 'populate_email');
function populate_email($value){
global $current_user;
get_currentuserinfo();
return $current_user->user_email;
}
//* This method can also be used for custom user fields, e.g...
//* Dynamically populate phone for logged in users
add_filter('gform_field_value_phone', 'populate_phone');
function populate_phone($value){
global $current_user;
get_currentuserinfo();
return $current_user->phone;
}
@maristhek
Copy link

Please clarify parameter name usage. None of the variations of "gform_field_value_$parameter_name" work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment