• Hi,

    Im using wordpress twentyten and I wanted to change the standard text displayed for a password protected page. I followed the directions for other posts and copied functions.php to my child theme and then edited it by adding the following code to the bottom of my functions.php file:

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

    It seemed to work fine and then I got a fatal error. What did I do wrong?

    Jeremy
    camptopeinu.com

Viewing 12 replies - 1 through 12 (of 12 total)
  • Jeremy,

    This method no longer seems to work since the newest WordPress update. I had a custom password text message and it disappeared when I updated WordPress. I am waiting for an answer regarding how to fix this problem, too.

    Thread Starter jmerr59944

    (@jmerr59944)

    please let me know if you hear anything. I have a bigger problem now. If I even copy the functions.php to my child theme WITHOUT making changes to it, the site goes down with a fatal error message!

    Jeremy,

    Yes I had that problem, too. You need to access the file manager your host provides, copy that file, remove it from the child theme, and put it back where it was. Your host may even help you with this. The functions.php file cannot be added to a child theme. If you make changes to that file, just keep a copy of the edited file.

    http://codex.wordpress.org/Child_Themes#Using_functions.php

    you need to start with an empty functions.php in the child theme.

    try this code:

    function my_password_form() {
    global $post;
    	$post = get_post( $post );
    	$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );
    	$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
    	<p>' . __( 'This content is certainly password protected. To view it please enter your password below:' ) . '</p>
    	<p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__( 'Submit' ) . '" /></p>
    	</form>
    	';
    return $output;
    }
    add_filter('the_password_form','my_password_form');

    based on the latest code from /wp-includes/post-template.php line 1238++ of the function get_the_password_form( $post = 0 )

    alchymyth,

    Thanks for the code. If added directly to the functions.php file like the fix that used to work, it breaks the site.

    If added to a new, blank, functions.php page in the child theme, the code weirdly appears above the header on every web page on the site. See: http://www.catalysthealthmedia.com

    This is the code that used to work by adding it to the bottom of the functions.php theme file prior to the WordPress 3.7x update. Can it be edited some way to make it work again?

    // Password Protected Page Message
    function custom_password_form($form) {
    $subs = array(
    ‘#<p>This post is password protected. To view it please enter your password below:</p>#’ =>

    ‘<p>CUSTOM PASSWORD MESSAGE</p></br></br>’,

    ‘#<form(.*?)>#’ => ‘<form$1 class=”passwordform”>’,
    ‘#<input(.*?)type=”password”(.*?) />#’ => ‘<input$1type=”password”$2 class=”text” />’,
    ‘#<input(.*?)type=”submit”(.*?) />#’ => ‘<input$1type=”submit”$2 class=”button” />’
    );

    echo preg_replace(array_keys($subs), array_values($subs), $form);
    }

    add_filter(‘the_password_form’, ‘custom_password_form’);

    If added to a new, blank, functions.php page in the child theme, the code weirdly appears above the header

    please read the posted Codex links.

    http://codex.wordpress.org/Child_Themes#Using_functions.php

    The structure of functions.php is simple: An opening PHP tag at the top, a closing PHP tag at the bottom, and, between them, your bits of PHP.

    your new empty functions.php needs to start with this in the first line (nothing whatsoever before that):

    <?php

    and may end with this as last line (nothing whatsoever after that):

    ?>

    I have no idea how to write code, alchymyth, so I didn’t know I had to precede and end the code with those tags. Not only did that solve that problem, but I was able to swap out the message for my custom message, which now appears on my password protected pages.

    Thanks A LOT for your help, this fix will help many people!!!

    Thread Starter jmerr59944

    (@jmerr59944)

    seemed to work, but when I added the edited text for the password protection, I am getting this:

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/48/12049648/html/wp-content/themes/twentyten-child/functions.php:14) in /home/content/48/12049648/html/wp-includes/pluggable.php on line 899

    Thread Starter jmerr59944

    (@jmerr59944)

    and now its working…so weird…but thanks!

    Thanks for the help, alchymyth.

    Sorry to bump an oldish thread…

    and may end with this as last line (nothing whatsoever after that):

    ?>

    Does that mean that the closing php tag is optional? (Obviously I’m not a coder). My current functions.php in my twenty eleven child theme has no closing tag. The entire contents of the child functions.php is this:

    <?php
    //after theme setup section
    add_action( 'after_setup_theme', 'twentyeleven_child_theme_setup' );
    function twentyeleven_child_theme_setup() {
    define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) );
    define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 200 ) );
    }

    I’m wanting to customize the password protection text but I’m terrified of breaking my site! If I add the php code from the codex at the end of my current functions.php and add a closing ?> will that do the trick?

    Answered my own question – yes it worked πŸ™‚ Thanks to all on this thread

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Text Change on Password Protected Page’ is closed to new replies.