This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
post_password_expires filter
Filters the life span of the post password cookie.
apply_filters( 'post_password_expires', int $expires )
Description
This is filter hook , which is used for filter the life span of the post password cookie.
Allows you to limit the cookie validity time either to a value passed as a parameter or to the session itself.
By default, the cookie expires 10 days from creation. To turn this into a session cookie, return 0.
Parameters
- $expires : (int) The expiry time, as passed to setcookie().
Live Example
To run the hook, copy the example below.
$time = apply_filters( 'post_password_expires', $time ); if ( !empty( $time ) ) { // everything has led up to this point... }
The following example is for adding a hook callback.
// define the post_password_expires callback function filter_post_password_expires( $time ) { // make filter magic happen here... return $time; }; // add the filter add_filter( 'post_password_expires', 'filter_post_password_expires', 10, 1 );
To remove a hook callback, use the example below.
// remove the filter remove_filter( 'post_password_expires', 'filter_post_password_expires', 10, 1 );
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' );
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.