• I have had a really good look around this site and many others, and I haven’t worked out this issue yet.

    Rather than modify the core code as I have done in the past I am now developing some of my hacks into plugins.

    One such simple function is redirection on login to homepage, which works perfectly fine with the following code bundled into a plugin (credit to WP community, not sure where I got this from!)

    <?php
    function MCMSlogin_redirect () {
    global $redirect_to;
    if ( ! current_user_can('edit_posts') )
    $redirect_to = get_option('home');
    }
    add_action('wp_authenticate', 'MCMSlogin_redirect');
    ?>

    So, when wp_authenticate runs it sends the user back to the homepage rather than straight to the dashboard.

    However, I don’t seem to be able to do this with logout. I have done some research and have tried using wp_logout – but further research has told me that ‘this is an action that is fired when a user is logging out and executes just after wp_clearcookie() runs and before the user is redirected’ – which is obviously not going to do what I want!

    I have also had a look at ‘loginout’ – but can’t really find any documentation on this.

    Does anyone have any ideas on how to re-direct on logout?

    I know there are a couple of plugins that do this, but I am really trying hard to learn about WP and would love to see one of you code ninjas come up with a solution to this simple problem I am having!

Viewing 9 replies - 1 through 9 (of 9 total)
  • All i done is change the redirect to

    do_action(‘wp_logout’);

    $redirect_to = ‘redirect.php’;

    Then in redirect.php i put

    <?
    header (“Location: https://mydomain.com/index.php&#8221;);
    ?>

    Thread Starter ninjaboy

    (@ninjaboy)

    Humph – I see how this would work but I’d prefer not to have to create another file (eg redirect.php in your example).

    I just need to work out which action to use for the logout redirection variable.

    Hello,

    I use two plugins working together to acheive a sophisticated login and redirect.
    Redirect Login

    and

    Themed login

    The result is clients can login on my front page, and are simply redirect into the client area of my website, without ever seeing the dashboard!

    d

    Thread Starter ninjaboy

    (@ninjaboy)

    artfulalibi – yup, I have had a look at both of those plugins. Themed login overides some of the core WP finctionality, so I’m not so interested in that one. You can actually achieve something very similar WITHOUT compromising the updates rolled out to WP if you know what you are doing with templates.

    Redirect Login is interesting, but I couldn’t get it working right (WP v2.1.3)

    Really I was just trying to understand how to hook into the logout process, just like I have done for the login process in my example above, which I bundled into a simple plugin.

    Simply put – how do I redirect on logout, without hacking the core code. I’m tired of having to apply my hacks everytime a new update of WP is released!

    Thread Starter ninjaboy

    (@ninjaboy)

    …just to make it clear, I want to bundle this function into a little plugin, rather than use someone elses code, I am trying to lift the lid on these WordPress Actions so I can learn more about the platform and PHP.

    Thread Starter ninjaboy

    (@ninjaboy)

    No clues then on re-directing on logout?? I’m tearing my hair out trying to work this one out!

    Thread Starter ninjaboy

    (@ninjaboy)

    Despite all my experimenting I still have not found out how to do this without modifying the core code. Modify redirect on login – yup, no problem (as shown in the example above) modify redirect on logout – I’d image would have worked the same but I can’t for the life of me work it out!!

    This seemed to get resolved (I think) in this:

    https://trac.www.ads-software.com/ticket/1239

    I am using WP2.1.3 install for testing this by the way. Why can’t I get $redirect_to to work with logout?

    tov3 your solution fixed my logout issues. Thank you so much. You cant even see the redirect page it loads so fast back to the index and im even on dialup!

    I used a combo of the login form i found on here a few bits here and a few there and now i have it when a user logs in the stay on the index page and when they logout they redirect back to the index page. works good for me and no plugin needed.

    Yep. I know it was five months ago, but t0v3’s solution is absolutely spot on. Perfect, in fact.

    If anyone’s reading this who wants a little more info about the solution, here’s how I implemented it:

    wrote this file in dreamweaver:

    <?
    header ("Location: https://mydomain.com/index.php");
    ?>

    Saved it as redirect.php and uploaded it to my theme folder (it doesn’t matter where you upload it, just as long as you can find it when you need it – see below)

    Then I went to my cPanel and modified the file called

    wp-login.php

    Only one line needed changing and that was line 78.

    t0v3 recommended changing it to:

    $redirect_to = 'redirect.php';

    But this will only work if you uploaded the file redirect.php to your root folder. I saved it my theme folder, so I had to stipulate the following directories:

    /wp-content/themes/stitched-10/redirect.php

    so line 78 looked like this:

    $redirect_to = 'https://www.mydomain.net/wp-content/themes/stitched-10/redirect.php';

    (that should all be on one line.)

    and then it worked!

    No hassle. No messing around in the theme’s other .php files. Just pure and simple.

    Thanks t0v3

    Good Work! ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Login and logout redirection’ is closed to new replies.