• Resolved bipolab

    (@bipolab)


    Hello,

    I would like to use your plugin to allow admins to add members via front-end. In other words, admin must have access to a pw-protected page from where they can add new users.

    is it possible?

Viewing 11 replies - 1 through 11 (of 11 total)
  • @bipolab

    Yes it’s possible if you enable the Registration form for logged-in users
    with the following code snippet:

    add_filter( 'um_registration_for_loggedin_users', '__return_true' );

    Add the code snippet to your active theme/child-theme’s functions.php file
    or use the “Code Snippets” plugin.

    https://www.ads-software.com/plugins/code-snippets/

    Thread Starter bipolab

    (@bipolab)

    Thank you!
    It worked… I have few more questions but I’ll ask them in separate topics so to be more helpful for other users

    Thread Starter bipolab

    (@bipolab)

    Even if the topic is closed, I would add a question down here…

    Since several admins will add users this way (front-end), I’d need to retrive their username/mail from the form and I would use it as a filter/sorting criteria.

    It could be used in an autofilled text field (no matter if editable or not or even hidden).

    In few words, I would like to have the ability to show all and only the users registered by [email protected] or by [email protected]

    @bipolab

    With a meta_key “user registered by” you can use the UM Members Directory for your listing of users by each User Administrator.

    Thread Starter bipolab

    (@bipolab)

    Thank you for such a prompt reply!!
    I really appreciate it ??
    However I’m afraid I’ve not understood something.
    Should I add a text field that must be filled from the admin each time?

    (I was wondering instead if I could populate the text field with a shortcode instead… a shortcode for a wp_get_current_user() function, without the need for the admin to fill it)

    @bipolab

    Yes you can use this code snippet for the “user registered by” field.

    add_action( 'um_registration_complete', 'um_110821_user_referral', 1 );
    
    function um_110821_user_referral( $user_id ) {
    
        $referer_id = get_current_user_id();
        update_user_meta( $user_id, "um_user_referral", $referer_id );
    }
    Thread Starter bipolab

    (@bipolab)

    Hello Missveronica, thanks for taking the time to reply me back.
    I’ve added a text field in registration form with the name “user registered by” (meta key can’t have spaces so…)
    And I’ve set this field to be shown in members directory.
    I’ve added the provided code into functions.php

    but nothing happens.
    I’ve trying both writing something in “user registered by” field and leaving it blank during registration but without success.

    I’m sure I’m missing something or maybe I’ve not explained myself correctly ??

    @bipolab

    The meta_key in the code snippet is um_user_referral and contains the user ID of the admin doing the Registration.

    You must define a text field with this meta_key but the user ID value is inserted by the code snippet during the user registration update to the DB.

    Thread Starter bipolab

    (@bipolab)

    Got it.
    THANK YOU VERY MUCH!!!!!!

    Since I need the username instead of the ID I’ve changed the code this way:

    add_action( 'um_registration_complete', 'um_110821_user_referral', 1 );
    
    function um_110821_user_referral($referer_name) {
    $current_user = wp_get_current_user();
    $user_name = $current_user->user_login;
    update_user_meta( $referer_name, "um_user_referral", $user_name );
    }

    And I’ve seen that I can add its email field too, with its meta_key.
    In the following example, I’ve used um_mail_referral as meta_key (for a text field… mail field will be used for other purposes and there is no more of them available ) and I’ve changed the name of the action. (Maybe there’s a way to do it faster and smarter but it works)

    add_action( 'um_registration_complete', 'um_88046_mail_referral', 1 );
    function um_88046_mail_referral($referer_mail) {
    $current_user = wp_get_current_user();
    $user_mail = $current_user->user_email;
    update_user_meta( $referer_mail, "um_mail_referral", $user_mail );
    }

    BTW, is there a way to cleanup the meta_keys used in deleted field? They still appears in members directory…

    I’m going to see if I can hide those text field too!

    Again: Thank you!

    @bipolab

    BTW, is there a way to cleanup the meta_keys used in deleted field? They still appears in members directory…

    Here is an UM guide where one step is to delete a Form field:

    https://docs.ultimatemember.com/article/1784-how-to-convert-text-box-field-to-textarea-field

    Update of the code snippet:

    add_action( 'um_registration_complete', 'um_110821_user_referral', 1 );
    
    function um_110821_user_referral( $user_id ) {
    
        global $current_user;
        
        update_user_meta( $user_id, "um_user_referral_id", $current_user->ID );
        update_user_meta( $user_id, "um_user_referral_login", $current_user->user_login );
        update_user_meta( $user_id, "um_user_referral_email", $current_user->user_email );
    }
    • This reply was modified 1 year, 10 months ago by missveronica.
    Thread Starter bipolab

    (@bipolab)

    Thank you!
    I’ll follow your suggestions.

    Great job!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘User added by admins only’ is closed to new replies.