PHP Redirects



function getUrl() {
  $url  = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] :  'https://'.$_SERVER["SERVER_NAME"];
  $url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
  $url .= $_SERVER["REQUEST_URI"];
  return $url;
}


function redirect_non_admins() {

	if ( current_user_can('administrator')) { return; }

	$this_url = getUrl();
	
	$url = parse_url($this_url); 
	
	$new_url = 'https://whateversiteyouwant.com/'.$url['path'];
	
	wp_redirect( $new_url );


}

add_action('template_redirect','redirect_non_admins');


Comments