EDIT
You are using auth_redirect();
, by default it checks if a user is logged in or not, so you don’t need to check again if a user is logged in or not
When this code is called from a page, it checks to see if the user viewing the page is logged in. If the user is not logged in, they are redirected to the login page. The user is redirected in such a way that, upon logging in, they will be sent directly to the page they were originally trying to access.
So you can just do
if ( ! is_page ( 6 ) ) {
auth_redirect();
}
EDIT 2
//If Role = Customer & Page Is ID 6 Then Redirect To Checkout
if ( user_can( $current_user, "customer" ) && ! is_page( 6 ) )
This is your code’s first two lines, check line one Page Is ID 6 and check line 2 ! is_page( 6 )
. Spot the difference?
Your code in line 2 says if the page ID IS NOT 6
EDIT 3
The script is being run from header.php and is the first thing in the PHP file
What do you mean the first thing in the php file. This will break you site. You will need to move this code to at least within the opening body tag (<body>
), where it should be
EDIt 4
Since we started, a few thing changed :-). Try to re-organise your sequence
//If Role = Customer & Page Is ID 6 Then Redirect To Checkout
if ( user_can( $current_user, "customer" ) && ! is_page( 6 ) ) {
wp_redirect(home_url().'/checkout');
exit;
}elseif ( user_can( $current_user, "member" ) && is_page( 6 ) {
// User role = member and Page ID is 6 redirect to home page
wp_redirect(home_url());
exit;
} elseif ( ! is_page ( 6 ) && !is_user_logged_in() ) {
//If Not Logged in & Page Is Not ID 6 then redirect to login
auth_redirect(); //Not sure if this will work.
}
?>