elmanisero

Custom Password Form with email

Sep 2nd, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. /**********************************************
  2. * Custom Password Form
  3. **********************************************/
  4. add_filter( 'the_password_form', 'custom_password_form' );
  5.  
  6. function custom_password_form() {
  7. global $post;
  8. $label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
  9. $o = '<form class="protected-post-form form-inline" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post">
  10. <input class="input-medium" placeholder="Password" name="post_password" id="' . $label . '" type="password" /> <button type="submit" name="Submit" class="btn btn-primary">Submit</button>
  11. </form><p>This page is password protected. <a href="mailto:[email protected]">Contact us</a> in case you have lost your password or want to register for access. Thank you</p>
  12. ';
  13. return $o;
  14. }
  15.  
  16. /**
  17. * Add a message to the password form.
  18. *
  19. * @wp-hook the_password_form
  20. * @param string $form
  21. * @return string
  22. */
  23. add_filter( 'the_password_form', 'wpse_71284_custom_post_password_msg' );
  24.  
  25. function wpse_71284_custom_post_password_msg( $form )
  26. {
  27. // No cookie, the user has not sent anything until now.
  28. if ( ! isset ( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) )
  29. return $form;
  30.  
  31. // We have a cookie, but it doesn’t match the password.
  32. $msg = '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">&times;</button><p>The password you submitted was incorrect.</p></div>';
  33.  
  34. return $msg . $form;
  35. }
  36.  
  37. /**
  38. * Remove Protected: from Title
  39. */
  40.  
  41. add_filter('protected_title_format', 'blank');
  42. function blank($title) {
  43. return '%s';
  44. }
Advertisement
Add Comment
Please, Sign In to add comment