Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Password protecting posts, browser cookie timelimit WordPress

  • SOLVED

Hi Guys

I have a client who wants to password protect his post (which is pretty straight forward) but he also wants to put a time limit on the access. For example if the client leaves his browser and comes back he wants them to have to log in again.

Is this some that is possible? Maybe with a custom function or plugin

He had the functionality installed in the core code originally (he says) and since i've updated his core software that functionality is lost.

(I've given him the dont customise the core code lecture! :))

Any thoughts would be greatly appreciated

thanks
Steve

Answers (1)

2013-03-12

Navjot Singh answers:

Try [[LINK href="http://wordpress.stackexchange.com/a/24605"]]this solution[[/LINK]].


Steve Watson comments:

Does the default cookie expire after two days anyway?


Navjot Singh comments:

[[LINK href="http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie"]]2 days[[/LINK]] if you don't set the remember me checkbox and 2 weeks if you set it.


Navjot Singh comments:

This solution expands or shortens the two weeks value which is set by the checkbox. If you don't set the checkbox, it will expire in 2 days anyway.


Steve Watson comments:

Are we talking about his solution:

function keep_me_logged_in_for_1_year( $expirein ) {
return 31556926; // 1 year in seconds
}
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' );

I'm not a coder so can you give me an example of how I would edit that function to shorten the two week value please?


Navjot Singh comments:

31556926 is number of seconds in 1 year. Just calculate the time you need to shorten it to and calculate the seconds in it and replace 31556926 with it. Like for 3 days, just set it to 259200. And then add this function in your theme's function.php file or you can add it as a custom plugin.


Steve Watson comments:

can I change the title of the function to "keep_me_logged_in_for_4_hours" in both places or will that mess it up?

sorry my php knowledge is not good :)


Navjot Singh comments:

Yes you can change it at both the places to anything you want. It will work.


Steve Watson comments:

Thanks Navjot. Really helpful :)