WordPress.org

Ready to get started?Download WordPress

Forums

Different users view different custom fields (selected by username) (2 posts)

  1. Andrew Wilson
    Member
    Posted 4 years ago #

    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

  2. Andrew Wilson
    Member
    Posted 4 years ago #

    Anyone?

Topic Closed

This topic has been closed to new replies.

About this Topic