Changeset 2324049
- Timestamp:
- 06/14/2020 10:54:08 PM (6 years ago)
- Location:
- whos-logged-in
- Files:
-
- 2 added
- 6 edited
- 1 copied
-
assets/screenshot-1.png (added)
-
assets/screenshot-2.png (added)
-
tags/1.2 (copied) (copied from whos-logged-in/trunk)
-
tags/1.2/js/wli-script.js (modified) (3 diffs)
-
tags/1.2/readme.txt (modified) (3 diffs)
-
tags/1.2/whos-logged-in.php (modified) (8 diffs)
-
trunk/js/wli-script.js (modified) (3 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/whos-logged-in.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
whos-logged-in/tags/1.2/js/wli-script.js
r2201746 r2324049 1 1 jQuery(document).ready(function($){ 2 // every XXXX seconds(1000 == 1 second) make ajax call foruser list2 // every XXXX seconds(1000 == 1 second) make ajax call to update user list 3 3 setInterval(function(){ 4 4 $.post( … … 14 14 }, 15000); // 15000ms = 15 seconds 15 15 16 // log users out after the current browser tab is not in focus for some amount of time 17 // function that makes the ajax call to log user out. 16 // function that makes ajax call to log users out after the current browser tab is not in focus for some amount of time 18 17 function wliLogoutUsers() { 19 18 $.post( … … 23 22 security: wli_js_vars.secret_nonce 24 23 }, 25 function() { 26 window.location.reload(); 24 function(response) { 25 // if setting to autologout users is turned on, then reload page on ajax success 26 if(response != "auto-kick-is-turned-off") { 27 window.location.reload(); 28 } 27 29 } 28 30 ); 29 31 } 30 // Start the Timeout that calls function to log user out after 15 minutes 32 // When user leaves current tab/window, then start a 15 minute timer that calls the "wliLogoutUsers" function to log users when it's done 33 wliTimeout = ""; // fix for console warning: initialize variable in global scope so it is available in both of the below functions locally 31 34 function wliStartLogoutTimer() { 32 wliTimeout = window.setTimeout(wliLogoutUsers, 900000); // 900000ms = 15minutes35 wliTimeout = window.setTimeout(wliLogoutUsers, 5000); // 1,200,000ms = 20 minutes 33 36 } 34 // Clear the timer if user comes back to current tab/window37 // When a user comes back to the current tab/window, then clear the 15 minute timer if user so they don't get logged out 35 38 function wliClearLogoutTimer() { 36 window.clearTimeout(wliTimeout); 39 if(wliTimeout != "") { 40 window.clearTimeout(wliTimeout); 41 } 37 42 } 38 43 44 // NOTE: using the javascript "blur" event to recognize when a user has left the current tab/window is not incredibly reliable across browsers and devices, but it is the most reliable approach I could find to make the requested feature functional 39 45 window.addEventListener( 'blur', wliStartLogoutTimer ); 40 46 window.addEventListener( 'focus', wliClearLogoutTimer ); -
whos-logged-in/tags/1.2/readme.txt
r2201753 r2324049 4 4 Tags: logged-in, activity, dashboard, metabox 5 5 Requires at least: 4.0 6 Tested up to: 5. 36 Tested up to: 5.4.2 7 7 Requires PHP: 5.6 8 Stable tag: 1. 18 Stable tag: 1.2 9 9 License: GPLv3 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html 11 11 12 The Who's Logged In Plugin provides a simple meta box on your dashboard home page that shows a list of users that have logged in12 The Who's Logged In Plugin provides a simple meta box on your dashboard home page that shows a list of users as they log in and log out 13 13 14 14 == Description == … … 17 17 18 18 == New Feature! == 19 * Added a requested feature that automatically logs out users **15 minutes** after they have left the current website window or tab. The automatically updating list of users displayed on your administrator dashboard will update shortly after to reflect that user has been automatically logged out. If a user returns to the window or tab within 15 minutes, the timer that would have logged them out stops.19 * Added a settings page that, for now, has a single option to turn the automatic logout of inactive users functionality on and off. Current development is underway for a handful of other new settings page options, but I would love to hear any and all suggestions for new features you would like to see in the Who's Logged In plugin. Please visit the support forum to leave your ideas, or click on the authors link underneath the Plugins title here https://wordpress.org/plugins/whos-logged-in/ 20 20 21 21 == Installation == 22 22 23 1. Install the plugin through the WordPress plugins screen directly. 24 2. Activate the plugin through the 'Plugins' screen in your WordPress Dashboard. 25 3. Visit your Dashboard home page and look for the Who's Logged In Metabox. 23 1. Search for and install the Who's Logged In plugin from the "Plugins" section of your WordPress dashboard. 24 2. Once installed, activate the plugin from the same "Plugins" section of your WordPress Dashboard. 25 3. Once the plugin is activated, you can visit the Dashboard >> Home page to see the Who's Logged In Metabox. 26 27 == Frequently Asked Questions == 28 29 = Where is the settings page for the Who's Logged In plugin located? = 30 31 You can find the plugins settings page after logging in as an administrator, and clicking on the Dashboard >> Settings >> Who's Logged In sub menu item. 32 33 = I'm an administrator, and while viewing my dashboard page I don't see the Who's Logged In metabox anywhere? = 34 35 Check that the Who's Logged In plugin has actually been activated on the Dashboard >> Plugins page first off. If the plugin is activated you may need to click on the "Screen Options" button, near the top right of the dashboard page, then check off the "Who's Logged In" box to add it to your dashboard. 26 36 27 37 == Screenshots == 28 38 29 39 1. The Who's Logged In Metabox that gets added to your Dashboard home page. 40 2. Showing the location of the Who's Logged In plugin settings page. 30 41 31 42 == Changelog == 43 44 = 1.2 = 45 * Added a requested settings page that, for now, has one setting for turning the automatic logout of inactive users functionality that was added in version 1.1 on and off. Also changed the automatic logout timer to be 20 minutes instead of 15 minutes to make it a little more friendly. 32 46 33 47 = 1.1 = … … 36 50 == Upgrade Notice == 37 51 38 = 1. 1=39 * cAdded a requested feature that automatically logs out users **15 minutes** after they have left the current website window or tab. The automatically updating list of users displayed on your administrator dashboard will update shortly after to reflect that user has been automatically logged out. If a user returns to the window or tab within 15 minutes, the timer that would have logged them out stops.52 = 1.2 = 53 * Adds new settings page with an option for turning the automatic logging out of inactive users functionality on and off. -
whos-logged-in/tags/1.2/whos-logged-in.php
r2201746 r2324049 3 3 /* 4 4 Plugin Name: Who's Logged In 5 Description: Displays a metabox in your WordPress Dashboard page that builds a list of users thatlog in and log out6 Version: 1. 15 Description: Adds a metabox in all Administrator users Dashboard page that shows a list of users that updates regularly as they log in and log out 6 Version: 1.2 7 7 Author: Ben HartLenn 8 8 Author URI: bhartlenn@gmail.com … … 11 11 License URI: https://www.gnu.org/licenses/gpl-3.0.html 12 12 13 The Who's Logged In plugin shows you a list of logged in users on your dashboard home page, and it updates the list every 5 seconds!14 Copyright (C) 20 17Ben HartLenn13 The Who's Logged In plugin shows you a list of logged in users on your dashboard home page, and it updates the list every 15 seconds! 14 Copyright (C) 2020 Ben HartLenn 15 15 16 16 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. … … 23 23 along with The Who's Logged In plugin. If not, see <http://www.gnu.org/licenses/>. 24 24 25 Please contact the author through bhartlenn@gmail.com for any inquiries.25 Please contact the plugin author via email at ~ bhartlenn at gmail dot com ~ for any inquiries or suggestions, thanks! 26 26 */ 27 27 … … 40 40 $wli_token_users_array = wp_list_pluck($wli_token_user_objects, 'user_login'); 41 41 42 // initialize output variable43 $wli_logged_in_users_output = "";44 45 42 // loop through the array of users stored in the plugin option, and remove them if they do not have an active session token in database 46 43 foreach( $wli_logged_in_users as $wli_user_id => $wli_user_login ) { … … 49 46 } 50 47 } 48 49 // initialize output variable 50 $wli_logged_in_users_output = ""; 51 51 52 52 // build user list output for display … … 66 66 update_option( 'wli_logged_in_users', $wli_logged_in_users, '', 'no' ); 67 67 } 68 69 // get current user and add to logged in users list on plugin activation 68 // ***** End plugin helper functions section ***** 69 70 // ***** Plugin Functionality Section ***** 71 72 // Setup a settings page for Who's Logged In available at Dashboard >> Settings >> Whos Logged In 73 add_action( 'admin_menu', 'wli_add_settings_page' ); 74 function wli_add_settings_page() { 75 // add_options_page adds our sub menu under Dashboard >> Settings 76 add_options_page( 77 'Whos Logged In', 78 'Whos Logged In', 79 'administrator', 80 'whos-logged-in', 81 'wli_render_plugin_settings_page' 82 ); 83 } 84 85 // register settings to our plugins settings/options page 86 add_action( 'admin_init', 'wli_settings_init' ); 87 function wli_settings_init() { 88 // register plugin setting that will have an array of option-like key:value pairs stored in the one option 89 register_setting( 90 'wli_settings', 91 'wli_settings_general', 92 [ 93 'type' => 'array' 94 ] 95 ); 96 97 // add plugin settings section 98 add_settings_section( 99 'wli_settings_page_general_section', 100 __( 'General Settings', 'whos_logged_in' ), 101 'wli_settings_general_section_callback', 102 'whos-logged-in' 103 ); 104 105 // add checkbox field for turning auto kick users functionality on and off 106 add_settings_field( 107 'wli_auto_kick_inactive_users', 108 __( 'Auto logout inactive users', 'whos_logged_in' ), 109 'wli_auto_kick_users_field_render', 110 'whos-logged-in', 111 'wli_settings_page_general_section' 112 ); 113 } 114 115 // settings section intro text 116 function wli_settings_general_section_callback() { 117 } 118 119 // render checkbox field for kicking users automatically 120 function wli_auto_kick_users_field_render() { 121 122 $general_settings = get_option( 'wli_settings_general' ); 123 $value = $general_settings['wli_auto_kick_inactive_users']; 124 $checked = checked( $value, 1, false ); 125 ?> 126 <input id="wli_auto_kick_inactive_users" type="checkbox" name="wli_settings_general[wli_auto_kick_inactive_users]" value="1" <?= $checked; ?> ><label for="wli_auto_kick_inactive_users">Turning on this option will make the plugin automatically logout <b>ANY</b> inactive users after 20 minutes of continous inactivity on your website.</label> 127 <?php 128 } 129 130 131 // render the settings page html/php 132 function wli_render_plugin_settings_page() { 133 // check user capabilities 134 if ( !current_user_can( 'manage_options' ) ) { 135 return; 136 } 137 ?> 138 139 <div class='wli-settings-page wrap'> 140 <h1><?= esc_html( get_admin_page_title() ); ?></h1> 141 <form action='options.php' method='post'> 142 143 <?php 144 //Output nonce, action, and option_page fields for a settings page. 145 settings_fields( 'wli_settings' ); 146 147 // output the settings sections and fields 148 do_settings_sections( 'whos-logged-in' ); 149 150 // form submit button 151 submit_button( 'Save Settings' ); 152 ?> 153 154 </form> 155 </div> 156 157 <?php 158 } 159 160 161 70 162 register_activation_hook( __FILE__, 'wli_plugin_activation' ); 71 163 function wli_plugin_activation() { 164 // get current user and add to logged in users list on plugin activation 72 165 $wli_current_user = wp_get_current_user(); 73 166 update_option( 'wli_logged_in_users', [ $wli_current_user->ID => $wli_current_user->user_login ], '', 'no' ); 167 // default to not automatically kicking users off when plugin is activated 168 update_option( 'wli_settings_general', ['wli_auto_kick_inactive_users' => 0] ); 74 169 } 75 170 … … 78 173 function wli_plugin_deactivation() { 79 174 delete_option( 'wli_logged_in_users' ); 175 delete_option( 'wli_settings_general' ); 80 176 } 81 177 … … 151 247 add_action( 'wp_ajax_wli_ajax_logout_users', 'wli_ajax_logout_users' ); 152 248 function wli_ajax_logout_users() { 153 // get the current user 154 $current_user = wp_get_current_user(); 155 156 // get all sessions for the current user by their ID 157 $sessions = WP_Session_Tokens::get_instance($current_user->ID); 158 159 // now that we have got all of the users sessions, destroy them! 160 $sessions->destroy_all(); 161 249 // check if auto kick users setting is on or off 250 $general_settings = get_option( 'wli_settings_general' ); 251 $value = $general_settings['wli_auto_kick_inactive_users']; 252 // if auto kick is turned on, then proceed to... 253 if($value == 1) { 254 // ...get the current user that triggered this action 255 $current_user = wp_get_current_user(); 256 257 // ...get all sessions for the current user by their ID 258 $sessions = WP_Session_Tokens::get_instance($current_user->ID); 259 260 // ...destroy their sessions, and all of them! 261 $sessions->destroy_all(); 262 } 263 // or else send response to let javascript know not to refresh page on ajax success 264 else { 265 echo "auto-kick-is-turned-off"; 266 } 267 // and then die 162 268 wp_die(); 163 269 } -
whos-logged-in/trunk/js/wli-script.js
r2201746 r2324049 1 1 jQuery(document).ready(function($){ 2 // every XXXX seconds(1000 == 1 second) make ajax call foruser list2 // every XXXX seconds(1000 == 1 second) make ajax call to update user list 3 3 setInterval(function(){ 4 4 $.post( … … 14 14 }, 15000); // 15000ms = 15 seconds 15 15 16 // log users out after the current browser tab is not in focus for some amount of time 17 // function that makes the ajax call to log user out. 16 // function that makes ajax call to log users out after the current browser tab is not in focus for some amount of time 18 17 function wliLogoutUsers() { 19 18 $.post( … … 23 22 security: wli_js_vars.secret_nonce 24 23 }, 25 function() { 26 window.location.reload(); 24 function(response) { 25 // if setting to autologout users is turned on, then reload page on ajax success 26 if(response != "auto-kick-is-turned-off") { 27 window.location.reload(); 28 } 27 29 } 28 30 ); 29 31 } 30 // Start the Timeout that calls function to log user out after 15 minutes 32 // When user leaves current tab/window, then start a 15 minute timer that calls the "wliLogoutUsers" function to log users when it's done 33 wliTimeout = ""; // fix for console warning: initialize variable in global scope so it is available in both of the below functions locally 31 34 function wliStartLogoutTimer() { 32 wliTimeout = window.setTimeout(wliLogoutUsers, 900000); // 900000ms = 15minutes35 wliTimeout = window.setTimeout(wliLogoutUsers, 5000); // 1,200,000ms = 20 minutes 33 36 } 34 // Clear the timer if user comes back to current tab/window37 // When a user comes back to the current tab/window, then clear the 15 minute timer if user so they don't get logged out 35 38 function wliClearLogoutTimer() { 36 window.clearTimeout(wliTimeout); 39 if(wliTimeout != "") { 40 window.clearTimeout(wliTimeout); 41 } 37 42 } 38 43 44 // NOTE: using the javascript "blur" event to recognize when a user has left the current tab/window is not incredibly reliable across browsers and devices, but it is the most reliable approach I could find to make the requested feature functional 39 45 window.addEventListener( 'blur', wliStartLogoutTimer ); 40 46 window.addEventListener( 'focus', wliClearLogoutTimer ); -
whos-logged-in/trunk/readme.txt
r2201753 r2324049 4 4 Tags: logged-in, activity, dashboard, metabox 5 5 Requires at least: 4.0 6 Tested up to: 5. 36 Tested up to: 5.4.2 7 7 Requires PHP: 5.6 8 Stable tag: 1. 18 Stable tag: 1.2 9 9 License: GPLv3 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html 11 11 12 The Who's Logged In Plugin provides a simple meta box on your dashboard home page that shows a list of users that have logged in12 The Who's Logged In Plugin provides a simple meta box on your dashboard home page that shows a list of users as they log in and log out 13 13 14 14 == Description == … … 17 17 18 18 == New Feature! == 19 * Added a requested feature that automatically logs out users **15 minutes** after they have left the current website window or tab. The automatically updating list of users displayed on your administrator dashboard will update shortly after to reflect that user has been automatically logged out. If a user returns to the window or tab within 15 minutes, the timer that would have logged them out stops.19 * Added a settings page that, for now, has a single option to turn the automatic logout of inactive users functionality on and off. Current development is underway for a handful of other new settings page options, but I would love to hear any and all suggestions for new features you would like to see in the Who's Logged In plugin. Please visit the support forum to leave your ideas, or click on the authors link underneath the Plugins title here https://wordpress.org/plugins/whos-logged-in/ 20 20 21 21 == Installation == 22 22 23 1. Install the plugin through the WordPress plugins screen directly. 24 2. Activate the plugin through the 'Plugins' screen in your WordPress Dashboard. 25 3. Visit your Dashboard home page and look for the Who's Logged In Metabox. 23 1. Search for and install the Who's Logged In plugin from the "Plugins" section of your WordPress dashboard. 24 2. Once installed, activate the plugin from the same "Plugins" section of your WordPress Dashboard. 25 3. Once the plugin is activated, you can visit the Dashboard >> Home page to see the Who's Logged In Metabox. 26 27 == Frequently Asked Questions == 28 29 = Where is the settings page for the Who's Logged In plugin located? = 30 31 You can find the plugins settings page after logging in as an administrator, and clicking on the Dashboard >> Settings >> Who's Logged In sub menu item. 32 33 = I'm an administrator, and while viewing my dashboard page I don't see the Who's Logged In metabox anywhere? = 34 35 Check that the Who's Logged In plugin has actually been activated on the Dashboard >> Plugins page first off. If the plugin is activated you may need to click on the "Screen Options" button, near the top right of the dashboard page, then check off the "Who's Logged In" box to add it to your dashboard. 26 36 27 37 == Screenshots == 28 38 29 39 1. The Who's Logged In Metabox that gets added to your Dashboard home page. 40 2. Showing the location of the Who's Logged In plugin settings page. 30 41 31 42 == Changelog == 43 44 = 1.2 = 45 * Added a requested settings page that, for now, has one setting for turning the automatic logout of inactive users functionality that was added in version 1.1 on and off. Also changed the automatic logout timer to be 20 minutes instead of 15 minutes to make it a little more friendly. 32 46 33 47 = 1.1 = … … 36 50 == Upgrade Notice == 37 51 38 = 1. 1=39 * cAdded a requested feature that automatically logs out users **15 minutes** after they have left the current website window or tab. The automatically updating list of users displayed on your administrator dashboard will update shortly after to reflect that user has been automatically logged out. If a user returns to the window or tab within 15 minutes, the timer that would have logged them out stops.52 = 1.2 = 53 * Adds new settings page with an option for turning the automatic logging out of inactive users functionality on and off. -
whos-logged-in/trunk/whos-logged-in.php
r2201746 r2324049 3 3 /* 4 4 Plugin Name: Who's Logged In 5 Description: Displays a metabox in your WordPress Dashboard page that builds a list of users thatlog in and log out6 Version: 1. 15 Description: Adds a metabox in all Administrator users Dashboard page that shows a list of users that updates regularly as they log in and log out 6 Version: 1.2 7 7 Author: Ben HartLenn 8 8 Author URI: bhartlenn@gmail.com … … 11 11 License URI: https://www.gnu.org/licenses/gpl-3.0.html 12 12 13 The Who's Logged In plugin shows you a list of logged in users on your dashboard home page, and it updates the list every 5 seconds!14 Copyright (C) 20 17Ben HartLenn13 The Who's Logged In plugin shows you a list of logged in users on your dashboard home page, and it updates the list every 15 seconds! 14 Copyright (C) 2020 Ben HartLenn 15 15 16 16 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. … … 23 23 along with The Who's Logged In plugin. If not, see <http://www.gnu.org/licenses/>. 24 24 25 Please contact the author through bhartlenn@gmail.com for any inquiries.25 Please contact the plugin author via email at ~ bhartlenn at gmail dot com ~ for any inquiries or suggestions, thanks! 26 26 */ 27 27 … … 40 40 $wli_token_users_array = wp_list_pluck($wli_token_user_objects, 'user_login'); 41 41 42 // initialize output variable43 $wli_logged_in_users_output = "";44 45 42 // loop through the array of users stored in the plugin option, and remove them if they do not have an active session token in database 46 43 foreach( $wli_logged_in_users as $wli_user_id => $wli_user_login ) { … … 49 46 } 50 47 } 48 49 // initialize output variable 50 $wli_logged_in_users_output = ""; 51 51 52 52 // build user list output for display … … 66 66 update_option( 'wli_logged_in_users', $wli_logged_in_users, '', 'no' ); 67 67 } 68 69 // get current user and add to logged in users list on plugin activation 68 // ***** End plugin helper functions section ***** 69 70 // ***** Plugin Functionality Section ***** 71 72 // Setup a settings page for Who's Logged In available at Dashboard >> Settings >> Whos Logged In 73 add_action( 'admin_menu', 'wli_add_settings_page' ); 74 function wli_add_settings_page() { 75 // add_options_page adds our sub menu under Dashboard >> Settings 76 add_options_page( 77 'Whos Logged In', 78 'Whos Logged In', 79 'administrator', 80 'whos-logged-in', 81 'wli_render_plugin_settings_page' 82 ); 83 } 84 85 // register settings to our plugins settings/options page 86 add_action( 'admin_init', 'wli_settings_init' ); 87 function wli_settings_init() { 88 // register plugin setting that will have an array of option-like key:value pairs stored in the one option 89 register_setting( 90 'wli_settings', 91 'wli_settings_general', 92 [ 93 'type' => 'array' 94 ] 95 ); 96 97 // add plugin settings section 98 add_settings_section( 99 'wli_settings_page_general_section', 100 __( 'General Settings', 'whos_logged_in' ), 101 'wli_settings_general_section_callback', 102 'whos-logged-in' 103 ); 104 105 // add checkbox field for turning auto kick users functionality on and off 106 add_settings_field( 107 'wli_auto_kick_inactive_users', 108 __( 'Auto logout inactive users', 'whos_logged_in' ), 109 'wli_auto_kick_users_field_render', 110 'whos-logged-in', 111 'wli_settings_page_general_section' 112 ); 113 } 114 115 // settings section intro text 116 function wli_settings_general_section_callback() { 117 } 118 119 // render checkbox field for kicking users automatically 120 function wli_auto_kick_users_field_render() { 121 122 $general_settings = get_option( 'wli_settings_general' ); 123 $value = $general_settings['wli_auto_kick_inactive_users']; 124 $checked = checked( $value, 1, false ); 125 ?> 126 <input id="wli_auto_kick_inactive_users" type="checkbox" name="wli_settings_general[wli_auto_kick_inactive_users]" value="1" <?= $checked; ?> ><label for="wli_auto_kick_inactive_users">Turning on this option will make the plugin automatically logout <b>ANY</b> inactive users after 20 minutes of continous inactivity on your website.</label> 127 <?php 128 } 129 130 131 // render the settings page html/php 132 function wli_render_plugin_settings_page() { 133 // check user capabilities 134 if ( !current_user_can( 'manage_options' ) ) { 135 return; 136 } 137 ?> 138 139 <div class='wli-settings-page wrap'> 140 <h1><?= esc_html( get_admin_page_title() ); ?></h1> 141 <form action='options.php' method='post'> 142 143 <?php 144 //Output nonce, action, and option_page fields for a settings page. 145 settings_fields( 'wli_settings' ); 146 147 // output the settings sections and fields 148 do_settings_sections( 'whos-logged-in' ); 149 150 // form submit button 151 submit_button( 'Save Settings' ); 152 ?> 153 154 </form> 155 </div> 156 157 <?php 158 } 159 160 161 70 162 register_activation_hook( __FILE__, 'wli_plugin_activation' ); 71 163 function wli_plugin_activation() { 164 // get current user and add to logged in users list on plugin activation 72 165 $wli_current_user = wp_get_current_user(); 73 166 update_option( 'wli_logged_in_users', [ $wli_current_user->ID => $wli_current_user->user_login ], '', 'no' ); 167 // default to not automatically kicking users off when plugin is activated 168 update_option( 'wli_settings_general', ['wli_auto_kick_inactive_users' => 0] ); 74 169 } 75 170 … … 78 173 function wli_plugin_deactivation() { 79 174 delete_option( 'wli_logged_in_users' ); 175 delete_option( 'wli_settings_general' ); 80 176 } 81 177 … … 151 247 add_action( 'wp_ajax_wli_ajax_logout_users', 'wli_ajax_logout_users' ); 152 248 function wli_ajax_logout_users() { 153 // get the current user 154 $current_user = wp_get_current_user(); 155 156 // get all sessions for the current user by their ID 157 $sessions = WP_Session_Tokens::get_instance($current_user->ID); 158 159 // now that we have got all of the users sessions, destroy them! 160 $sessions->destroy_all(); 161 249 // check if auto kick users setting is on or off 250 $general_settings = get_option( 'wli_settings_general' ); 251 $value = $general_settings['wli_auto_kick_inactive_users']; 252 // if auto kick is turned on, then proceed to... 253 if($value == 1) { 254 // ...get the current user that triggered this action 255 $current_user = wp_get_current_user(); 256 257 // ...get all sessions for the current user by their ID 258 $sessions = WP_Session_Tokens::get_instance($current_user->ID); 259 260 // ...destroy their sessions, and all of them! 261 $sessions->destroy_all(); 262 } 263 // or else send response to let javascript know not to refresh page on ajax success 264 else { 265 echo "auto-kick-is-turned-off"; 266 } 267 // and then die 162 268 wp_die(); 163 269 }
Note: See TracChangeset
for help on using the changeset viewer.