WordPress.org

Ready to get started?Download WordPress

Forums

Overridng the Protected Posts Form HTML? (4 posts)

  1. Matt Hill
    Member
    Posted 5 years ago #

    I'm trying to override the Protected Posts form with my own HTML. A new hook was added in 2.7 to supposedly allow this. However, I think it might be a little broken, or I'm misunderstanding how it works.

    I've created a new function in my functions.php:

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

    As you can see, I've changed the HTML from the original function (in wp-includes\post-template.php). However, the resulting HTML that's generated from my new function has a bunch of extra elements that I didn't specify, and they are in a very odd order! This is what gets generated:

    <form class="inlinepassword" action="http://local.natsel/wp/wp-pass.php" method="post">
    <fieldset><legend>Password protection</legend></p>
    <p>This Job Description is password protected. To view it please enter your password below:</p>
    <p><label for="pwbox-16">Password:</label></p>
    <input name="post_password" id="pwbox-16" type="password" size="20" />
    <button type="submit" id="submit">OK</button><br />
    </fieldset></form>

    As you can see, there is an incorrect closing P tag that's been introduced after my Legend. There is a new P element created around the label which I don't want, and a BR element after the button.

    Where are these extra elements coming from? Why is one of them not constructed properly?

    Any tips would be appreciated.

  2. Matt Hill
    Member
    Posted 5 years ago #

    Anyone?

  3. Matt Hill
    Member
    Posted 5 years ago #

    How about I rephrase my query :-)

    What function in WordPress causes extra line breaks and paragraph tags to be created, and how do I disable its use on password protect forms?

  4. Matt Hill
    Member
    Posted 5 years ago #

    I found out about wpautop and tried removing it using a filter on password form hook, but nothing changes.

    I'd really appreciate any tips you can share, this is driving me nuts. Thanks! :-)

Topic Closed

This topic has been closed to new replies.

About this Topic