I've been banging my head against the wall for the last little bit and could really use some help. I'm rather new to PHP and I'm sure this isn't too complicated but I just can't seem to get the behavior I need so I'm reaching out.
Basically I have a client whose doing a limited launch of their service and would like to create a custom login page they can share with early adopters. So basically what I need is the following:
When a user navigates to the site I first need to check if it's the register URL (www.example.com/selected-customer/register/). If this is true I want to redirect to the register page.
Next I want to check if this URL is any URL other than my default 'Coming Soon' page. If it is not the coming soon page I then need to check if the user is logged in. If they are not logged in I want to redirect them to the 'Coming Soon' page if not I want to render the page requested. I've tried to code a sample but it's not doing what I need it too.
Any help would be greatly appreciated :)
Sample Code:
add_action( 'template_redirect', function() {
if( ( !is_page('coming-soon') ) ) {
if( ( is_page('register') ) ) {
wp_redirect( home_url( '/captains-crew/register/' ) ); // redirect all...
exit();
}
if (!is_user_logged_in() ) {
wp_redirect( home_url( '/coming-soon/' ) ); // redirect all...
exit();
}
}
});
I didn't try yet but would work.
add_action( 'template_redirect', function() {
if(is_page('register'))
{
wp_redirect( home_url( '/captains-crew/register/' ) );
exit;
} elseif (!is_page('coming-soon') && !is_user_logged_in() ) {
wp_redirect( home_url( '/coming-soon/' ) );
exit;
}
});