Support » Fixing WordPress » post_password_expires

  • Resolved ripriprip

    (@ripriprip)


    I would like to use this code, to be sure that the password would need to be entered upon each new session. as indicated here:
    https://developer.wordpress.org/reference/hooks/post_password_expires/

    However, I don’t have a child theme, so I can’t change the code as mentioned here.
    https://wordpress.org/support/topic/password-protection-33/

    I’m am learning, so terminology is hard for me.
    Can someone show me where the “0” is suppose to go in this code snip?

    1
    2
    3
    4
    5
    6
    7
    function Modif_expir_cookie( $time ) { 
      return time() + 600 ;  // 10 mn
      // for 5 minutes :  
      // return time() + 300;  in this case 60 * 5 
      // return 0; set cookie to expire at the end of the session
    }
    add_filter('post_password_expires', 'Modif_expir_cookie' );

    Can I put it into my plugin called “Code Snippets”? (free version)
    https://codesnippets.pro/about/

    If I can, can someone explain how to do that?

    or I guess I just put it into my theme’s functions.php file? But then I have to worry about it every time the theme upgrades?

    Thank you in advance, Tammy

    • This topic was modified 1 year, 7 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Prin a11n

    (@prin_settasatian)

    Hello there,

    I understand you would like to use the code that you mentioned on your site.

    Yes, you can use the Code Snippets plugin (https://wordpress.org/plugins/code-snippets/) to do this.

    After installing and activating the plugin:
    1. Go to your site’s dashboard.
    2. On the left sidebar, click on Snippets.
    3. Click on the Add New button.
    4. Paste your code in the box (make sure the Functions tab is selected).
    5. Click on the Save Changes and Activate button.

    Let me know if you need further help.

    Thread Starter ripriprip

    (@ripriprip)

    Thank you, I do need further help, I don’t understand where to put the 0 ? as in this comment.

    // return 0; set cookie to expire at the end of the session
    }

    could someone paste the code, exactly how I am to paste it into my code snippets, please?

    Thank you so much.
    Tammy

    Prin a11n

    (@prin_settasatian)

    Hi @ripriprip,

    You will need to replace the line return time() + 600 ; with return 0;, so:

    function Modif_expir_cookie( $time ) { 
      return 0;
    }
    add_filter('post_password_expires', 'Modif_expir_cookie' );

    Hope this helps.

    Thread Starter ripriprip

    (@ripriprip)

    Thank you.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @ripriprip I’m sorry but this topic is being closed. Here’s why.

    You wrote this. It’s archived now but moderators can still see it.

    do you do small paid code modification projects? I might need some help, for functionality above my abilities. [email redacted ] -I hope you don’t mind me asking.

    Per the forum guideline I am now closing this topic.

    https://wordpress.org/support/guidelines/#do-not-offer-to-pay-for-help

    If you need to hire someone please consider posting to https://jobs.wordpress.net/ instead.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘post_password_expires’ is closed to new replies.