function auto_login_protected_page() {
if (isset($_GET[‘pw’])) {
$password = sanitize_text_field($_GET[‘pw’]);
$post = get_post();
if ($post && $post->post_password == $password) {
// Set cookie to simulate form submission
setcookie(‘wp-postpass_’ . COOKIEHASH, $password, time() + 864000, COOKIEPATH);
// Redirect to remove the password from the URL
wp_redirect(get_permalink($post));
exit;
}
}
}
add_action(‘template_redirect’, ‘auto_login_protected_page’);

Scroll to Top