• Resolved webnik

    (@noisedude)


    Hi folks, I have a site set to private right now – pgslearning.co.uk/art/ – and users log in using a common subscriber account.

    When they log in though, they get sent to the dashboard/profile section. I just want them to be redirected to the home page of the site.

    I’m using a custom login screen plugin – can I add some code to that? I have to replicate this behaviour over 20-30 sites so I’d prefer to do it in a plugin so that I can copy the files over.

    Users must NOT be able to change the profile email address and I’d really rather they weren’t presented with site backend at all. There are no links in my sidebar or anywhere else on the pages, editors know the URL to log in manually, everyone else just needs to put in a password and then hit the homepage.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You might take a look at Peter’s Login Redirect. Does everything you need. If you’re code savvy, then you might just use the bits you need, and add them to your existing plugin. I’d pay attention to the redirect_per_user portions.

    Thread Starter webnik

    (@noisedude)

    Brilliant, thank you. I can’t immediately figure out the URLs …. can I just enter the the web address of the homepage or do I enter something internal to tell it to go to the front of the site?

    Go to Settings > Login redirects, and then enter your information. From what you’re saying, you’ll most likely use the “Specific User” form. Choose the user from the dropdown, put the redirect to URL in the blank.

    Since last night, I found out how to do this without the plugin. There are two ways:

    1) If the only people that are using the custom login screen at pgslearning.co.uk/art/, are the ones that share the subscriber account, then you can change the action link of your form to:

    action="https://pgslearning.co.uk/art/wp-login.php?redirect_to=/art/

    I saw that you have added the redirect query string to the link on the page, but you can remove this and the redirect will fail. Adding it to the action form will force it to work everytime. However, like I said, only use it if the subscriber account is the only one logging in there, because otherwise all users will be redirected.

    2) The second method is the most fool-proof, and doesn’t require the plugin. Like the plugin, it also lets you tie the redirect to a specific user. Just change 'admin' to the shared subscriber username, and '/art/' to wherever you want them redirected.

    function redirect_user_to( $redirect_to, $user ) {
    	global $user;
    
    	if ( $user->user_login == 'admin' ) {
    		$redirect_to = '/art/';
    		return $redirect_to;
    	}
    
    	return $redirect_to;
    }
    add_filter( 'login_redirect', 'redirect_user_to', 10, 3 );

    You can add this code to your functions.php, you can make it a plugin, you can even post it in your custom login plugin (assuming you wrote it yourself otherwise updating would be a pain).

    Hope this helps.

    Thread Starter webnik

    (@noisedude)

    Finally getting back to sorting this out now. I’m about to start putting some of this advice into practice and seeing what works.

    One thing though – the redirect in the URL at the moment is coming from the plugin I’m using which is called Authenticator.

    Can I modify the plugin OR make it a custom one OR (ideal option I think) remove the redirect instruction safely AND add the code from the previous post to my functions.php?

    The Authenticator plugin code is as follows … I can see the line that redirects (can I just take that whole line out??) but for the reasons stated before, it’s too easy to work around and I need something more robust.

    if (!class_exists('Authenticator')) {
    	class Authenticator {
    
    		function fb_authenticator_redirect() {
    			// Checks if a user is logged in, if not redirects them to the login page
    			if ( !is_user_logged_in() ) {
    				nocache_headers();
    				header("HTTP/1.1 302 Moved Temporarily");
    				header('Location: ' . get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
    				header("Status: 302 Moved Temporarily");
    				exit();
    			}
    		}
    
    		function Authenticator() {
    			global $pagenow;
    
    			if ('wp-login.php' != $pagenow && 'wp-register.php' != $pagenow)
    				add_action( 'template_redirect', array($this, 'fb_authenticator_redirect') );
    		}
    
    	}

    Thread Starter webnik

    (@noisedude)

    Addendum – I resolved this with the plugin called ‘WP Block Admin’, which boots my subscriber account straight back to the front page of the site even if they enter the pgslearning.co.uk/art/wp-admin/ URL manually.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Subscribers – hide profile/dashboard and redirect’ is closed to new replies.