The gform_user_registration_user_meta_options Gravity Forms PHP filter allows you to set the options for the “Other User Meta” group in the User Registration Add-On, instead of pulling the meta keys from the database.
Usage
add_filter('gform_user_registration_user_meta_options', 'your_function_name');
Parameters
- $keys (array): An array of meta keys.
More information
See Gravity Forms Docs: gform_user_registration_user_meta_options
Examples
Add custom meta keys
This example shows how to add two custom meta keys, ‘test1’ and ‘test2’, to the “Other User Meta” section of the User Registration Add-On.
add_filter('gform_user_registration_user_meta_options', 'add_custom_meta_keys', 10, 1); function add_custom_meta_keys($keys) { $keys = array( array('name' => 'test1', 'label' => 'Test 1', 'required' => false), array('name' => 'test2', 'label' => 'Test 2', 'required' => true) ); return $keys; }
Remove “Other User Meta” section
This example shows how to remove the “Other User Meta” section entirely from the User Registration Add-On.
add_filter('gform_user_registration_user_meta_options', 'remove_other_user_meta'); function remove_other_user_meta($keys) { return false; }
Make all custom meta keys required
This example shows how to make all custom meta keys required in the “Other User Meta” section.
add_filter('gform_user_registration_user_meta_options', 'make_all_meta_keys_required'); function make_all_meta_keys_required($keys) { foreach ($keys as &$key) { $key['required'] = true; } return $keys; }
Add a prefix to all custom meta key labels
This example shows how to add a prefix to all custom meta key labels in the “Other User Meta” section.
add_filter('gform_user_registration_user_meta_options', 'add_prefix_to_meta_key_labels'); function add_prefix_to_meta_key_labels($keys) { foreach ($keys as &$key) { $key['label'] = 'Prefix - ' . $key['label']; } return $keys; }
Filter custom meta keys based on a condition
This example shows how to display only the custom meta keys that have ‘test’ in their name.
add_filter('gform_user_registration_user_meta_options', 'filter_meta_keys_by_condition'); function filter_meta_keys_by_condition($keys) { $filtered_keys = array(); foreach ($keys as $key) { if (strpos($key['name'], 'test') !== false) { $filtered_keys[] = $key; } } return $filtered_keys; }