WordPress.org

Support

Support » WP-Advanced » [Resolved] Forcing Logout from the Admin Panel

[Resolved] Forcing Logout from the Admin Panel

  • Hi all,

    I’ve been trying to force anybody in the admin panel to logout. 🙂 Actually I want to use this for a different purpose(security) but for the basic, I’d need to get through this step.

    I expected the following code does the job but it doesn’t.

    function force_logout () {
    wp_clearcookie();
    do_action('wp_logout');
    nocache_headers();
    $redirect_to = 'wp-login.php';
    wp_redirect($redirect_to);
    exit();
    }
    add_action ('admin_head', 'force_logout');

    Does anybody know the solution for this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ok,

    If I embed the following code at the very beggining of the wp-admin/admin-header.php it works.

    header( 'Location: ' . get_settings('siteurl') );
    exit();

    However, if I do this as a plugin,

    /*
    Plugin Name: Go Home
    Plugin URI:
    Description: forces anybody to go home
    Version: 0.1beta
    Author: Goxu
    Author URI:
    */

    function force_gohome() {
    header( ‘Location: ‘ . get_settings(‘siteurl’) );
    exit();
    }

    add_action (‘admin_header’, ‘force_gohome’ ,1);`

    The priority is set to 1, so I assume that the funciton will be loaded prior to anyother funciotns. Am I correct?

    If so, why doesn’t it work? Any information will be greatly appreciated.

    I haven’t been able to figure out yet.

    There was a minor mistake in the last line. the ‘admin_header’ had to be ‘admin_head’.

    Still, I keep getting the following error in the admin panel after enabling this plugin. Is it only me getting this or do you also get this error too?

    Warning: Cannot modify header information – headers already sent by (output started at /home/wordpress/wp-admin/admin-header.php:16) in /home/wordpress/wp-content/plugins/force_gohome.php on line 12

    <?
    /*
    Plugin Name: Go Home
    Plugin URI: http://example.com
    Description: forces anybody to go home
    Version: 0.1beta
    Author: Goxu
    Author URI: http://example.com
    */
    function force_gohome(){
    header('Location: ' . get_settings('siteurl'));
    exit();
    }
    add_action('admin_head', 'force_gohome', 1);
    ?>

    The ‘init’ hook did the job.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Forcing Logout from the Admin Panel’ is closed to new replies.