• Resolved polymathy

    (@polymathy)


    I want to add an extra field (Field for Mr/Mrs) in the profile area. That field will be specified during registration, but I want to give the user the ability to change it in his profile afterwards.

    I tried editing the “Default Profile” form under settings > forms, but that didn’t do anything. So how do I do this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Towhid

    (@cryptex_vinci)

    Thread Starter polymathy

    (@polymathy)

    This does not work, because no normal form is displayed on the profile page. The profile page that the plugin created after installation had this shortcode in it:
    [ultimatemember_account]

    It’s not a normal form that you can edit in the form editor, right?

    Edit: I figured it out. It seems I can do it with this code:
    https://hookr.io/filters/um_account_secure_fields/

    • This reply was modified 4 years ago by polymathy.
    • This reply was modified 4 years ago by polymathy.
    • This reply was modified 4 years ago by polymathy.
    Thread Starter polymathy

    (@polymathy)

    The only problem with above code is, that even though I get the field I desired, I can’t save the field. Saving doesn’t seem to work.

    Thread Starter polymathy

    (@polymathy)

    The solution from the link above doesn’t seem to work anymore. So I used this solution:
    https://www.champ.ninja/2020/05/add-a-custom-account-tab-with-profile-form-fields/#comment-35

    Now I have a custom tab on my profile page where can add my own profile form. I used the default fields user_login, first_name, last_name, user_email as well as my own custom field user_title.

    The problem now is, user_login and user_email don’t show up in my form. What could be the reason for this? Also when I click save, I get the error message “This is not possible for security reasons”. I already checked for any plugin/theme compatibility issues, but there are none.

    Thread Starter polymathy

    (@polymathy)

    I finally figured out how it works. So if anyone else has the same issue, I added the following code, which I found in this thread:

    /**
     * Add extra fields to user account tab
     */
    function showUMExtraFields()
    {
        $id = um_user('ID');
        $output = '';
        $names = array('gender', 'therapy_center');
    
        $fields = array();
        foreach ($names as $name)
            $fields[$name] = UM()->builtin()->get_specific_field($name);
        $fields = apply_filters('um_account_secure_fields', $fields, $id);
        foreach ($fields as $key => $data)
            $output .= UM()->fields()->edit_field($key, $data);
    
        echo $output;
    }
    
    add_action('um_after_account_general', 'showUMExtraFields', 100);
    
    /**
     * Get content for extra fields in user account tab
     */
    function getUMFormData()
    {
        $id = um_user('ID');
        $names = array('gender', 'therapy_center');
    
        foreach ($names as $name)
            update_user_meta($id, $name, $_POST[$name]);
    }
    
    add_action('um_account_pre_update_profile', 'getUMFormData', 100);

    You can also use this for custom fields, that are not from the default set of fields. You will have to create the field and then use the meta key you specified in the form editor.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @polymathy

    Thanks for letting us know how you resolve the issue. I am closing this thread now.

    Regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How Do I Add an Extra Field in the User Profile Area?’ is closed to new replies.