Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#4721 closed defect (bug) (fixed)

Password-Protected Post Delivers WAI-Unfriendly Code

Reported by: cmarshall's profile cmarshall Owned by: nazgul's profile Nazgul
Milestone: 2.5 Priority: normal
Severity: minor Version: 2.2.2
Component: Template Keywords: has-patch
Focuses: Cc:

Description

Very simple. The form emitted by the password-protected post (in place of the content) does not meet basic WAI guidelines (label associated with form element using the for= attribute). Normally, I would rewrite this myself, but this is generated by the core (get_the_password_form in post-template.php).

If there is a simple workaround or overload, that would be great. I will be trying to figure out if I can overload it, but it does not appear to be be possible.

This isn't actually an easy issue to address, as the label's for attribute needs a unique ID, so I am applying the following hack:

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

Attachments (2)

4721.diff (4.3 KB) - added by Nazgul 17 years ago.
4721b.diff (953 bytes) - added by Nazgul 17 years ago.

Download all attachments as: .zip

Change History (7)

@Nazgul
17 years ago

#1 follow-up: @Nazgul
17 years ago

  • Keywords has-patch added
  • Owner changed from anonymous to Nazgul
  • Status changed from new to assigned

Patch adds a unique id to the label based on the given post id.
It uses a random value if no post id is given for backwards compatibility.

#2 in reply to: ↑ 1 @westi
17 years ago

Replying to Nazgul:

Patch adds a unique id to the label based on the given post id.
It uses a random value if no post id is given for backwards compatibility.

Interesting patch.

Could we not use the global $ID if one is not passed and assume we are in "the loop"?

Having to put all that conditional code in the template looks a bit bad as well - but I guess that is something for another ticket ;-)

#3 @Nazgul
17 years ago

  • Milestone changed from 2.3 to 2.4

@Nazgul
17 years ago

#4 @Nazgul
17 years ago

Cleaner patch attached.

#5 @ryan
17 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6698]) Add unique 'for' attribute to labels for post password forms. Props Nazgul. fixes #4721

Note: See TracTickets for help on using tickets.