Ticket #4721 (closed defect: fixed)

Opened 1 year ago

Last modified 10 months ago

Password-Protected Post Delivers WAI-Unfriendly Code

Reported by: cmarshall Assigned to: Nazgul
Priority: normal Milestone: 2.5
Component: Template Version: 2.2.2
Severity: minor Keywords: has-patch
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

4721.diff (4.3 kB) - added by Nazgul on 09/07/07 11:41:50.
4721b.diff (0.9 kB) - added by Nazgul on 01/31/08 21:32:42.

Change History

09/07/07 11:41:50 changed by Nazgul

  • attachment 4721.diff added.

(follow-up: ↓ 2 ) 09/07/07 11:44:18 changed by Nazgul

  • keywords set to has-patch.
  • 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.

(in reply to: ↑ 1 ) 09/07/07 11:49:21 changed by westi

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 ;-)

09/19/07 21:17:04 changed by Nazgul

  • milestone changed from 2.3 to 2.4.

01/31/08 21:32:42 changed by Nazgul

  • attachment 4721b.diff added.

01/31/08 21:33:16 changed by Nazgul

Cleaner patch attached.

01/31/08 21:47:35 changed by ryan

  • status changed from assigned to closed.
  • resolution set to fixed.

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