Changeset 3081704
- Timestamp:
- 05/06/2024 06:54:09 AM (20 months ago)
- Location:
- stop-logging-me-out
- Files:
-
- 1 added
- 6 edited
- 1 copied
-
assets/screenshot-1.png (added)
-
tags/1.0.0 (copied) (copied from stop-logging-me-out/trunk)
-
tags/1.0.0/languages/stop-logging-me-out.pot (modified) (4 diffs)
-
tags/1.0.0/readme.txt (modified) (3 diffs)
-
tags/1.0.0/stop-logging-me-out.php (modified) (9 diffs)
-
trunk/languages/stop-logging-me-out.pot (modified) (4 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/stop-logging-me-out.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
stop-logging-me-out/tags/1.0.0/languages/stop-logging-me-out.pot
r2928333 r3081704 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Stop Logging Me Out 0.1.1\n"5 "Project-Id-Version: Stop Logging Me Out 1.0.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/stop-logging-me-out\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 202 3-06-20T14:46:34+09:30\n"12 "POT-Creation-Date: 2024-05-06T05:36:58+00:00\n" 13 13 "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" 15 15 "X-Domain: stop-logging-me-out\n" 16 16 … … 20 20 21 21 #. Description of the plugin 22 msgid " WordPress logs you out again when you revisit a tab/window where a previous session had expired."22 msgid "Stop a previously expired session's login page from forcibly logging you out of your current session." 23 23 msgstr "" 24 24 … … 31 31 msgstr "" 32 32 33 #: stop-logging-me-out.php:1 4034 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 34 msgid "You could not be authenticated in order to return you to your session. You will need to log in again." 35 35 msgstr "" 36 36 37 #: stop-logging-me-out.php:207 37 #: stop-logging-me-out.php:232 38 msgid "You have logged in again since this page loaded. Would you like to try returning to your session?" 39 msgstr "" 40 41 #: stop-logging-me-out.php:233 38 42 msgid "You have logged in again since this page automatically logged you out. Would you like to try returning to it?" 39 43 msgstr "" -
stop-logging-me-out/tags/1.0.0/readme.txt
r2928333 r3081704 3 3 Tags: login, sessions, annoyances 4 4 Requires at least: 4.0.0 5 Tested up to: 6. 2.26 Stable tag: 0.1.15 Tested up to: 6.5.2 6 Stable tag: 1.0.0 7 7 Requires PHP: 7.0.0 8 8 License: GPLv2 or later … … 13 13 == Description == 14 14 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.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 WordPress mistakenly believes you need to do it again and again. 16 16 17 This plugin interacts with the login system, somay 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.17 This 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. 18 18 19 19 == Installation == … … 21 21 Install in the usual manner by searching for this plugin by name, or uploading it, on your **Add Plugins** page. 22 22 23 No configuration is required but it only fixes reauthentication pages that were generated *after* the plugin was installed.23 No 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. 24 24 25 25 == Changelog == 26 27 = 1.0.0 = 28 29 * Offer to return to a current session from regular login pages as well. 26 30 27 31 = 0.1.1 = -
stop-logging-me-out/tags/1.0.0/stop-logging-me-out.php
r2928333 r3081704 2 2 /* 3 3 Plugin 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.14 Description: Stop a previously expired session's login page from forcibly logging you out of your current session. 5 Version: 1.0.0 6 6 Requires at least: 4.0.0 7 7 Requires PHP: 7.0.0 … … 14 14 15 15 (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() { 18 18 static $path; 19 19 if ($path === null) { 20 20 list($path) = explode('?', preg_replace( 21 '|https?://[^/]+|i' # same pattern as used in wp-includes/default-constants.php, for performance21 '|https?://[^/]+|i' # same as used in COOKIEPATH definition, for performance 22 22 , '' 23 23 , wp_login_url() … … 31 31 $slmo_expire = null; 32 32 $slmo_user_id = 0; 33 $ keep_login_cookies = false;34 $ modify_login = 0;33 $slmo_retain_cookies = false; 34 $slmo_modify_login = 0; 35 35 36 36 # change boolean reauth value to a timestamp … … 81 81 add_action( 82 82 '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; 85 85 $slmo_user_id = 0; 86 86 } … … 91 91 add_filter( 92 92 '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) { 94 94 if ($slmo_user_id) { 95 95 $slmo_send_auth_cookies = $send_auth_cookies; 96 96 } 97 elseif ($ keep_login_cookies) {97 elseif ($slmo_retain_cookies) { 98 98 $send_auth_cookies = false; # unnecessary session destruction stopped 99 99 } 100 100 elseif ($send_auth_cookies) { 101 setcookie($ cookie_name, ' ', time() - YEAR_IN_SECONDS, $cookie_path(), COOKIE_DOMAIN); # real logout101 setcookie($slmo_cookie_name, ' ', time() - YEAR_IN_SECONDS, $slmo_cookie_path(), COOKIE_DOMAIN); # real logout 102 102 } 103 103 return $send_auth_cookies; … … 108 108 add_action( 109 109 '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) { 111 111 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); 113 113 } 114 114 } … … 118 118 add_filter( 119 119 '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; 121 122 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 ) 125 131 ) { 126 $ modify_login =(int) $_REQUEST['reauth'];132 $slmo_modify_login = $unforced ? $min : (int) $_REQUEST['reauth']; 127 133 if ( 128 !empty($_COOKIE[$ cookie_name])129 && (int) $_COOKIE[$ cookie_name] > $modify_login #logged in again since WP required reauth134 !empty($_COOKIE[$slmo_cookie_name]) 135 && (int) $_COOKIE[$slmo_cookie_name] > $slmo_modify_login # not reauth, or logged in again since WP required reauth 130 136 ) { 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 ); 134 158 exit; 135 159 } 136 $ keep_login_cookies = true; # cookies may still be valid for grace-period, etc., but thispage normally wipes them160 $slmo_retain_cookies = true; # cookies may still be valid for grace-period, etc., but login page normally wipes them 137 161 } 138 162 $errors->add( 139 163 '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') 141 165 ); 142 $ modify_login = time(); # hold off focus detection until after next login166 $slmo_modify_login = time(); # hold off focus detection until after next login 143 167 } 144 168 } … … 151 175 add_action( 152 176 '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) { 155 179 printf( 156 180 <<<'EOHTML' … … 202 226 </script> 203 227 EOHTML 204 , json_encode($ cookie_name)205 , $ modify_login228 , json_encode($slmo_cookie_name) 229 , $slmo_modify_login 206 230 , 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') 208 234 )) 209 235 ); -
stop-logging-me-out/trunk/languages/stop-logging-me-out.pot
r2928333 r3081704 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Stop Logging Me Out 0.1.1\n"5 "Project-Id-Version: Stop Logging Me Out 1.0.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/stop-logging-me-out\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 202 3-06-20T14:46:34+09:30\n"12 "POT-Creation-Date: 2024-05-06T05:36:58+00:00\n" 13 13 "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" 15 15 "X-Domain: stop-logging-me-out\n" 16 16 … … 20 20 21 21 #. Description of the plugin 22 msgid " WordPress logs you out again when you revisit a tab/window where a previous session had expired."22 msgid "Stop a previously expired session's login page from forcibly logging you out of your current session." 23 23 msgstr "" 24 24 … … 31 31 msgstr "" 32 32 33 #: stop-logging-me-out.php:1 4034 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 34 msgid "You could not be authenticated in order to return you to your session. You will need to log in again." 35 35 msgstr "" 36 36 37 #: stop-logging-me-out.php:207 37 #: stop-logging-me-out.php:232 38 msgid "You have logged in again since this page loaded. Would you like to try returning to your session?" 39 msgstr "" 40 41 #: stop-logging-me-out.php:233 38 42 msgid "You have logged in again since this page automatically logged you out. Would you like to try returning to it?" 39 43 msgstr "" -
stop-logging-me-out/trunk/readme.txt
r2928333 r3081704 3 3 Tags: login, sessions, annoyances 4 4 Requires at least: 4.0.0 5 Tested up to: 6. 2.26 Stable tag: 0.1.15 Tested up to: 6.5.2 6 Stable tag: 1.0.0 7 7 Requires PHP: 7.0.0 8 8 License: GPLv2 or later … … 13 13 == Description == 14 14 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.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 WordPress mistakenly believes you need to do it again and again. 16 16 17 This plugin interacts with the login system, somay 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.17 This 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. 18 18 19 19 == Installation == … … 21 21 Install in the usual manner by searching for this plugin by name, or uploading it, on your **Add Plugins** page. 22 22 23 No configuration is required but it only fixes reauthentication pages that were generated *after* the plugin was installed.23 No 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. 24 24 25 25 == Changelog == 26 27 = 1.0.0 = 28 29 * Offer to return to a current session from regular login pages as well. 26 30 27 31 = 0.1.1 = -
stop-logging-me-out/trunk/stop-logging-me-out.php
r2928333 r3081704 2 2 /* 3 3 Plugin 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.14 Description: Stop a previously expired session's login page from forcibly logging you out of your current session. 5 Version: 1.0.0 6 6 Requires at least: 4.0.0 7 7 Requires PHP: 7.0.0 … … 14 14 15 15 (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() { 18 18 static $path; 19 19 if ($path === null) { 20 20 list($path) = explode('?', preg_replace( 21 '|https?://[^/]+|i' # same pattern as used in wp-includes/default-constants.php, for performance21 '|https?://[^/]+|i' # same as used in COOKIEPATH definition, for performance 22 22 , '' 23 23 , wp_login_url() … … 31 31 $slmo_expire = null; 32 32 $slmo_user_id = 0; 33 $ keep_login_cookies = false;34 $ modify_login = 0;33 $slmo_retain_cookies = false; 34 $slmo_modify_login = 0; 35 35 36 36 # change boolean reauth value to a timestamp … … 81 81 add_action( 82 82 '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; 85 85 $slmo_user_id = 0; 86 86 } … … 91 91 add_filter( 92 92 '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) { 94 94 if ($slmo_user_id) { 95 95 $slmo_send_auth_cookies = $send_auth_cookies; 96 96 } 97 elseif ($ keep_login_cookies) {97 elseif ($slmo_retain_cookies) { 98 98 $send_auth_cookies = false; # unnecessary session destruction stopped 99 99 } 100 100 elseif ($send_auth_cookies) { 101 setcookie($ cookie_name, ' ', time() - YEAR_IN_SECONDS, $cookie_path(), COOKIE_DOMAIN); # real logout101 setcookie($slmo_cookie_name, ' ', time() - YEAR_IN_SECONDS, $slmo_cookie_path(), COOKIE_DOMAIN); # real logout 102 102 } 103 103 return $send_auth_cookies; … … 108 108 add_action( 109 109 '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) { 111 111 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); 113 113 } 114 114 } … … 118 118 add_filter( 119 119 '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; 121 122 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 ) 125 131 ) { 126 $ modify_login =(int) $_REQUEST['reauth'];132 $slmo_modify_login = $unforced ? $min : (int) $_REQUEST['reauth']; 127 133 if ( 128 !empty($_COOKIE[$ cookie_name])129 && (int) $_COOKIE[$ cookie_name] > $modify_login #logged in again since WP required reauth134 !empty($_COOKIE[$slmo_cookie_name]) 135 && (int) $_COOKIE[$slmo_cookie_name] > $slmo_modify_login # not reauth, or logged in again since WP required reauth 130 136 ) { 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 ); 134 158 exit; 135 159 } 136 $ keep_login_cookies = true; # cookies may still be valid for grace-period, etc., but thispage normally wipes them160 $slmo_retain_cookies = true; # cookies may still be valid for grace-period, etc., but login page normally wipes them 137 161 } 138 162 $errors->add( 139 163 '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') 141 165 ); 142 $ modify_login = time(); # hold off focus detection until after next login166 $slmo_modify_login = time(); # hold off focus detection until after next login 143 167 } 144 168 } … … 151 175 add_action( 152 176 '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) { 155 179 printf( 156 180 <<<'EOHTML' … … 202 226 </script> 203 227 EOHTML 204 , json_encode($ cookie_name)205 , $ modify_login228 , json_encode($slmo_cookie_name) 229 , $slmo_modify_login 206 230 , 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') 208 234 )) 209 235 );
Note: See TracChangeset
for help on using the changeset viewer.