0

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

0

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();
  • Hello thanks fot anwser i got this : PHP Fatal error: Call to a member function HashPassword() on a non-object in /home/test-user/public_html/wp-content/themes/default/template-landing-private.php on line 81 – JCF Jan 23 '17 at 14:51
  • You may need to add global $hasher; at the start. Otherwise can you post the entire file? – fergbrain Jan 23 '17 at 14:56
  • /* Template Name: TEST */ if ( isset( $_GET['code'] ) and 'mycustompassword' === $_GET['code'] and isset( $post->post_password ) and null !== 'wp-postpass_'.COOKIEHASH //!isset( 'wp-postpass_'.COOKIEHASH ) ) { setcookie( 'wp-postpass_'.COOKIEHASH, $hasher->HashPassword( wp_unslash( esc_attr( $post->post_password ) ) ), $expire, COOKIEPATH ); } get_header(); while ( have_posts() ) : the_post(); the_content(); endwhile; get_footer(); – JCF Jan 23 '17 at 15:10
  • Please post your code between back ticks (`) so that it's formatted properly – fergbrain Jan 23 '17 at 15:17
  • Hello, sorry i have post an anwser below with the complete code. Thanks ! – JCF Jan 23 '17 at 15:23
0

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.

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.