Plugin Directory

Changeset 3081704


Ignore:
Timestamp:
05/06/2024 06:54:09 AM (20 months ago)
Author:
lev0
Message:

Extend to all login pages

Location:
stop-logging-me-out
Files:
1 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stop-logging-me-out/tags/1.0.0/languages/stop-logging-me-out.pot

    r2928333 r3081704  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Stop Logging Me Out 0.1.1\n"
     5"Project-Id-Version: Stop Logging Me Out 1.0.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/stop-logging-me-out\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-06-20T14:46:34+09:30\n"
     12"POT-Creation-Date: 2024-05-06T05:36:58+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    14 "X-Generator: WP-CLI 2.6.0\n"
     14"X-Generator: WP-CLI 2.9.0\n"
    1515"X-Domain: stop-logging-me-out\n"
    1616
     
    2020
    2121#. Description of the plugin
    22 msgid "WordPress logs you out again when you revisit a tab/window where a previous session had expired."
     22msgid "Stop a previously expired session's login page from forcibly logging you out of your current session."
    2323msgstr ""
    2424
     
    3131msgstr ""
    3232
    33 #: stop-logging-me-out.php:140
    34 msgid "You could not be authenticated in order to return you to the original page. You will need to log in again."
     33#: stop-logging-me-out.php:164
     34msgid "You could not be authenticated in order to return you to your session. You will need to log in again."
    3535msgstr ""
    3636
    37 #: stop-logging-me-out.php:207
     37#: stop-logging-me-out.php:232
     38msgid "You have logged in again since this page loaded. Would you like to try returning to your session?"
     39msgstr ""
     40
     41#: stop-logging-me-out.php:233
    3842msgid "You have logged in again since this page automatically logged you out. Would you like to try returning to it?"
    3943msgstr ""
  • stop-logging-me-out/tags/1.0.0/readme.txt

    r2928333 r3081704  
    33Tags: login, sessions, annoyances
    44Requires at least: 4.0.0
    5 Tested up to: 6.2.2
    6 Stable tag: 0.1.1
     5Tested up to: 6.5.2
     6Stable tag: 1.0.0
    77Requires PHP: 7.0.0
    88License: GPLv2 or later
     
    1313== Description ==
    1414
    15 WordPress asks you to reauthenticate when your session expires, or for other security reasons. This is great *except* when you've just done so, and it logs you out again each time you visit a similar but obsolete reauthentication log in page.
     15WordPress asks you to reauthenticate when your session expires, or for other security reasons. This is great *except* when you've just done so, and WordPress mistakenly believes you need to do it again and again.
    1616
    17 This plugin interacts with the login system, so may not work in rare instances where that system is already being modified by other third party code in a way that isn't completely compatible with the default WordPress functions.
     17This plugin modifies a small portion the login system to prevent login cookies being erased when they don't need to. It may not work in rare instances where that system is already being modified by other third party code in a way that isn't completely compatible with the default WordPress functions.
    1818
    1919== Installation ==
     
    2121Install in the usual manner by searching for this plugin by name, or uploading it, on your **Add Plugins** page.
    2222
    23 No configuration is required but it only fixes reauthentication pages that were generated *after* the plugin was installed.
     23No configuration is required but it only fixes reauthentication pages generated *after* the plugin is installed, so visiting any that have the old `reauth=1` in the URL will still trigger WordPress' bad behaviour.
    2424
    2525== Changelog ==
     26 
     27= 1.0.0 =
     28
     29* Offer to return to a current session from regular login pages as well.
    2630 
    2731= 0.1.1 =
  • stop-logging-me-out/tags/1.0.0/stop-logging-me-out.php

    r2928333 r3081704  
    22/*
    33Plugin Name: Stop Logging Me Out
    4 Description: WordPress logs you out again when you revisit a tab/window where a previous session had expired.
    5 Version: 0.1.1
     4Description: Stop a previously expired session's login page from forcibly logging you out of your current session.
     5Version: 1.0.0
    66Requires at least: 4.0.0
    77Requires PHP: 7.0.0
     
    1414
    1515(function() {
    16     $cookie_name = 'slmo_last_login_' . COOKIEHASH;
    17     $cookie_path = function() {
     16    $slmo_cookie_name = 'slmo_last_login_' . COOKIEHASH;
     17    $slmo_cookie_path = function() {
    1818        static $path;
    1919        if ($path === null) {
    2020            list($path) = explode('?', preg_replace(
    21                 '|https?://[^/]+|i' # same pattern as used in wp-includes/default-constants.php, for performance
     21                '|https?://[^/]+|i' # same as used in COOKIEPATH definition, for performance
    2222                , ''
    2323                , wp_login_url()
     
    3131    $slmo_expire = null;
    3232    $slmo_user_id = 0;
    33     $keep_login_cookies = false;
    34     $modify_login = 0;
     33    $slmo_retain_cookies = false;
     34    $slmo_modify_login = 0;
    3535
    3636    # change boolean reauth value to a timestamp
     
    8181    add_action(
    8282        'clear_auth_cookie'
    83         , function() use (&$keep_login_cookies, &$slmo_user_id) {
    84             $keep_login_cookies = false;
     83        , function() use (&$slmo_retain_cookies, &$slmo_user_id) {
     84            $slmo_retain_cookies = false;
    8585            $slmo_user_id = 0;
    8686        }
     
    9191    add_filter(
    9292        'send_auth_cookies'
    93         , function($send_auth_cookies) use (&$slmo_send_auth_cookies, &$slmo_user_id, &$keep_login_cookies, $cookie_name, $cookie_path) {
     93        , function($send_auth_cookies) use (&$slmo_send_auth_cookies, &$slmo_user_id, &$slmo_retain_cookies, $slmo_cookie_name, $slmo_cookie_path) {
    9494            if ($slmo_user_id) {
    9595                $slmo_send_auth_cookies = $send_auth_cookies;
    9696            }
    97             elseif ($keep_login_cookies) {
     97            elseif ($slmo_retain_cookies) {
    9898                $send_auth_cookies = false; # unnecessary session destruction stopped
    9999            }
    100100            elseif ($send_auth_cookies) {
    101                 setcookie($cookie_name, ' ', time() - YEAR_IN_SECONDS, $cookie_path(), COOKIE_DOMAIN); # real logout
     101                setcookie($slmo_cookie_name, ' ', time() - YEAR_IN_SECONDS, $slmo_cookie_path(), COOKIE_DOMAIN); # real logout
    102102            }
    103103            return $send_auth_cookies;
     
    108108    add_action(
    109109        'wp_login'
    110         , function($user_login) use ($cookie_name, $cookie_path, &$slmo_secure_logged_in_cookie, &$slmo_expire, &$slmo_send_auth_cookies) {
     110        , function($user_login) use ($slmo_cookie_name, $slmo_cookie_path, &$slmo_secure_logged_in_cookie, &$slmo_expire, &$slmo_send_auth_cookies) {
    111111            if ($slmo_send_auth_cookies) {
    112                 setcookie($cookie_name, time(), $slmo_expire, $cookie_path(), COOKIE_DOMAIN, $slmo_secure_logged_in_cookie);
     112                setcookie($slmo_cookie_name, time(), $slmo_expire, $slmo_cookie_path(), COOKIE_DOMAIN, $slmo_secure_logged_in_cookie);
    113113            }
    114114        }
     
    118118    add_filter(
    119119        'wp_login_errors'
    120         , function($errors, $redirect_to) use ($cookie_name, &$keep_login_cookies, &$modify_login) {
     120        , function($errors, $redirect_to) use ($slmo_cookie_name, &$slmo_retain_cookies, &$slmo_modify_login) {
     121            $min = 1680000000;
    121122            if (
    122                 !$errors->has_errors()
    123                 && !empty($_REQUEST['reauth'])
    124                 && $_REQUEST['reauth'] > 1680000000 # assume our modified value
     123                (
     124                    !$errors->has_errors()
     125                    || $errors->get_error_codes() === ['loggedout']
     126                )
     127                && (
     128                    ($unforced = empty($_REQUEST['reauth']))
     129                    || $_REQUEST['reauth'] > $min # assume our modified value
     130                )
    125131            ) {
    126                 $modify_login = (int) $_REQUEST['reauth'];
     132                $slmo_modify_login = $unforced ? $min : (int) $_REQUEST['reauth'];
    127133                if (
    128                     !empty($_COOKIE[$cookie_name])
    129                     && (int) $_COOKIE[$cookie_name] > $modify_login # logged in again since WP required reauth
     134                    !empty($_COOKIE[$slmo_cookie_name])
     135                    && (int) $_COOKIE[$slmo_cookie_name] > $slmo_modify_login # not reauth, or logged in again since WP required reauth
    130136                ) {
    131                     if (wp_parse_auth_cookie('', $scheme = 'logged_in')) {
    132                         if (wp_validate_auth_cookie('', $scheme)) {
    133                             wp_safe_redirect($redirect_to);
     137                    if (wp_parse_auth_cookie('', 'logged_in')) {
     138                        if (
     139                            ($user = wp_get_current_user())
     140                            && $user->exists()
     141                        ) {
     142                            # extra redirect logic duplicated from wp-login.php
     143                            if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) {
     144                                // If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile.
     145                                if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) {
     146                                    $redirect_to = user_admin_url();
     147                                } elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) {
     148                                    $redirect_to = get_dashboard_url( $user->ID );
     149                                } elseif ( ! $user->has_cap( 'edit_posts' ) ) {
     150                                    $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
     151                                }
     152
     153                                wp_redirect( $redirect_to );
     154                                exit;
     155                            }
     156
     157                            wp_safe_redirect( $redirect_to );
    134158                            exit;
    135159                        }
    136                         $keep_login_cookies = true; # cookies may still be valid for grace-period, etc., but this page normally wipes them
     160                        $slmo_retain_cookies = true; # cookies may still be valid for grace-period, etc., but login page normally wipes them
    137161                    }
    138162                    $errors->add(
    139163                        'slmo_no_redir'
    140                         , esc_html__('You could not be authenticated in order to return you to the original page. You will need to log in again.', 'stop-logging-me-out')
     164                        , esc_html__('You could not be authenticated in order to return you to your session. You will need to log in again.', 'stop-logging-me-out')
    141165                    );
    142                     $modify_login = time(); # hold off focus detection until after next login
     166                    $slmo_modify_login = time(); # hold off focus detection until after next login
    143167                }
    144168            }
     
    151175    add_action(
    152176        'login_footer'
    153         , function() use (&$modify_login, $cookie_name) {
    154             if ($modify_login) {
     177        , function() use (&$slmo_modify_login, $slmo_cookie_name) {
     178            if ($slmo_modify_login) {
    155179                printf(
    156180                    <<<'EOHTML'
     
    202226</script>
    203227EOHTML
    204                     , json_encode($cookie_name)
    205                     , $modify_login
     228                    , json_encode($slmo_cookie_name)
     229                    , $slmo_modify_login
    206230                    , json_encode(wp_strip_all_tags(
    207                         __('You have logged in again since this page automatically logged you out. Would you like to try returning to it?', 'stop-logging-me-out')
     231                        empty($_REQUEST['reauth']) ?
     232                            __('You have logged in again since this page loaded. Would you like to try returning to your session?', 'stop-logging-me-out') :
     233                            __('You have logged in again since this page automatically logged you out. Would you like to try returning to it?', 'stop-logging-me-out')
    208234                    ))
    209235                ); 
  • stop-logging-me-out/trunk/languages/stop-logging-me-out.pot

    r2928333 r3081704  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Stop Logging Me Out 0.1.1\n"
     5"Project-Id-Version: Stop Logging Me Out 1.0.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/stop-logging-me-out\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-06-20T14:46:34+09:30\n"
     12"POT-Creation-Date: 2024-05-06T05:36:58+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    14 "X-Generator: WP-CLI 2.6.0\n"
     14"X-Generator: WP-CLI 2.9.0\n"
    1515"X-Domain: stop-logging-me-out\n"
    1616
     
    2020
    2121#. Description of the plugin
    22 msgid "WordPress logs you out again when you revisit a tab/window where a previous session had expired."
     22msgid "Stop a previously expired session's login page from forcibly logging you out of your current session."
    2323msgstr ""
    2424
     
    3131msgstr ""
    3232
    33 #: stop-logging-me-out.php:140
    34 msgid "You could not be authenticated in order to return you to the original page. You will need to log in again."
     33#: stop-logging-me-out.php:164
     34msgid "You could not be authenticated in order to return you to your session. You will need to log in again."
    3535msgstr ""
    3636
    37 #: stop-logging-me-out.php:207
     37#: stop-logging-me-out.php:232
     38msgid "You have logged in again since this page loaded. Would you like to try returning to your session?"
     39msgstr ""
     40
     41#: stop-logging-me-out.php:233
    3842msgid "You have logged in again since this page automatically logged you out. Would you like to try returning to it?"
    3943msgstr ""
  • stop-logging-me-out/trunk/readme.txt

    r2928333 r3081704  
    33Tags: login, sessions, annoyances
    44Requires at least: 4.0.0
    5 Tested up to: 6.2.2
    6 Stable tag: 0.1.1
     5Tested up to: 6.5.2
     6Stable tag: 1.0.0
    77Requires PHP: 7.0.0
    88License: GPLv2 or later
     
    1313== Description ==
    1414
    15 WordPress asks you to reauthenticate when your session expires, or for other security reasons. This is great *except* when you've just done so, and it logs you out again each time you visit a similar but obsolete reauthentication log in page.
     15WordPress asks you to reauthenticate when your session expires, or for other security reasons. This is great *except* when you've just done so, and WordPress mistakenly believes you need to do it again and again.
    1616
    17 This plugin interacts with the login system, so may not work in rare instances where that system is already being modified by other third party code in a way that isn't completely compatible with the default WordPress functions.
     17This plugin modifies a small portion the login system to prevent login cookies being erased when they don't need to. It may not work in rare instances where that system is already being modified by other third party code in a way that isn't completely compatible with the default WordPress functions.
    1818
    1919== Installation ==
     
    2121Install in the usual manner by searching for this plugin by name, or uploading it, on your **Add Plugins** page.
    2222
    23 No configuration is required but it only fixes reauthentication pages that were generated *after* the plugin was installed.
     23No configuration is required but it only fixes reauthentication pages generated *after* the plugin is installed, so visiting any that have the old `reauth=1` in the URL will still trigger WordPress' bad behaviour.
    2424
    2525== Changelog ==
     26 
     27= 1.0.0 =
     28
     29* Offer to return to a current session from regular login pages as well.
    2630 
    2731= 0.1.1 =
  • stop-logging-me-out/trunk/stop-logging-me-out.php

    r2928333 r3081704  
    22/*
    33Plugin Name: Stop Logging Me Out
    4 Description: WordPress logs you out again when you revisit a tab/window where a previous session had expired.
    5 Version: 0.1.1
     4Description: Stop a previously expired session's login page from forcibly logging you out of your current session.
     5Version: 1.0.0
    66Requires at least: 4.0.0
    77Requires PHP: 7.0.0
     
    1414
    1515(function() {
    16     $cookie_name = 'slmo_last_login_' . COOKIEHASH;
    17     $cookie_path = function() {
     16    $slmo_cookie_name = 'slmo_last_login_' . COOKIEHASH;
     17    $slmo_cookie_path = function() {
    1818        static $path;
    1919        if ($path === null) {
    2020            list($path) = explode('?', preg_replace(
    21                 '|https?://[^/]+|i' # same pattern as used in wp-includes/default-constants.php, for performance
     21                '|https?://[^/]+|i' # same as used in COOKIEPATH definition, for performance
    2222                , ''
    2323                , wp_login_url()
     
    3131    $slmo_expire = null;
    3232    $slmo_user_id = 0;
    33     $keep_login_cookies = false;
    34     $modify_login = 0;
     33    $slmo_retain_cookies = false;
     34    $slmo_modify_login = 0;
    3535
    3636    # change boolean reauth value to a timestamp
     
    8181    add_action(
    8282        'clear_auth_cookie'
    83         , function() use (&$keep_login_cookies, &$slmo_user_id) {
    84             $keep_login_cookies = false;
     83        , function() use (&$slmo_retain_cookies, &$slmo_user_id) {
     84            $slmo_retain_cookies = false;
    8585            $slmo_user_id = 0;
    8686        }
     
    9191    add_filter(
    9292        'send_auth_cookies'
    93         , function($send_auth_cookies) use (&$slmo_send_auth_cookies, &$slmo_user_id, &$keep_login_cookies, $cookie_name, $cookie_path) {
     93        , function($send_auth_cookies) use (&$slmo_send_auth_cookies, &$slmo_user_id, &$slmo_retain_cookies, $slmo_cookie_name, $slmo_cookie_path) {
    9494            if ($slmo_user_id) {
    9595                $slmo_send_auth_cookies = $send_auth_cookies;
    9696            }
    97             elseif ($keep_login_cookies) {
     97            elseif ($slmo_retain_cookies) {
    9898                $send_auth_cookies = false; # unnecessary session destruction stopped
    9999            }
    100100            elseif ($send_auth_cookies) {
    101                 setcookie($cookie_name, ' ', time() - YEAR_IN_SECONDS, $cookie_path(), COOKIE_DOMAIN); # real logout
     101                setcookie($slmo_cookie_name, ' ', time() - YEAR_IN_SECONDS, $slmo_cookie_path(), COOKIE_DOMAIN); # real logout
    102102            }
    103103            return $send_auth_cookies;
     
    108108    add_action(
    109109        'wp_login'
    110         , function($user_login) use ($cookie_name, $cookie_path, &$slmo_secure_logged_in_cookie, &$slmo_expire, &$slmo_send_auth_cookies) {
     110        , function($user_login) use ($slmo_cookie_name, $slmo_cookie_path, &$slmo_secure_logged_in_cookie, &$slmo_expire, &$slmo_send_auth_cookies) {
    111111            if ($slmo_send_auth_cookies) {
    112                 setcookie($cookie_name, time(), $slmo_expire, $cookie_path(), COOKIE_DOMAIN, $slmo_secure_logged_in_cookie);
     112                setcookie($slmo_cookie_name, time(), $slmo_expire, $slmo_cookie_path(), COOKIE_DOMAIN, $slmo_secure_logged_in_cookie);
    113113            }
    114114        }
     
    118118    add_filter(
    119119        'wp_login_errors'
    120         , function($errors, $redirect_to) use ($cookie_name, &$keep_login_cookies, &$modify_login) {
     120        , function($errors, $redirect_to) use ($slmo_cookie_name, &$slmo_retain_cookies, &$slmo_modify_login) {
     121            $min = 1680000000;
    121122            if (
    122                 !$errors->has_errors()
    123                 && !empty($_REQUEST['reauth'])
    124                 && $_REQUEST['reauth'] > 1680000000 # assume our modified value
     123                (
     124                    !$errors->has_errors()
     125                    || $errors->get_error_codes() === ['loggedout']
     126                )
     127                && (
     128                    ($unforced = empty($_REQUEST['reauth']))
     129                    || $_REQUEST['reauth'] > $min # assume our modified value
     130                )
    125131            ) {
    126                 $modify_login = (int) $_REQUEST['reauth'];
     132                $slmo_modify_login = $unforced ? $min : (int) $_REQUEST['reauth'];
    127133                if (
    128                     !empty($_COOKIE[$cookie_name])
    129                     && (int) $_COOKIE[$cookie_name] > $modify_login # logged in again since WP required reauth
     134                    !empty($_COOKIE[$slmo_cookie_name])
     135                    && (int) $_COOKIE[$slmo_cookie_name] > $slmo_modify_login # not reauth, or logged in again since WP required reauth
    130136                ) {
    131                     if (wp_parse_auth_cookie('', $scheme = 'logged_in')) {
    132                         if (wp_validate_auth_cookie('', $scheme)) {
    133                             wp_safe_redirect($redirect_to);
     137                    if (wp_parse_auth_cookie('', 'logged_in')) {
     138                        if (
     139                            ($user = wp_get_current_user())
     140                            && $user->exists()
     141                        ) {
     142                            # extra redirect logic duplicated from wp-login.php
     143                            if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) {
     144                                // If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile.
     145                                if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) {
     146                                    $redirect_to = user_admin_url();
     147                                } elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) {
     148                                    $redirect_to = get_dashboard_url( $user->ID );
     149                                } elseif ( ! $user->has_cap( 'edit_posts' ) ) {
     150                                    $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
     151                                }
     152
     153                                wp_redirect( $redirect_to );
     154                                exit;
     155                            }
     156
     157                            wp_safe_redirect( $redirect_to );
    134158                            exit;
    135159                        }
    136                         $keep_login_cookies = true; # cookies may still be valid for grace-period, etc., but this page normally wipes them
     160                        $slmo_retain_cookies = true; # cookies may still be valid for grace-period, etc., but login page normally wipes them
    137161                    }
    138162                    $errors->add(
    139163                        'slmo_no_redir'
    140                         , esc_html__('You could not be authenticated in order to return you to the original page. You will need to log in again.', 'stop-logging-me-out')
     164                        , esc_html__('You could not be authenticated in order to return you to your session. You will need to log in again.', 'stop-logging-me-out')
    141165                    );
    142                     $modify_login = time(); # hold off focus detection until after next login
     166                    $slmo_modify_login = time(); # hold off focus detection until after next login
    143167                }
    144168            }
     
    151175    add_action(
    152176        'login_footer'
    153         , function() use (&$modify_login, $cookie_name) {
    154             if ($modify_login) {
     177        , function() use (&$slmo_modify_login, $slmo_cookie_name) {
     178            if ($slmo_modify_login) {
    155179                printf(
    156180                    <<<'EOHTML'
     
    202226</script>
    203227EOHTML
    204                     , json_encode($cookie_name)
    205                     , $modify_login
     228                    , json_encode($slmo_cookie_name)
     229                    , $slmo_modify_login
    206230                    , json_encode(wp_strip_all_tags(
    207                         __('You have logged in again since this page automatically logged you out. Would you like to try returning to it?', 'stop-logging-me-out')
     231                        empty($_REQUEST['reauth']) ?
     232                            __('You have logged in again since this page loaded. Would you like to try returning to your session?', 'stop-logging-me-out') :
     233                            __('You have logged in again since this page automatically logged you out. Would you like to try returning to it?', 'stop-logging-me-out')
    208234                    ))
    209235                ); 
Note: See TracChangeset for help on using the changeset viewer.