How to Hide User Profile from Other Users?

You can use the following code snippet to hide user profile from other users. 

In other words, when implemented, the given code snippet will ensure that only the currently logged-in user can see their profile, and nobody else. As such, viewing "others' profiles" will no longer be possible. 

Hiding User Profile from Other Users

We recommend using the Code Snippets plugin for adding code snippets to your site. 

add_action('template_redirect', 'template_redirect_cb', 9);

function template_redirect_cb(){
	global $post;
	if ( ! is_page() ) {
		return false;
	}
	if ( uwp_is_page_builder() ) {
		return false; 
	}
	$current_page_id = isset($post->ID) ? absint($post->ID) : '';
	$uwp_page = uwp_get_page_id('profile_page', false);
	if ( $uwp_page && ((int) $uwp_page ==  $current_page_id ) ) {
		$user = uwp_get_user_by_author_slug();
		if ( !(is_user_logged_in() && $user && $user->ID == get_current_user_id()) ) {
			wp_redirect( home_url() );
			exit();
		}
	}
}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.