WordPress.org

Ready to get started?Download WordPress

Forums

How do I change Password Protected text? (25 posts)

  1. gswaim
    Member
    Posted 4 years ago #

    Hi,

    When trying to access a password protected page this text is displayed.

    "This post is password protected. To view it please enter your password below:"

    I would like to change this text to let people know how they can obtain a password. Where do I make these changes. I don't see it in the theme files.

    Thanks in advance for help on this!

  2. Michael Fields
    Themer
    Posted 4 years ago #

    This piece of code should do it for you. Place this code in your theme's functions.php file. You can add customizations to the custom_password_form() function - just don't use print or echo - the function must return a value.

    <?php
    add_filter( 'the_password_form', 'custom_password_form' );
    function custom_password_form() {
    	global $post;
    	$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
    	$o = '<form class="protected-post-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:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
    	</form>
    	';
    	return $o;
    }
    ?>
  3. gswaim
    Member
    Posted 4 years ago #

    Thanks, mfields, this worked!

  4. curvaciousb
    Member
    Posted 4 years ago #

    I'd like to style this function.. any idea how to do that? I usually work on the front end, so I am not very well-versed on php.

  5. Michael Fields
    Themer
    Posted 4 years ago #

    @curvaciousb: Notice that in the function I added a class to the form. You can apply styles to .protected-post-form in your stylesheet.

  6. asbo6544
    Member
    Posted 4 years ago #

    hi could you please explain this a bit more i added your code to the end of the funtions.php form and when i load it i get a fatel error so i have to change it back.

    could anyone let me know where i am going wrong

    thank you

  7. Michael Fields
    Themer
    Posted 4 years ago #

    @asbo6544
    1. What fatal error?
    2. Did you accidentally nest the php tags? <?php ?>.

  8. asbo6544
    Member
    Posted 4 years ago #

    what i did was just add it to the end of the function.php form and removed the <?php from the start of your code.

    this is the error code i get.

    Fatal error: Call to undefined function esc_attr__() in /mounted-storage/home61b/sub001/sc31192-CUDB/doggingukcontacts.com/wp-content/themes/Tech/functions.php on line 172

    afterwards i also tried to remove ?> from the end of the code and also got the same error code.
    is there somewhere where is has to go can it just be added anywhere??

    thank you for your quick reply mfields

  9. Michael Fields
    Themer
    Posted 4 years ago #

    The function esc_attr__() is not defined in you installation of WordPress... which means that you are using a version that is below 2.8.0... which means that your blog is at risk of being compromised by that new evil WordPress worm thing.

    Please upgrade ASAP.

    If this is not an option you can always replace esc_attr__() with attribute_escape(), but be warned this this function is deprecated which means that it may not exist in future releases of WordPress core.

    Best to upgrade.

  10. asbo6544
    Member
    Posted 4 years ago #

    thank you so much for all your help mfields i only wish there was as many people as you around.

    i mananged to find another file that held what i needed to edit but will also upgrade my version of wordpress.

    once again thank you very much for all help.

    ps so when i upgrade to the newest version of wordpress the code above will work and also allow me to style the form???

  11. Michael Fields
    Themer
    Posted 4 years ago #

    @asbo6544 - Thanks for the kind words :) Yes, when you upgrade WordPress, the code I posted above will work just fine, Best wishes.

  12. toyNN
    Member
    Posted 4 years ago #

    Just the script help I needed for controlling the text and initial view of a protected page. Thank you for posting.

    My php is nube level at best so I'm wondering if it's possible to remove the
    that's between the label and the password input? I don't see this from your code.

  13. Michael Fields
    Themer
    Posted 4 years ago #

    You can alter anything inside the custom_password_form() function. I hope this will illustrate:

    custom_password_form(){
       /* Do what ever you want here */
    }

    Hope this helps :)

  14. toyNN
    Member
    Posted 4 years ago #

    Ack sorry I didn't use the correct formating in my post so the tag I wanted to remove was obscured. Again I don't know php that well but the code with the nice function you provded:

    <label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />

    Produces output like:

    Password: <br />
    [Password Input]

    I'd like to remove that <br /> but in your code there's nothing between the </label><input> tags so I don't understand how the break can be removed. Any help appreciated.

  15. Michael Fields
    Themer
    Posted 4 years ago #

    toyNN, I took a look into this and the <br /> is being inserted by the wpautop() function. This function treats the <input> element as a "block". Unfortunately, there is no easy way to filter this function.

    The following solution is not the best, but will work.

    add_filter( 'the_content', 'no_block_for_input', 2000 );
    function no_block_for_input( $c ) {
    	return preg_replace( '/<br \/>\s<input/', '<input', $c );
    }

    Please bear in mind that it will remove all <br /> elements from the beginning of inputs posted via the Edit Post Content box which may be undesirable.... best I could do though :)'

    May be someone else knows how to better address this?

  16. toyNN
    Member
    Posted 4 years ago #

    Appreciate your work on this...I guess is just best to punt on it for now and allow the break tag there for the password input.

    The rest of the add_filter() functions you provided has been great - it allows me to add help and contact text on the protected pages so my users can request help with access/pw. That was most important.

    Thanks again, David

  17. Electric Studio
    Member
    Posted 4 years ago #

    Posts like these are exactly why I love WordPress and it's community!

  18. Geoff Beattie
    Member
    Posted 4 years ago #

    @mfields - Thanks for the help!
    I must be honest and say that I have never edited any php and was a little concerned that I would mes it all up, but I just found an editor, added the code, changed the text and it worked!
    Thankyou.

  19. Michael Fields
    Themer
    Posted 4 years ago #

    @Electric Studio - what an awesome thing to say and I totally agree! I would be lost in web development without help from numerous support forums that I have been a part of... always nice to hear that my efforts are appreciated :)

    @Geoff - glad this worked for you and congrats on your first block of php code!

  20. pitaoj
    Member
    Posted 4 years ago #

    Hi, I have a swedish install of WordPress and have tried finding the text to change. Iif I change the corresponding text in the PO file nothing happens ? Any help much appreciated.

  21. rebeccaclarke
    Member
    Posted 4 years ago #

    Hi everyone,

    Check out the following post. It explains how to password protect a portion of a post, which you can easily use to get rid of the "This post is password protected. To view it please enter your password below:" message.

    http://www.robcooper.com/wordpress/how-to-password-protect-post-page.html

    It's a free plugin for WordPress, and basically everything between the tags [password] and [/password] are password protected. You can type what ever message you want before or after those tags.

    Hope this helps!

    -Rebecca

  22. seenmich
    Member
    Posted 4 years ago #

    Hi everyone,

    Just came across this issue today. Here's the best solution I could find. In your post-template.php, (found in wp-includes) open it in Dreamweaver and hit control+F (find). Search for This post is password protected. To view it please enter your password below. Change the phrase to whatever you'd like it to say!
    Hope this helps!

    -Shaun

  23. Brian
    Member
    Posted 3 years ago #

    This was awesome. A quick google search and here I was to my answer. Worked like a charm. Thanks for contributing!

  24. laowaichinese
    Member
    Posted 3 years ago #

    Is there an easy way to add something to that ".protected-post-form" thing in the stylesheet to change the password input type from "password" to "text"? I don't want the letters to be hidden (******) when inputting the password.

    Thanks anyone.

  25. esmi
    Forum Moderator
    Posted 3 years ago #

    You'd need to change the input from type="password to type="text. You can't make that change via CSS,

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.