• Resolved satyriasis66

    (@satyriasis66)


    Is there a way to show a module based on a user role?

    For example, I would like to show one module only to administrators, and other only to translator users. What expression shoulf I use?

Viewing 1 replies (of 1 total)
  • Plugin Author Jonathan Horowitz

    (@jhorowitz)

    Hi @satyriasis66,

    Try using current_user_can() with a capability instead of a role name.

    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 1 replies (of 1 total)
  • The topic ‘Display based on user role’ is closed to new replies.