stephenjbell

WordPress Check Post Password from anywhere

Nov 28th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. <?php  
  2.  
  3. /* Check if the currently saved page password matches a specific page  */
  4. function page_password_correct($page_id){
  5.     if(isset( $_COOKIE['wp-postpass_' . COOKIEHASH] )){
  6.         require_once ABSPATH . WPINC . '/class-phpass.php';
  7.         $hasher = new PasswordHash( 8, true );
  8.         $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
  9.         $the_post = get_post( $page_id );
  10.         return $hasher->CheckPassword( $the_post->post_password, $hash );
  11.    
  12.     }
  13.     return false;
  14. }
  15.  
  16. ?>
Advertisement
Add Comment
Please, Sign In to add comment