I'm looking to create a 'Last Updated' field in a user's profile. I was then going to create a rule that filled that field with the current date everytime the user's profile was edited. I want the information for admin purposes and don't want the user to see this info.

Is this possible? I'd prefer not to use a module.

EDIT: I would be fine with the field being on the user-edit page instead (but still hidden) if that's easier.

3 Answers 3


I recently needed something similar and ended up pre-processing some of the details in template.php and then rendering the output in user-profile.tpl.php. What I did was like this:

function MYTHEME_preprocess_user_profile(&$variables) {

// check if current user has role 'Administrator'


    if ($variables['user']) { 
        foreach($variables['user']->roles as $key => $role) { 
            $variables['classes_array'][] = $role;

    if(in_array($ok_role,$variables['classes_array']) {
    } else {

// etc...


This gives me an extra variable that's TRUEfor admins and falsefor everybody else. I did then check the fields user-profile.tpl.php accordingly similar to this:

<?PHP if(($profile_updated)&&($visiblebyrole)) { ?>
    <div class="updated"><?PHP print($profile_updated); ?></div>
<?PHP } ?>

You could probably improve the code structure, but for me it worked.


Is this possible?

Yes, but not out of the box with Drupal.

I'd prefer not to use a module.

Not an option unfortunately, you need either a contrib or custom module to make this happen. You could theoretically do it in the theme, but that logic doesn't belong there.

Field Permissions is the go-to module for this.

Ah, just noticed your edit.

If you want the field to simply not be rendered, but you're happy for it to exist in the edit form, you can override the user-profile.tpl.php template in your theme, and just hide the field there:

<?php hide($user_profile['foo']); ?>

Or just hide it through the UI at admin/config/people/accounts/display if that works for your scenario.


This works for D7. You have to do it by a custom module, replace MYMODULE with your module name and field_YOUR_FIELD with your field name. It will not hide it for admin user

//implement function form_alter

      function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
        global $user;
        $uuid = $user->uid;

  /*  check that user is NOT admin (No1) */
    if ($uuid !='1') {        
        //if form id is user_profile_form --> hide fields
         if ($form_id=='user_profile_form') {              

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.