1

I wanted to delete all the cookies set for password protected posts when user logged out from the site after going through those Password protected posts.

Is there any function to do this?

1

The post password cookie is set with:

setcookie( 
    'wp-postpass_' . COOKIEHASH, 
     $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), 
     $expire, 
     COOKIEPATH, 
     COOKIE_DOMAIN, 
     $secure 
);

in the wp-login.php file.

We can then use the clear_auth_cookie hook, in the wp_clear_auth_cookie() function, to clear it on logout:

/**
 * Clear the Post Password Cookie on logout.
 *
 * @link http://wordpress.stackexchange.com/a/198890/26350
 */
add_action( 'clear_auth_cookie', function()
{    
    setcookie(  
       'wp-postpass_' . COOKIEHASH, 
       '', 
       time() - YEAR_IN_SECONDS, 
       COOKIEPATH, 
       COOKIE_DOMAIN 
    );
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.