Support » Plugins » Hacks » How to make a READ-ONLY field in User Profile? (here's my original code)

  • Hi I’ve created a custom field in my functions.php to the user profile.

    This field serve as a “registration” number and must be view only by the user in his profile and read-only except for an admin who is able to edit it.

    Here is a paste of the code i’m using. Can someone paste me a corrected version of what I need and explain how it work please?

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

Viewing 5 replies - 1 through 5 (of 5 total)
  • don’t they already have a “registration number” that’s built in and read only? i.e. $current_user->ID

    I explain: my site is private and registration is off. My users are salesrep and in this read-only field i want i will place a unique salesrep code. the connected user can see his code but can’t edit it. He must be the only one (except admin) to have acces to his code.

    Here is the Code i’m using.

    I would like someone to give me a corrected version to make it Read-Only to users but Read/write to Admins

    I’m still learning my PHP so Syntax and where to place what is a little confusing for me. So if someone would be kind enought to tell me why new code will be placed at that specific place i would be wore that happy


    You can try to disable the input field if the current user is NOT an admin (code not tested)…

    $disable_input = 'disabled="disabled"';
    if ( current_user_can( 'create_users' ) ) {  //<-- Only admins can create_users
    	$disable_input = '';
    <input type="text" name="jobpos" id="jobpos" value="<?php echo esc_attr( get_the_author_meta( 'jobpos', $user->ID ) ); ?>"
    class="regular-text" <?php echo $disable_input ?> />

    @johnnyn05 I’ll check that bit of code of you tomorow when i’ll be back to my programming.

    Thanx hope it’ll work. If so I’ll bo so darn happy loll

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to make a READ-ONLY field in User Profile? (here's my original code)’ is closed to new replies.