WordPress protected Pages

Would be possible to access the protected pages with password through of a token. What I mean I pass the token by URL, is going to be checked if the page is protected, if yes check if the URL has the token than the token to be check if match or not.

Related posts

Leave a Reply

1 comment

  1. The protected post system uses POST so by default, no you can’t. However, here is a bare-bone mechanism that will let you do this.

    function bypass_protected_post() {
      if (is_single()) {
        global $post,$_GET;
        if (isset($post->post_password)) {
          $bypasskey = get_post_meta($post->ID, 'bypasskey', true);
          if (isset($_GET['bypasskey']) && $_GET['bypasskey'] == $bypasskey) {
            $post->post_password = null;
          }
        }
      }
    }
    add_action('wp_head','bypass_protected_post');
    

    You need to set the bypasskey value for the post using the normal custom meta fields form. You’d access the protected post by tacking ?bypasskey=<whatever> onto the URL. Place this in your theme’s functions.php and you are good to go.

    Consider this a sort-of proof-of-concept. I don’t think I’d implement it exactly as it is. I’d probably put it in a plugin and use one-time keys or keys with a limited lifespan– say two or three days. And maybe include a random key generator.