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
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.
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();
}
});
}
There’s no doubt fine-tuning to make it perfect (such as disabling the button in case somebody hits it lots of times).
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.
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.
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
*/
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