• Resolved Scotty501

    (@scotty501)


    Hi All.

    I am struggling to find a clean solution to this. I want to add unique numbers (membership) to each users profile. I have tried many plugins which allow you to add extra fields – but I dont want it to be edited by the user or populated manually or need a full blown membership plugin – the standard roles are fine.

    I thought the easiest way would be to add the User ID to the profile page where its populated automatically on admin approval of registration – but I am not savvy enough to make it work.

    Any ideas or tips – much appreciated.

    [No bumping. If it’s that urgent, consider hiring someone.]

Viewing 8 replies - 1 through 8 (of 8 total)
  • hello scotty501

    Did you ever resolve this? I too want this function but I dont know how. Could you share how you did it?

    To show the ID number of any author, paste this into the loop of a post, page or CPT of the author/user in questions.

    <?php
    $user = get_userdata($post->post_author);
    echo the_author_meta( 'ID' )
    ?>

    Thread Starter Scotty501

    (@scotty501)

    Thanks for the response Ape (great name).

    Its not really an author info in a post as such I am trying to show – just want to insert some kind of membership number or any unique number for that matter into the User Profile – the user ID seemed a good place to start.

    I can easily add an extra field using a plugin but all seem to be user based – where I want the number to be automatically assigned – and as USER ID is automatically assigned – it works well for the purpose – and cannot be changed – perfect. If I could get it to display as a field within the profile.

    Make sense or have I just confused the world ??

    This might work for you…

    add_action( 'show_user_profile', 'extra_profile_fields' );
    
    	function extra_profile_fields( $user ) { ?>
    
    		<table class="form-table">
    
    			<tr>
    				<th><label>Profile/User ID</label></th>
    
    				<td>
    					<input type="text" name="uuid" id="uuid" value="<?php $user = get_userdata($post->post_author); echo the_author_meta( 'ID' ) ?>" class="regular-text" readonly />
    				</td>
    			</tr>
    		</table>
    		<?php }

    Please note, I’ve not tested or checked the code.

    Paste it into your function.php template file if you have one.

    Thread Starter Scotty501

    (@scotty501)

    Ah man that almost worked – it placed the extra field in there – but it shows “0” in the box – instead of the true user ID – other than that – it would appear to the be right way to go – it shows “0” regardless of which user profile I look at.

    If I could fix that part – I am where I want to be.

    No promises, as I’ve not tested it, but you can try this…

    $user = get_userdata($post->post_author);
    add_action( 'show_user_profile', 'extra_profile_fields' );
    function extra_profile_fields( $user ) { ?>
    
    	<table class="form-table">
    		<tr>
    			<th><label>Profile/User ID</label></th>
    			<td>
    				<input type="text" name="uuid" id="uuid" value="<?php echo esc_attr( get_the_author_meta( 'ID', $user->ID ) ) ?>" class="regular-text" readonly />
    			</td>
    		</tr>
    	</table>
    
    <?php }
    Thread Starter Scotty501

    (@scotty501)

    That worked perfectly! Thank you so much.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding User ID to profile page?’ is closed to new replies.