Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
What are you asking? I don't understand a single word.... –  kaiser Nov 17 '12 at 13:15
    
Let me try to translate :) "I'd like to set some of my posts to 'protected' but still allow access using a nonce-like passcode in the $_GET string." –  s_ha_dum Nov 17 '12 at 15:07
    
thanks @s_ha_dum that is what I try –  fefe Nov 17 '12 at 16:48

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
thanks a lot,lot. Anyway I wanted to limit the lifespan of each login session. Let me give a try and I'm going to give a feedback soon. –  fefe Nov 17 '12 at 20:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.