PHP dopasswordstuff

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

PHP dopasswordstuff

Post by D Willett »

Guys. Not sure if we have any php guru's on board but I'll ask anyway.

The following php is stored as a template in my Wordpress site:

Code: Select all

<?php /*
function dopasswordstuff(){
   if(isset($_POST['homepagepassword'])) {
    global $wpdb;
    $post_password = trim($_POST['passwordfield']);
    $post_id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_password = %s", $post_password) );
    if (!empty($post_id)) {
      if ( empty( $wp_hasher ) ) {
        require_once( ABSPATH . 'wp-includes/class-phpass.php' );
        // By default, use the portable hash from phpass
        $wp_hasher = new PasswordHash(8, true);
      }
      // 10 days
      setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $post_password ) ), time() + 864000, COOKIEPATH );
      wp_redirect(get_permalink($post_id));
    }
    exit;
  }
}
add_action('template_redirect','dopasswordstuff');

?>
How do I call this from a new page?
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: PHP dopasswordstuff

Post by HansV »

Sorry about the lack of replies. You may be better off asking your question in a PHP-specific forum, e.g.
http://board.phpbuilder.com/" onclick="window.open(this.href);return false;
http://www.codingforums.com/" onclick="window.open(this.href);return false; (general coding board; they have a PHP forum)
http://www.devnetwork.net/" onclick="window.open(this.href);return false;
http://www.php-forum.com/phpforum/" onclick="window.open(this.href);return false;
Best wishes,
Hans

User avatar
kdock
5StarLounger
Posts: 720
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: PHP dopasswordstuff

Post by kdock »

Dave,

Is this a plugin? What is it supposed to do? Maybe unlock a passworded post? Have you tried the WordPress forums?

And if it's a plugin, it should automatically kick in for any post that meets the criteria of the plugin. Unless the plugin is invoked with a shortcode? Do you know who wrote the plugin so you can check with the author or others who've used it?

And that about exhausts my ability to assist on this.

Best, Kim
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: PHP dopasswordstuff

Post by D Willett »

Hi Kim. Yes its a php routine to direct a user to a protected post, I tried the code with a html submit form but it didn't work.
Basically it returned nothing so I couldn't even suggest any error statements.

It seems though to be quite a useful function once working.
I'll check back on the Wordpress forums.

Thanks for the links Hans.

Regards all.
Cheers ...

Dave.