WordPress.org

Ready to get started?Download WordPress

Forums

Welcome Visitor plugin fails userlevel test (4 posts)

  1. j8h9
    Member
    Posted 7 years ago #

    Installed the welcome-visitor plugin. When I go to options->Welcome I get an error msg indicating not authorized. I found on the plugin blog some fix to the code. The fix says to remove the following check:

    global $user_level;
    if ($user_level < 8)
    die($no_access_msg);

    $user_level is null. To fix, I could comment out but I'd rather convert it to the new capabilities/roles.

    So how do I check for admin authority? I've been reviewing the capabilities.php file and am just not very familiar with the oops nomenclature. I tried this: $role = get_role('administrator'); but can't seem to reference the var? An associative array is returned? When I echo I get resource #3 so I know I'm not referencing it properly.

    All I need is a couple lines of code to determine whether user is admin... Thanks to all.

  2. stormerider
    Member
    Posted 7 years ago #

    Off the cuff code, but should at least point you in the right direction:

    global		$user_ID;
    
    $isAdmin	= 0;
    $meta		= get_usermeta($user_ID, 'wp_capabilities');
    
    if (is_array($meta) && $meta['wp_capabilities']) {
    	$capa	= unserialize($meta['wp_capabilities']);
    	if ($capa['administrator']) {
    		$isAdmin	= 1;
    	}
    }
  3. j8h9
    Member
    Posted 7 years ago #

    Outstanding. Thank you for speedy response. I'm beginning to love wordpress.

  4. howbowers
    Member
    Posted 7 years ago #

    You can fix this without altering any code.

    1. Go to the Users page
    2. Select your user ID
    3. In "Update Selected" area, click "Set the Role of checked users to" and select "Administrator" from the pop-up menu
    4. Click the "Bulk Upadate" button.

    This also fixed my problem with the Related Posts plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic