Forum Replies Created

Viewing 2 replies - 16 through 17 (of 17 total)
  • Here is my client re-direct template page. Just set the main client page to this template, re-direct all users with the role of ‘Client’ to this page, and you’ll be all set.

    Note: If you are the user ‘admin’, you will see a list of links to all of your client pages. If not, you will be automatically re-directed to the client page that corresponds to the username that is logged in. There are handlers in here as well for other logging-in user scenarios.

    <?php
    /*
    Template Name: _ClientRedirect_DONOTUSE
    */
    ?>
    
    <?php 
    
    $username = ( $userdata->user_login ) ?>
    
    <?php 
    
    if (current_user_can( 'level_10' ) || is_user_logged_in())  {
    	if($username == "admin"){
        	//list all client pages
    		get_header();
    		include("breadcrumb.php");
    		echo '<div><h1>Client Pages</h1><ul>';
    		wp_list_pages('title_li=&child_of=60&title_li=');
    		echo '</ul></div>';
    	}
    	else{
    		//user is loged in so re-direct to their page
    		header('Location:https://www.mydomain.com/clients/' . $username);
    	}
    
    } elseif ( is_user_logged_in()==false ) {
    	//user not logged in so re-direct to login page
    	header('Location:https://www.mydomain.com/wp-admin/');
    
    } elseif ( is_user_logged_in() && $username!=$shorttitle ) {
    	//user logged in - redirect to their page
    	header('Location:https://www.mydomain.com/wp-admin/');
    
    } 
    
    ?>

    This is fantastic. Worked like a charm.

    One minor enhancement: I set the “Clients” parent page up as a re-direct page. Then I set “Peter’s Login Redirect” plugin to redirect all users that have the “Client” role to that page after login. When any client log sinto the site now, they automatically get re-directed to their specific page. This circumvents the need to redirect each user to their specific page in the re-direct plugin.

    Well done. Saved me loads of time.

Viewing 2 replies - 16 through 17 (of 17 total)