• I tried to Callback UM Roles in Role Dropdown, but get some issue.

    What I did ?

    • Add “Role Dropdown” in Registration Form
    • Add callback : role_select_choices_callback
    • Add Parent Option ( Parent option is a dropdown with options : Membre de bureau, Bienfaiteur & Entreprise)
    • Added this code to my Function.php :
    function role_select_choices_callback( $has_parent = false ) {

    // choices array.
    $all_options = array(
    "Membre de bureau" => array(
    "Direction" => "Direction"
    ),
    "Bienfaiteur" => array(
    "Etudiant" => "Etudiant",
    "Bienfaiteur" => "Bienfaiteur"
    ),
    "Entreprise" => array(
    "Donnateur" => "Donnateur",
    "Sponsor" => "Sponsor"
    ),
    );

    // get values from the parent field, sent via the AJAX post.
    $parent_options = isset( $_POST['parent_option'] ) ? $_POST['parent_option'] : array();
    if ( ! is_array( $parent_options ) ) {
    $parent_options = array( $parent_options );
    }

    // get related options for the parent field choice.
    $arr_options = array();
    if ( empty( $parent_options ) ) {
    foreach ( $all_options as $k => $opts ) {
    $arr_options = array_merge( $opts, $arr_options );
    }
    } else {
    foreach ( $parent_options as $parent_option ) {
    if ( isset( $all_options[$parent_option] ) ) {
    $arr_options = array_merge( $arr_options, $all_options[$parent_option] );
    }
    }
    }

    // Optional. Display this if there are no related options for this choice.
    if ( empty( $arr_options ) ) {
    $arr_options[] = 'No role found';
    }

    return array_unique( $arr_options );
    }

    After checking Console I found this error :

    Uncaught TypeError: Cannot read properties of undefined (reading 'default')
    at d (um-scripts.min.js?ver=2.8.8:1:10530)
    at Object.success (um-scripts.min.js?ver=2.8.8:1:11647)
    at c (jquery.min.js?ver=3.7.1:2:25304)
    at Object.fireWith [as resolveWith] (jquery.min.js?ver=3.7.1:2:26053)
    at l (jquery.min.js?ver=3.7.1:2:77782)
    at XMLHttpRequest.<anonymous> (jquery.min.js?ver=3.7.1:2:80265)

    To make sure callback and parent options works good:

    I added a simple Dropdown with the same settings (callback + Parent Option) and it works fine. But it can’t register user with the choosen Role.

    System Info :

    • PHP : 8.1
    • All plugins are updated

  • You must be logged in to reply to this topic.