Last active
May 17, 2025 13:12
-
-
Save yuriinalivaiko/0a804d322f7ff19fc2594a1e029ae8e7 to your computer and use it in GitHub Desktop.
Ultimate Member documentation. Article: Choices Callback and Parent Option features. Example: Three dropdown fields linked using the Parent Option setting.
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 | |
// Continent field. | |
function custom_continent_choices_callback() { | |
// choices array. | |
$options = array( | |
"africa" => "Africa", | |
"america" => "America", | |
"eurasia" => "Eurasia", | |
); | |
return array_unique( $options ); | |
} | |
// Country field. | |
function custom_country_choices_callback() { | |
// choices array. | |
$all_options = array( | |
"africa" => array( | |
"EG" => "Egypt", | |
"KE" => "Kenya", | |
), | |
"america" => array( | |
"CA" => "Canada", | |
"US" => "United States", | |
), | |
"eurasia" => array( | |
"FR" => "France", | |
"ES" => "Spain", | |
), | |
); | |
$parent = empty( $_POST['parent_option'] ) ? '' : sanitize_text_field( $_POST['parent_option'] ); | |
$options = ( $parent && array_key_exists( $parent, $all_options ) ) ? $all_options[ $parent ] : array(); | |
return array_unique( $options ); | |
} | |
// City field. | |
function custom_city_choices_callback() { | |
// choices array. | |
$all_options = array( | |
"EG" => array( | |
"Alexandria" => "Alexandria", | |
"Cairo" => "Cairo", | |
), | |
"KE" => array( | |
"Nairobi" => "Nairobi", | |
"Mombasa" => "Mombasa", | |
), | |
"CA" => array( | |
"Toronto" => "Toronto", | |
"Montreal" => "Montreal", | |
), | |
"US" => array( | |
"New York City" => "New York City", | |
"Los Angeles" => "Los Angeles", | |
), | |
"FR" => array( | |
"Paris" => "Paris", | |
"Marseille" => "Marseille", | |
"Lyon" => "Lyon", | |
), | |
"ES" => array( | |
"Madrid" => "Madrid", | |
"Barcelona" => "Barcelona", | |
), | |
); | |
$parent = empty( $_POST['parent_option'] ) ? '' : sanitize_text_field( $_POST['parent_option'] ); | |
$options = ( $parent && array_key_exists( $parent, $all_options ) ) ? $all_options[ $parent ] : array(); | |
return array_unique( $options ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to generate a Unique User ID from the details that users enter for State, Local Government, Ward, and their WordPress assigned ID.
Each Local Government has Local Government Name and Local Government Code.
Each Ward has Ward Name and Ward code.
For example, Abia State has Abia North as a Local Government, and the Local Government code is 01.
Abia North Local Government has many Wards, and two Wards are listed below with their Ward codes:
Eziama with Code 01.
Osusu with Code 02.
THE PROCESS
Use the Choices callback to auto-populate a Text field with the correct Local Government Code when a Local Government Name is chosen.
And also use the Choices callback to auto-populate a Text field with the correct Ward Code when a Ward Name is chosen.
On the Registration Form -- State, Local Government Name, and Ward name will be available and visible to the user.
But Local Government Code and Ward code will not be visible to the user on the Registration Form.
However, if someone selects Abia North as his/her Local Government, a Text field called "Local Government Code" will be auto-populated with 01.
And if they select Osusu as their Ward— a Text field called "Ward code" will be auto-populated with 02.
Then the system will add their WordPress assigned ID to generate the Unique User ID on Form Submission.
THE RESULT
The User ID will be: 01-02-18, gotten from:
Local Government: Abia North with code 01.
Ward: Osusu with code 02.
WordPress ID: 18
QUESTION
Please, how do I achieve this?
Special Regards.