Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function doPasswordStuff(){
  2. if(isset($_POST['homepagepassword'])){
  3. global $wpdb;
  4. $post_password = trim($_POST['passwordfield']);
  5. $post_id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_password = %s", $post_password) );
  6. if (!empty($post_id)) {
  7. if ( empty( $wp_hasher ) ) {
  8. require_once( ABSPATH . 'wp-includes/class-phpass.php' );
  9. // By default, use the portable hash from phpass
  10. $wp_hasher = new PasswordHash(8, true);
  11. }
  12. setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $post_password ) ), time() + 864000, COOKIEPATH );
  13. wp_redirect(get_permalink($post_id));
  14. exit();
  15. } else {
  16. // oh dear, there isnt a post with this 'password', put a redirect to a fallback here
  17. wp_redirect('http://address');
  18. exit();
  19. }
  20. wp_reset_query();
  21. }
  22. }
  23. add_action('template_redirect','doPasswordStuff');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement