A Not "Normal" Auto Logout

Okay so I push the edge everyday and sometimes it pushes

back. I’ve got a question that pushes the edge and wondering

if there is a brave soul or just a killer dude who already knows

the answer to this…

Objective:

I want the ability so when a logged in visitor coming to a special

page that they are “auto logged out” without having to click on

any links. Simply upon page load, this code or scripts run in the

background says in human term….

“Hey wordpress, log me out and redirect me to another page”.

Could this be something available already form the codex?

Could this be something someone could develop for my functions.php?

Let me know what’s up!

  • Philip John
    • DEV MAN’s Apprentice

    Hiya!

    Sure, this would be possible with a custom plugin or addition to your functions.php.

    You’d first need to detect the page with is_page, probably hooking into init like so;

    <?php
    function my_logout_page(){
    $logout_page_slug = 'logout';

    if (is_page($logout_page_slug)){
    /* log me out... */
    }
    }
    add_action('init', 'my_logout_page');
    ?>

    Then you’d just add wp_logout to actually do the logging out, like so:

    <?php
    function my_logout_page(){
    $logout_page_slug = 'logout';

    if (is_page($logout_page_slug) && is_user_logged_in()){
    wp_logout();
    }
    }
    add_action('init', 'my_logout_page');
    ?>

    Note that I’ve also added is_user_logged_in() to that last sample so it only logs people out when they are actually logged in!

    I haven’t tested that so it might not work…. you have been warned!

    Phil

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.