As Gael mentioned, there's not native WordPress functionality to handle this, but it's not too difficult to achieve.
update_post_meta( $post_id, 'post_subscriber', $user_id );
First, I would create post meta that identifies the user who should have access. You would probably want to set this up with Meta Boxes on the individual pages or using the Settings API. If you have multiple users that need access to the same page, you may want to set this up as User Meta instead which would flip the code below a bit on its head.
Since we're doing 1 user accesses 1 page, the post meta should work fine.
Next, you need to determine whether you want to hide the content of the page only or pretend the page doesn't exist at all. Pick one of these two, not both.
1. Hide the content
We'll filter the page's content, leaving everything else accessible (like the title, featured image, etc. You can replace the content with a message informing the visitor that they're not allowed to see this content, "Nope!" It's a good practice to include a login form along with your message in case the user just forgot to log in ahead of time.
function my_filter_content( $content ) {
global $post;
if ( empty( $post ) || ! is_page() ) {
return $content;
}
$post_subscriber_id = get_post_meta( $post->ID, 'post_subscriber', true );
if ( ! $post_subscriber_id ) {
return $content;
}
$user = wp_get_current_user();
if ( $user->ID === $post_subscriber_id || user_can( $user->ID, 'administrator' ) ) {
return $content;
} else {
// Content restricted message.
return 'Nope!';
}
}
add_filter( 'the_content', 'my_filter_content', 11 );
2. Redirect the page
Instead of allowing anything to be seen by unauthorized users or the public, this action redirects unauthorized users to a completely separate page where they can be informed they tried to access something by mistake. It's usually a good practice to include a login form on this page in case the user has access, but forgot to log in.
function my_page_template_redirect() {
// Conditions for targeting the correct content type.
if ( is_page() ) {
global $post;
$post_subscriber_id = get_post_meta( $post->ID, 'post_subscriber', true );
// Now we know this page has restricted content.
if ( $post_subscriber_id ) {
// Check user is logged in.
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
// Check user is allowed access.
if ( $user->ID === $post_subscriber_id || user_can( $user->ID, 'administrator' ) ) {
return;
}
}
// Redirect user to page explaining why they can't see the content.
wp_safe_redirect( home_url( '/access-denied/' ) );
die;
}
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );