I was very happy with the above logic and just needed it slightly changed. Adding a !
before is_user_logged_in()
solved my issue completely and allowed me to do the logic in reverse.
/**********************************START*************************************
********** Redirect account page to login page if user is logged In *********
****************************************************************************/
add_action( 'template_redirect', function() {
if ( ! is_user_logged_in() || ! is_page() ) return;
$restricted = array( 4062, 4066 ); // all your restricted pages
if ( in_array( get_queried_object_id(), $restricted ) ) {
wp_redirect( site_url( '/account' ) );
exit();
}
});