0

I would like it if I'm logged in as an administrator can look at the profiles of all users if they are logged in as a subscriber, for example, "toni123456" Can I see only your profile "toni123456". This is a template domain/wordpress/author/user_name

1

Inside your template you can implement a condition checking if the user is a super admin or if the user has certain capabilities (if you want to target administrators and not only super admins)

First case

if (is_super_admin() ) {
    //your super admin logic here
}else{
    //subscriber logic
}

Second case

if ( current_user_can( 'manage_options' ) ) {
    //your admin logic here
} else {
    //subscriber logic
}

http://codex.wordpress.org/Function_Reference/is_super_admin

http://codex.wordpress.org/Function_Reference/current_user_can

Also here you can use this function to check user roles

http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/

UPDATE

An update according to op question

if(is_user_logged_in()){
    if ( current_user_can( 'manage_options' ) ) {
        //your admin logic here
    } else {
        $current_user = wp_get_current_user();
        $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));

        if($current_user->user_login == $curauth->user_login){
          // User is the same as author, show the panel
        }else{
          //different user and author, access forbidden.
        }
    }
}else{
    echo 'Access forbidden';
}
5
  • it will be fine just like I would have if sm logged in as "toni123" that you can only see the profile of "toni123" So my profile but not from another user Jul 22 '14 at 13:38
  • Sorry but I don't understand what you mean. With the code above you can check which type of user is logged in and act appropriate.
    – Laxmana
    Jul 22 '14 at 15:24
  • a list of username: 1: admin 2: toni123 3: miha123 each user on wordpress has its own profile mysite/wordpress/author/username Example1 > So I would like if I sign up as an example, a user with the username "toni123" if I go to mysite/wordpress/author/toni123 do I see my profile page if you go to mysite/wordpress/author/miha123 it I can write that I do not have access because I'm not an administrator. Example2 > if I'm logged in as "miha123" is just the opposite. Example3 > If I'm logged in as an administrator, I have access to all users Jul 22 '14 at 17:55
  • therefore: I need to add some code here *** if (current_user_can ('manage_options')) { / / your logic here admin }else { *** } Jul 22 '14 at 17:57
  • I made an update to my answer.
    – Laxmana
    Jul 22 '14 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.