WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] password protected - change message (6 posts)

  1. mores
    Member
    Posted 5 years ago #

    Hey guys and gals,
    I've failed to find the way to change the layout of password protected pages.
    Where do I change the "this post is protected" message, how do I add a contact form so people can write and request a password ... help :)

  2. mores
    Member
    Posted 5 years ago #

    Well no thanks to you people ;) I managed to find the solution myself. There is no theme file that needs editing, so you need to add a filter to your functions.php file in the theme directory. Use this

    function replace_the_password_form($content) {
      global $post;
      // if there's a password and it doesn't match the cookie
      if ( !empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH])!=$post->post_password ) {
        $output = '
    
        <form action="'.get_option('siteurl').'/wp-pass.php" method="post">
          '.__("This post is password protected. To view it please enter your password below:").'
    
            <label for="post_password">Passwort:</label>
            <input name="post_password" class="input" type="password" size="20" />
            <input type="submit" name="Submit" class="button" value="'.__("Submit").'" />
    
        </form>
    
        ';
        return $output;
      }
      else return $content;
    }
    add_filter('the_content','replace_the_password_form');

    Obviously, now you can edit it to your liking.

    I found this info on this site:
    http://simbo.de/blog/wordpress/wordpress-tipp-passwort-formular-bei-geschuetzten-beitraegen-anpassen/

  3. stevehl42
    Member
    Posted 5 years ago #

    awesome, thanks for the help!

  4. jfgrissom
    Member
    Posted 5 years ago #

    Mores you rock!

    This is good stuff... you're the man for posting it...

    NO! You are two men!

    hehe...

    thanks a bunch

  5. fedmich
    Member
    Posted 5 years ago #

    exactly what I need right now!
    Thanks a lot Mores :)

  6. katenutri
    Member
    Posted 4 years ago #

    There is no theme file that needs editing, so you need to add a filter to your functions.php file in the theme directory

    Well, yes there is :)

    You will find the form in /wp-includes/post-template.php it looks like this:

    function get_the_password_form() {
    	global $post;
    	$label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
    	$output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
    	' . __("This post is password protected. To view it please enter your password below:") . '
    
    	<label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . __("Submit") . '" />
    
    	</form>
    	';
    	return apply_filters('the_password_form', $output);
    }

    Solution found here: http://www.dagondesign.com/articles/show-the-intro-to-password-protected-posts-in-wordpress/

Topic Closed

This topic has been closed to new replies.

About this Topic