• Resolved tcumpston

    (@tcumpston)


    I want to display different images based on the user’s role. I’m trying to use if( get_role(‘subscriber’) but to no avail. Can you point me in the right direction?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tcumpston

    (@tcumpston)

    I changed to current_user_can(“role-a”) and it sort of works. I have 3 rows with 3 different images.

    The first row has !is_user_logged_in() and that image shows when the user is not logged in. WORKS PERFECT.

    The second row has current_user_can(“role-a”) and that image shows when the user’s role is role-a. WORKS PERFECT.

    The second row has current_user_can(“role-b”) and that image shows when the user’s role is role-b. CURRENTLY SHOWS THE IMAGE FOR A AND B.

    Plugin Author Jonathan Horowitz

    (@jhorowitz)

    Checking roles in this way is deprecated in WordPress. Try using a capability instead of a role name in current_user_can().

    If you must use roles, define this function in your theme’s functions.php:

    function current_user_has_role( $role ) {
    	$user = wp_get_current_user();
    	return $user->exists() && in_array( $role, $user->roles );
    }

    Then use that function instead of current_user_can().

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Test user role’ is closed to new replies.