Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $post_password ) ), time() + 864000, COOKIEPATH );
- wp_redirect(get_permalink($post_id));
- exit();
- } else {
- // oh dear, there isnt a post with this 'password', put a redirect to a fallback here
- wp_redirect('http://address');
- exit();
- }
- wp_reset_query();
- }
- }
- add_action('template_redirect','doPasswordStuff');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement