• hi , i use word press 3.9.2

    i have some password protected pages and posts

    they work well and wants password for see them , but after i enter password and open a protected post or pages

    they will not act like a protected page anymore !! they are just like normal posts !!

    it` too bad for me cause maybe my costumers that have these pass open these pages in coffee net or somewhere like that !!

    i read some post about clear cookie after a few min but they are not obvious and they are for wp 3.4 ( wp-pass.php)

    i found this on wp-login:
    $expire = apply_filters( ‘post_password_expires’, time() + 10 * DAY_IN_SECONDS );

    but no clue it`s what i need or not and how can i define a time for example 5 minutes !

    i have no user login in my site and the password protected is nice for me .

    it will be Great if there is a way to clear cookie or cache after close the window of browsers or a few minutes after entering pages or posts ?

Viewing 9 replies - 1 through 9 (of 9 total)
  • I’ve not tested this but you should be able to do this with the filter you found:

    function arioman_post_pass_to_session( $expires ) {
        return 0;
    }
    add_filter( 'post_password_expires', 'arioman_post_pass_to_session' );

    You would place this in a child theme functions.php or a small custom plugin and it would turn the post password into a session cookie. This would mean that the cookie would expire as soon as the browser was fully closed.

    Thread Starter arioman

    (@arioman)

    thanks so much for reply

    only a few questions :

    is arioman_post_pass_to_session a name of function and can replace by any words ??

    2- this is great for browser fully closed , but can you help me how add a time expire ( for example 5 min ) to clear password cookies ?

    cause sometimes maybe they don’t close the window or forget to close it

    1. That is a function name. It should have a unique prefix to avoid conflicts and be descriptive enough to tell you what the function is doing.
    2. If you look at the develop page I linked to you can change the return of zero to something else to set a specific expires date.
    Thread Starter arioman

    (@arioman)

    sorry i`m really amateur in code

    i see and read a link
    apply_filters ( ‘post_password_expires’, int $expires )

    but it`s a general help and not mentioned about how specify the time ( for example by sec or minutes ? )

    and when i put your code in my function.php and save m the code show on top of site as text !! why this happened ??

    is this matter what line in function.php must paste it ??!

    Thread Starter arioman

    (@arioman)

    well seems i solve the code problem and put it on function.php of my theme successfully !!

    but still after i enter a protected page once , i close Firefox and try to reach protected page again and page load without protecting !!

    i must go to Firefox privacy and clear all cookies and temp to see the protect code box again !!

    whats the problem ??

    i have W3 Total cache plugin but i put the link of protected pages in never cache this pages Options

    This would only work for new sessions. You probably need to delete cookies to remove any that may be holding your expires. Caching could also prevent this from working as desired.

    Thread Starter arioman

    (@arioman)

    thanks for useful info

    do you have any idea how can i delete cookies after a specific time ?

    what function i need ??

    it`s very strange why wordpress put the protected page option by default and not thinking about cache and cookie problem

    cause it can`t called protected page if ask password only one time on every system !!

    The function I provided will do just that. You just need to change the return to be your specified time. For instance, if you wanted the cookie to be deleted after one day you would return time() + DAY_IN_SECONDS.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘pass-protected pages and posts not protected after enter them 1 time’ is closed to new replies.