1

Wordpress is being used on a site I'm helping out on where we're trying to get some accurate statistics from the users logged in on the site. Specifically, we want time they are active and we want to automatically log them out when they're inactive.

I've seen several plugins that do auto-logout type things, but they only check on page load due to the nature of the PHP plugins being server side.

We need some client-side solution that logs them out when idle (potentially giving them a pop up to click so that they don't get logged out).

I've seen some topics on this here:

php ajax auto logout with timer

How can I detect with JavaScript/jQuery if the user is currently active on the page?

But I'm not sure how I can apply this to every page on the wordpress site short of just editing the source. That's possible of course, but I don't think that's the right solution.

So, I think I can handle the code to detect user activity, the topics I linked help with that. I'm not sure about actually logging out the user from the site. I'm not super familiar with jQuery and AJAX solutions, throwing Wordpress into the mix doesn't help much either.

Community
  • 1
  • 1
Wuzseen
  • 687
  • 3
  • 14
  • 20
  • 1
    You probably need to start with a tutorial on how Wordpress plugins work, and read a little in the codex. A plugin will work on all pages, and logging someone out is just a matter of a few lines of code. Figuring out the Wordpress Ajax system is a little harder, and I'd wait until I grasped the essentials before I started on that. – adeneo Feb 03 '13 at 22:37
  • I've got a good grasp on how the plugins work, I've had to modify a bunch to get some auto-logout functionality working on the server side. But the problem is, if the user doesn't go to a new page then I can't tell if they were idle for 20 minutes or 2 hours. The plugins are all server-side so that doesn't really help me with this problem, or am I wrong with that? (Again, I'm not super familiar with wordpress) I just can't seem to find anything. – Wuzseen Feb 03 '13 at 22:40
  • If the user stays on the page, javascript is probably what you're looking for, and then just send an ajax request to a serverside script that logs the user out, but ajax is handled a little differently in Wordpress, at least if you're doing it according to the manual. You could just do a redirect to a logout page based on a javascript timer, would be much simpler. – adeneo Feb 03 '13 at 22:45
  • That sounds almost exactly like what I'm looking for here. I just am unsure of how to integrate all that into Wordpress. Am I looking to make a plugin that inserts the relevant javascript into each and every page? – Wuzseen Feb 03 '13 at 22:47
  • This wordpress plugin: http://wordpress.org/extend/plugins/html-javascript-adder/ That seems to be a potential solution for shipping this code to every page, or is there something lighter? – Wuzseen Feb 03 '13 at 22:55
  • 1
    You can either use a plugin, hardcode the script tag into header.php, or use wp_enqueue_script() in a plugin to add the script. All methods will automatically work on all your pages. – adeneo Feb 04 '13 at 00:21
  • Awesome man, thanks for the help. I've more or less got it under control now. – Wuzseen Feb 04 '13 at 01:55

0 Answers0