-
-
Save carlitoescobar/718fde7547df948f46e6f2dce3c54821 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().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment