• Hi,

    I’m looking for advice on how to hide custom fields depending on the user. I stumbled across some great advice here about how to hide based upon user levels:

    In WP 2.8.X you should be able to make these changes in “wp-admin/includes/template.php”. Take a look at the function “_list_meta_row” around line 2282. On line 2293 you should see something like this:

    if ('_' == $entry['meta_key'] { 0 })
    $style .= ' hidden';

    This is saying if there is an underscore character at the beginning of the meta key then hide it. Example would be “_customfield_price”. This is done because WP already has several custom fields it doesn’t want you to see and it designates them by putting an underscore at the beginning of their name. Depending on how detailed you want to get, modify line 2293-2294 to look something like this:

    global $userdata;
    get_currentuserinfo();
    $level = $userdata->user_level; //gets user level
    
    if ('_' == $entry['meta_key'] { 0 } || $level < 10 && 'customfield_discount' == $entry['meta_key'] )
    $style .= ' hidden';

    http://wordpress.org/support/topic/220905?replies=6#post-1193604

    This works fine, but: I have multiple admins, and would prefer to have some custom views ONLY editable/viewable by myself. Can anyone help with how to alter the ‘$level < 10’ to select based upon user names instead of admin level? Ideally excluding all user names apart from mine (for sake of argument, lets call my admin username ‘AWilson’).

    Much appreciated.

    Andrew

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Different users view different custom fields (selected by username)’ is closed to new replies.