Restrict other users to access author page wordpress

I have custom author template in wordpress: mysite.com/author/john/ and I want to restrict access to this page so only john when he log in that can access this page not other users whether they log in or not.

Can someone help me with this?

Related posts

Leave a Reply

1 comment

  1. Try Below code..

    $logged_in_user_id = 0;
    // get author info 
    $user_info  = get_userdata($post->post_author); 
    $author_id  = $user_info->ID;   
    
    // get logged in user info 
    $user_logged_in = is_user_logged_in();
    $user_data = array();
    if($user_logged_in){ 
    global $current_user;
    get_currentuserinfo();          
    $logged_in_user_id = $current_user->ID;
    }
    
    // check the logged in user id is same as author id
    
    if($logged_in_user_id == $author_id ){
    
    // Show blog information...
    
    }else{
    
     // Show blog access denied message
    }