Title: Unsaved changes
Last modified: December 11, 2017

---

# Unsaved changes

 *  [Marcus Downing](https://wordpress.org/support/users/marcusdowning/)
 * (@marcusdowning)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/)
 * If a user is editing a page and has unsaved changes at the time the logout passes,
   this happens:
 * 1. A popup appears saying, “You have been logged out.”
    2. A popup appears *over*
   that one, with the login box. 3. On logging in, the first popup is still there.
   4. On clicking OK, the user gets a warning from their browser, saying, “Do you
   want to leave this page? Unsaved changes will be lost.”
 * This seems like a quite unfriendly experience. In practice, the user’s changes
   are autosaved and can be recovered quickly enough, but a user may not know this,
   and will find the “your work is gone” situation scary.
 * Why is the first popup there? It doesn’t add anything before the second popup
   appears, nor is it any use afterwards when it’s no longer true.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Deepen Bajracharya](https://wordpress.org/support/users/j_3rk/)
 * (@j_3rk)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9771641)
 * Yes this issue has been mentioned but i don’t see anyway to avoid this situation.
 * 1. This popup is generated by plugin when user is idle for defined time.
    2. 
   This is generated by WordPress(Hearbeat API) when after logged out user is still
   idle on the page. I don’t see a way that i can deactivate anything here. ( Added
   in WP 3.6 refer heartbeat API ) 3. Yes after logging in first popup will still
   be there because no redirects. 4. This cannot be avoided through the plugin itself.
   I don’t see anyway to track user activity on editing here.
 * So this situation cannot be avoided at the moment. First popup is plugin generated
   for logout. Second is generated through WordPress core after user is logged out
   and still inactive or haven’t refreshed the page for some time.
 * Sorry but crrently, the only way to avoid this situation is not be idle when 
   a post is being edited if you do not want redirect otherwise autosave effect 
   is in place.
 * Thanks
 *  Thread Starter [Marcus Downing](https://wordpress.org/support/users/marcusdowning/)
 * (@marcusdowning)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9771720)
 * How about this:
 * In `inactive-layout.js`, instead of the button saying `onclick="window.location.
   reload();"`, instead call a function that uses Ajax to check whether the user
   is currently logged in, and if they are, it dismisses the dialog box instead 
   of reloading.
 * It doesn’t get rid of the two popups, but it does stop people losing work.
 *  Thread Starter [Marcus Downing](https://wordpress.org/support/users/marcusdowning/)
 * (@marcusdowning)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9771728)
 *     ```
       function ina__timeout_ok() {
         jQuery.post(ajaxurl, { action: 'is_user_logged_in' }, function (response) {
           if (response == 'yes') {
             jQuery('#ina__dp_logout_message_box').hide();
           } else {
             window.location.reload();
           }
         });
       }
       ```
   
 *  Thread Starter [Marcus Downing](https://wordpress.org/support/users/marcusdowning/)
 * (@marcusdowning)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9771743)
 * There’s no doubt fine-tuning to make it perfect (such as disabling the button
   in case somebody hits it lots of times).
 *  Thread Starter [Marcus Downing](https://wordpress.org/support/users/marcusdowning/)
 * (@marcusdowning)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9771756)
 * Oh, and you need to add an Ajax action `wp_ajax_is_user_logged_in` and `wp_ajax_nopriv_is_user_logged_in`
   to make it work.
 *  Thread Starter [Marcus Downing](https://wordpress.org/support/users/marcusdowning/)
 * (@marcusdowning)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9771767)
 * btw, all your JS functions should be namespaced. Right now, if another plugin
   tries to make a function called something obvious like `setup`, one or both will
   fail.
 *  Thread Starter [Marcus Downing](https://wordpress.org/support/users/marcusdowning/)
 * (@marcusdowning)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9771832)
 * Here’s a patch that I’ve tested and works:
 *     ```
       diff --git a/assets/js/inactive-logout.js b/assets/js/inactive-logout.js
       index 17747a2..62efa07 100755
       --- a/assets/js/inactive-logout.js
       +++ b/assets/js/inactive-logout.js
       @@ -60,6 +60,16 @@ function goInactive() {
          }
        }
   
       +function ina__timeout_ok() {
       +  jQuery.post(ina_ajax.ajaxurl, { action: 'is_user_logged_in' }, function (response) {
       +    if (response == 'yes') {
       +      jQuery('#ina__dp_logout_message_box').hide();
       +    } else {
       +      window.location.reload();
       +    }
       +  });
       +}
       +
        //Show timeout Message Now
        function showTimeoutMessage() {
          var countdown = 10;
       @@ -104,7 +114,7 @@ function showTimeoutMessage() {
                if( op.redirect_url ) {
                  window.location = op.redirect_url;
                } else {
       -          $('#ina__dp_logout_message_box .ina-dp-noflict-modal-body').html( '<p>' + op.msg + '<p><p class="ina-dp-noflict-btn-container"><a class="btn-timeout" href="javascript:void(0);" onclick="window.location.reload();">OK</a></p>' );
       +          $('#ina__dp_logout_message_box .ina-dp-noflict-modal-body').html( '<p>' + op.msg + '<p><p class="ina-dp-noflict-btn-container"><a class="btn-timeout" href="javascript:void(0);" onclick="ina__timeout_ok();">OK</a></p>' );
                }
                return false;
              });
       @@ -124,7 +134,7 @@ function showTimeoutMessage() {
                    if( op.redirect_url ) {
                      window.location = op.redirect_url;
                    } else {
       -              $('#ina__dp_logout_message_box .ina-dp-noflict-modal-body').html( '<p>' + op.msg + '<p><p class="ina-dp-noflict-btn-container"><a class="btn-timeout" href="javascript:void(0);" onclick="window.location.reload();">OK</a></p>' );
       +              $('#ina__dp_logout_message_box .ina-dp-noflict-modal-body').html( '<p>' + op.msg + '<p><p class="ina-dp-noflict-btn-container"><a class="btn-timeout" href="javascript:void(0);" onclick="ina__timeout_ok();">OK</a></p>' );
                    }
                    return false;
                  });
       @@ -149,4 +159,4 @@ function showTimeoutMessage() {
        */
        function goActive() {
          startTimer();
       -}
       \ No newline at end of file
       +}
       diff --git a/src/inactive-logout-functions.php b/src/inactive-logout-functions.php
       index ad2ef85..1a4bb22 100755
       --- a/src/inactive-logout-functions.php
       +++ b/src/inactive-logout-functions.php
       @@ -16,6 +16,10 @@ class Inactive__Logout_functions {
        		add_action( 'wp_footer', array( $this, 'ina_logout_dialog_modal') );
        		add_action( 'admin_footer', array( $this, 'ina_logout_dialog_modal') );
   
       +    //Ajax for checking if a user is currently logged in
       +    add_action( 'wp_ajax_is_user_logged_in', array( $this, 'ajax_check_user_logged_in' ) );
       +    add_action( 'wp_ajax_nopriv_is_user_logged_in', array( $this, 'ajax_check_user_logged_in' ) );
       +
        		//Ajax for checking last session
        		add_action( 'wp_ajax_ina_checklastSession', array( $this, 'ina_checking_last_session' ) );
        		add_action( 'wp_ajax_nopriv_ina_checklastSession', array( $this, 'ina_checking_last_session' ) );
       @@ -28,6 +32,14 @@ class Inactive__Logout_functions {
        		add_action( 'wp_ajax_ina_get_enabled_roles', array( $this, 'ina_get_enabled_roles' ) );
        	}
   
       +  /**
       +  * Check if a user is currently logged in
       +  */
       +  function ajax_check_user_logged_in() {
       +      echo is_user_logged_in() ? 'yes' : 'no';
       +      die();
       +  }
       +
        	/**
        	* Check Last Session and Logout User
        	*/
       ```
   
 *  Plugin Author [Deepen Bajracharya](https://wordpress.org/support/users/j_3rk/)
 * (@j_3rk)
 * [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9773576)
 * Hello,
 * Always welcomed for contributions.. Although, would appreciate if you send in
   your PRs from git so that i can verify and pull it instead of pasting a git diff
   formatted text.
 * Thanks

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Unsaved changes’ is closed to new replies.

 * ![](https://ps.w.org/inactive-logout/assets/icon-256x256.png?rev=3133765)
 * [Inactive Logout](https://wordpress.org/plugins/inactive-logout/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/inactive-logout/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/inactive-logout/)
 * [Active Topics](https://wordpress.org/support/plugin/inactive-logout/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/inactive-logout/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/inactive-logout/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Deepen Bajracharya](https://wordpress.org/support/users/j_3rk/)
 * Last activity: [8 years, 5 months ago](https://wordpress.org/support/topic/unsaved-changes/#post-9773576)
 * Status: not resolved