SHARE
TWEET

Untitled

a guest Apr 27th, 2017 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if ( isset ($_POST['post_password'] ) ) custom_postpass_check();
  2.  
  3. function custom_password_form( $out ) {
  4.     $out = str_replace('wp-login.php', '', $out);
  5.     return $out;
  6. }
  7. add_filter( 'the_password_form', 'custom_password_form', 10, 1 );
  8.  
  9. function custom_postpass_check(){
  10.     $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
  11.     if ( ! array_key_exists( 'post_password', $_POST ) ) {
  12.         wp_safe_redirect( wp_get_referer() );
  13.         exit();
  14.     }
  15.  
  16.     $hasher = new PasswordHash( 8, true );
  17.  
  18.     $expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
  19.     $referer = wp_get_referer();
  20.     if ( $referer ) {
  21.         $secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
  22.     } else {
  23.         $secure = false;
  24.     }
  25.     setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
  26.  
  27.     wp_safe_redirect( wp_get_referer() );
  28.     exit();
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top