WordPress protected Pages

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.

Leave a Comment