Plugin Directory

Changeset 2324049


Ignore:
Timestamp:
06/14/2020 10:54:08 PM (6 years ago)
Author:
bhartlenn
Message:

Uploading version 1.2 of Who's Logged In plugin to wordpress plugins repository, and svn tagged version 1.2 for future use.

Location:
whos-logged-in
Files:
2 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • whos-logged-in/tags/1.2/js/wli-script.js

    r2201746 r2324049  
    11jQuery(document).ready(function($){
    2     // every XXXX seconds(1000 == 1 second) make ajax call for user list
     2    // every XXXX seconds(1000 == 1 second) make ajax call to update user list
    33    setInterval(function(){
    44        $.post(
     
    1414    }, 15000); // 15000ms = 15 seconds
    1515
    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
    1817        function wliLogoutUsers() {
    1918      $.post(
     
    2322              security: wli_js_vars.secret_nonce
    2423          },
    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                        }   
    2729          }
    2830      );
    2931        }
    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
    3134        function wliStartLogoutTimer() {
    32             wliTimeout = window.setTimeout(wliLogoutUsers, 900000); // 900000ms = 15 minutes
     35            wliTimeout = window.setTimeout(wliLogoutUsers, 5000); // 1,200,000ms = 20 minutes
    3336        }
    34         // Clear the timer if user comes back to current tab/window
     37        // 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
    3538        function wliClearLogoutTimer() {
    36             window.clearTimeout(wliTimeout);
     39            if(wliTimeout != "") {
     40                window.clearTimeout(wliTimeout);
     41            }
    3742        }
    3843       
     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
    3945        window.addEventListener( 'blur', wliStartLogoutTimer );
    4046        window.addEventListener( 'focus', wliClearLogoutTimer );
  • whos-logged-in/tags/1.2/readme.txt

    r2201753 r2324049  
    44Tags: logged-in, activity, dashboard, metabox
    55Requires at least: 4.0
    6 Tested up to: 5.3
     6Tested up to: 5.4.2
    77Requires PHP: 5.6
    8 Stable tag: 1.1
     8Stable tag: 1.2
    99License: GPLv3
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1111
    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 in
     12The 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
    1313
    1414== Description ==
     
    1717
    1818== 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/
    2020
    2121== Installation ==
    2222
    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.
     231. Search for and install the Who's Logged In plugin from the "Plugins" section of your WordPress dashboard.
     242. Once installed, activate the plugin from the same "Plugins" section of your WordPress Dashboard.
     253. 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 
     31You 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
     35Check 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.
    2636
    2737== Screenshots ==
    2838
    29391. The Who's Logged In Metabox that gets added to your Dashboard home page.
     402. Showing the location of the Who's Logged In plugin settings page.
    3041
    3142== 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.
    3246
    3347= 1.1 =
     
    3650== Upgrade Notice ==
    3751
    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  
    33/*
    44  Plugin Name: Who's Logged In
    5   Description: Displays a metabox in your WordPress Dashboard page that builds a list of users that log in and log out
    6   Version: 1.1
     5  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
    77  Author: Ben HartLenn
    88  Author URI: bhartlenn@gmail.com
     
    1111  License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1212
    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) 2017  Ben HartLenn
     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 15 seconds!
     14  Copyright (C) 2020  Ben HartLenn
    1515
    1616  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.
     
    2323  along with The Who's Logged In plugin. If not, see <http://www.gnu.org/licenses/>.
    2424
    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!
    2626 */
    2727
     
    4040    $wli_token_users_array = wp_list_pluck($wli_token_user_objects, 'user_login');
    4141   
    42     // initialize output variable
    43     $wli_logged_in_users_output = "";
    44    
    4542    // 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
    4643    foreach( $wli_logged_in_users as $wli_user_id => $wli_user_login )  {
     
    4946        }
    5047    }
     48   
     49    // initialize output variable
     50    $wli_logged_in_users_output = "";
    5151   
    5252    // build user list output for display
     
    6666    update_option( 'wli_logged_in_users', $wli_logged_in_users, '', 'no' );
    6767}
    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
     73add_action( 'admin_menu', 'wli_add_settings_page' );
     74function 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
     86add_action( 'admin_init', 'wli_settings_init' );
     87function 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
     116function wli_settings_general_section_callback() {
     117}
     118
     119// render checkbox field for kicking users automatically
     120function 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
     132function 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
    70162register_activation_hook( __FILE__, 'wli_plugin_activation' );
    71163function wli_plugin_activation() {
     164    // get current user and add to logged in users list on plugin activation
    72165    $wli_current_user = wp_get_current_user();
    73166    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] );
    74169}
    75170
     
    78173function wli_plugin_deactivation() {
    79174    delete_option( 'wli_logged_in_users' );
     175        delete_option( 'wli_settings_general' );
    80176}
    81177
     
    151247add_action( 'wp_ajax_wli_ajax_logout_users', 'wli_ajax_logout_users' );
    152248function 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
    162268    wp_die();
    163269}
  • whos-logged-in/trunk/js/wli-script.js

    r2201746 r2324049  
    11jQuery(document).ready(function($){
    2     // every XXXX seconds(1000 == 1 second) make ajax call for user list
     2    // every XXXX seconds(1000 == 1 second) make ajax call to update user list
    33    setInterval(function(){
    44        $.post(
     
    1414    }, 15000); // 15000ms = 15 seconds
    1515
    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
    1817        function wliLogoutUsers() {
    1918      $.post(
     
    2322              security: wli_js_vars.secret_nonce
    2423          },
    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                        }   
    2729          }
    2830      );
    2931        }
    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
    3134        function wliStartLogoutTimer() {
    32             wliTimeout = window.setTimeout(wliLogoutUsers, 900000); // 900000ms = 15 minutes
     35            wliTimeout = window.setTimeout(wliLogoutUsers, 5000); // 1,200,000ms = 20 minutes
    3336        }
    34         // Clear the timer if user comes back to current tab/window
     37        // 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
    3538        function wliClearLogoutTimer() {
    36             window.clearTimeout(wliTimeout);
     39            if(wliTimeout != "") {
     40                window.clearTimeout(wliTimeout);
     41            }
    3742        }
    3843       
     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
    3945        window.addEventListener( 'blur', wliStartLogoutTimer );
    4046        window.addEventListener( 'focus', wliClearLogoutTimer );
  • whos-logged-in/trunk/readme.txt

    r2201753 r2324049  
    44Tags: logged-in, activity, dashboard, metabox
    55Requires at least: 4.0
    6 Tested up to: 5.3
     6Tested up to: 5.4.2
    77Requires PHP: 5.6
    8 Stable tag: 1.1
     8Stable tag: 1.2
    99License: GPLv3
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1111
    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 in
     12The 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
    1313
    1414== Description ==
     
    1717
    1818== 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/
    2020
    2121== Installation ==
    2222
    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.
     231. Search for and install the Who's Logged In plugin from the "Plugins" section of your WordPress dashboard.
     242. Once installed, activate the plugin from the same "Plugins" section of your WordPress Dashboard.
     253. 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 
     31You 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
     35Check 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.
    2636
    2737== Screenshots ==
    2838
    29391. The Who's Logged In Metabox that gets added to your Dashboard home page.
     402. Showing the location of the Who's Logged In plugin settings page.
    3041
    3142== 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.
    3246
    3347= 1.1 =
     
    3650== Upgrade Notice ==
    3751
    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  
    33/*
    44  Plugin Name: Who's Logged In
    5   Description: Displays a metabox in your WordPress Dashboard page that builds a list of users that log in and log out
    6   Version: 1.1
     5  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
    77  Author: Ben HartLenn
    88  Author URI: bhartlenn@gmail.com
     
    1111  License URI: https://www.gnu.org/licenses/gpl-3.0.html
    1212
    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) 2017  Ben HartLenn
     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 15 seconds!
     14  Copyright (C) 2020  Ben HartLenn
    1515
    1616  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.
     
    2323  along with The Who's Logged In plugin. If not, see <http://www.gnu.org/licenses/>.
    2424
    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!
    2626 */
    2727
     
    4040    $wli_token_users_array = wp_list_pluck($wli_token_user_objects, 'user_login');
    4141   
    42     // initialize output variable
    43     $wli_logged_in_users_output = "";
    44    
    4542    // 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
    4643    foreach( $wli_logged_in_users as $wli_user_id => $wli_user_login )  {
     
    4946        }
    5047    }
     48   
     49    // initialize output variable
     50    $wli_logged_in_users_output = "";
    5151   
    5252    // build user list output for display
     
    6666    update_option( 'wli_logged_in_users', $wli_logged_in_users, '', 'no' );
    6767}
    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
     73add_action( 'admin_menu', 'wli_add_settings_page' );
     74function 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
     86add_action( 'admin_init', 'wli_settings_init' );
     87function 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
     116function wli_settings_general_section_callback() {
     117}
     118
     119// render checkbox field for kicking users automatically
     120function 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
     132function 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
    70162register_activation_hook( __FILE__, 'wli_plugin_activation' );
    71163function wli_plugin_activation() {
     164    // get current user and add to logged in users list on plugin activation
    72165    $wli_current_user = wp_get_current_user();
    73166    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] );
    74169}
    75170
     
    78173function wli_plugin_deactivation() {
    79174    delete_option( 'wli_logged_in_users' );
     175        delete_option( 'wli_settings_general' );
    80176}
    81177
     
    151247add_action( 'wp_ajax_wli_ajax_logout_users', 'wli_ajax_logout_users' );
    152248function 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
    162268    wp_die();
    163269}
Note: See TracChangeset for help on using the changeset viewer.