• Resolved aymanibrahim77

    (@aymanibrahim77)


    hello
    I am using add_filter( ‘um_registration_for_loggedin_users’, ‘__return_true’ );
    to let the logged in user can add new users

    want to add field in profile form and in the wordpress edit user page in the backend name (registered by)
    so if I open any user edit page or profile page I will find this field that will be filled by the username of the user who registered this user

    so please help to do this

    also need to know how to let the user who do the registration can select any of wordpress user roles for the new user
    regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Aswin Giri

    (@aswingiri)

    Hello @aymanibrahim77

    Please try this code snippet:

    add_action( 'um_user_register', function( $user_id, $args ){
        if(is_user_logged_in()){
            $current_user = get_current_user_id();
    
            if( $current_user != $user_id ){
                update_user_meta( $user_id,'registered_by', $current_user );
            }
        }
    },10,2 );
    
    add_action( 'show_user_profile', 'registered_by_user_profile_fields' );
    add_action( 'edit_user_profile', 'registered_by_user_profile_fields' );
    function registered_by_user_profile_fields( $user ) { 
        $registered_by = get_user_meta( $user->ID, 'registered_by', true );
        if( $registered_by ):
        ?>
        <table class="form-table">
        <tr>
            <th><label for="address"><?php _e("Registered By", "ultimate-member"); ?></label></th>
            <td>
                <?php
                    $by_user = um_fetch_user( $registered_by );
                    echo '<a href="'.um_user_profile_url($by_user).'">'.um_user('display_name').'</a>';
    um_reset_user();
                ?>
            </td>
        </tr>
        </table>
    <?php 
    endif;
    }

    The above code snippet will add user meta if the account was registered when the user was logged in and adds a “Registered by” information on the WordPress edit user screen with the link to the user profile of the user who registered the account.

    Thread Starter aymanibrahim77

    (@aymanibrahim77)

    Dear @aswingiri Thank you very much for the code it work 100%
    best regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘to to add registered by field’ is closed to new replies.