Bypass a WordPress Password Protected Post or Page via a URL

I have a password protected page that i would like to be accessible with a custom link with the password as get variable in url www.domaine.tld/my-page?code=mycustompassword

I have found this but this is not working Bypass password protected posts via GET variable

Could you pleaser help me to bypass the password form

Regards

Topic password Wordpress

Category Web


instead of using the_content(), use echo apply_filters( 'the_content', $post->post_content ); i could be wrong but i believe that this will bypass the password form entirely, then you can do your own simple logic for whether or not to show the content. In either case however i strongly advise not doing this if the content is very sensitive data. ie. i hope it's not someone's personal information. you will additionally have to make sure the post has a password so that it doesn't show up in search results, sitemaps, feeds, or wp json api endpoints.


You can use the same principle as the worked example, however replace $_GET with $_POST. So you'd have something like this towards the end:

// Your custom check for the '$_POST' content
// …also check if there in fact is a password
// …and if the user is a repeated visitor, do not set the Cookie again
if (
        isset( $_POST['circumvent'] ) 
        and 'disable-pass' === $_POST['circumvent'] 
        and isset( $post->post_password )
        and ! isset( 'wp-postpass_'.COOKIEHASH )
    ) {
    // Finally we use the plain text password to set the Cookie
    // as if the user would have entered it into the password form
    setcookie(
        'wp-postpass_'.COOKIEHASH,
        $hasher->HashPassword( wp_unslash( esc_attr( $post->post_password ) ) ),
        $expire,
        COOKIEPATH
    );
}
// Now display the content:
the_content();

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.