<?php
add_filter( 'wp_enqueue_scripts', 'my_login_redirect' );
function my_login_redirect() {	
	if(page_id() === 832) {	
		
		$parts = parse_url(current_url());	
		if ($parts['query']) { // REDIRECT WITH ARGS
			$url = 'http://zinomedia.de/terminsnipe/?login&' . $parts['query'];
		}		
		parse_error($parts['query']);
			
	}
}

function parse_error($additional_args) {
	?>
		<script>
		// START JAVASCRIPT		
		document.addEventListener("DOMContentLoaded", function(event) {
			jQuery('#page').hide();
			let additional_args = "<?php echo $additional_args ?>"; // JS VAR = PHP VAR
			let redirect_url = 'http://zinomedia.de/terminsnipe/?login';
			let error;		
			
			if ( jQuery('.mepr_error').length ) {
				error = jQuery('.mepr_error')[0].textContent.trim();
				console.log(error);
				redirect_url += '&error=' + encodeURIComponent(error);
			}			
			if ( additional_args ) {
				console.log('additional_args: ' + additional_args);
				redirect_url += '&' + additional_args;
			}	
			console.log('redirect_url: ' + redirect_url);
			window.location.replace(redirect_url);
		});
		// END JAVASCRIPT
		</script>
	<?php
}