Give access to only two (/home, /inbox) page for a particular user with specific role in wordpress

Solution:

The main issue the way I tried to get the page slug, the correct way to get the slug is “$post->post_name”. also I put exit after wp_safe_redirect as well because codex suggest that:

function vendor_redirect() {
   global $post;
   if(current_user_can('Vendor') && !in_array($post->post_name,array("home","inbox"))) {
      wp_safe_redirect(get_permalink(get_page_by_path( 'inbox' )));
      exit;
   }
}
add_action('template_redirect', 'vendor_redirect');