Skip to content

Instantly share code, notes, and snippets.

@szbl
Forked from bmoredrew/utm redirect
Created December 14, 2012 17:22
Show Gist options
  • Save szbl/4287121 to your computer and use it in GitHub Desktop.
Save szbl/4287121 to your computer and use it in GitHub Desktop.
<?php
function utm_welcome_redirect() {
// redirect anyone that is not logged in to /welcome
if ( !is_user_logged_in() )
{
wp_redirect( site_url( '/welcome' ), 303 );
die;
}
else
{
// only redirect if user is NOT requesting an admin URL (requires password)
// and is not at the URL we want them to be at.
if ( !is_admin() && !empty( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] != '/' )
wp_redirect( get_bloginfo( 'wpurl' ), 303 );
// example to use if you want to simply keep them away from /welcome if logged in
/*
$uri = explode( '/', trim( $_SERVER['REQUEST_URI'], '/' ) );
if ( isset( $uri[0] ) && $uri[0] == 'welcome ')
wp_redirect( get_bloginfo( 'wpurl' ), 303 );
*/
die;
}
}
add_action( 'init', 'utm_welcome_redirect' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment