Make WordPress Core

Opened 18 years ago

Closed 17 years ago

#2883 closed defect (bug) (wontfix)

allowed_tags() more semantic

Reported by: davemad-davenet's profile dave@… Owned by: rob1n's profile rob1n
Milestone: Priority: low
Severity: normal Version: 2.0.3
Component: Template Keywords: has-patch dev-feedback 2nd-opinion
Focuses: Cc:

Description

  • File: template-functions-general.php
  • Function: allowed_tags()

The function allowed_tags() gereates a long line of tags which are allowed in comments.

function allowed_tags() {
	global $allowedtags;
	$allowed = '';
	foreach ( $allowedtags as $tag => $attributes ) {
		$allowed .= '<'.$tag;
		if ( 0 < count($attributes) ) {
			foreach ( $attributes as $attribute => $limits ) {
				$allowed .= ' '.$attribute.'=""';
			}
		}
		$allowed .= '> ';
	}
	return htmlentities($allowed);
}

This generates for example: <em> <i> <b> <strong> ...

But imo, this should be an unordered list, so i modified the function:

function allowed_tags() {
	global $allowedtags;
	$allowed = '';
	$pre = '<ul class="allowedtags">';
	$end = '</ul>';
	foreach ( $allowedtags as $tag => $attributes ) {
		$allowed .= '<li>&lt;'.$tag;
		if ( 0 < count($attributes) ) {
			foreach ( $attributes as $attribute => $limits ) {
				$allowed .= ' '.$attribute.'=""';
			}
		}
		$allowed .= '&gt;</li>';
	}
	return $pre.$allowed.$end;
}

Now, it generates this:

<ul class="allowedtags">

<li>&lt;em&gt;</li>

<li>&lt;i&gt;</li>

<li>&lt;strong&gt;</li>

<li>&lt;b&gt;</li>

</ul>

To make the whole thing html valid, change comments.php the allowed_tags part to:

	<p><strong>XHTML:</strong> You can use these tags:</p>
	<?php echo allowed_tags(); ?>

Greetings

Attachments (1)

general-template.php.diff (955 bytes) - added by leftjustified 18 years ago.
Updated: because backwards compat. is a Good Thing :)

Download all attachments as: .zip

Change History (9)

#1 @leftjustified
18 years ago

  • Component changed from Administration to Template
  • Keywords bg|has-patch added
  • Owner changed from anonymous to leftjustified

#2 @ryan
18 years ago

I'm concerned about breaking themes that process the return value. Are there any such themes out there? We could always add an optional $format arg that allows theme authors to request a list.

#3 @ptvguy
18 years ago

Just for comparison, I've put the suggested mod on my test1 blog with the "Flashy" theme in place:

http://test1.ptvguy.com/?p=1#comments

Here's what the same theme looks like normally:

http://blog.leenarts.net/2006/06/30/naked-presentations/#comments

Review the allowed comment tags between the website input box and the comment input box.

#4 @ptvguy
18 years ago

BTW, I didnm't do the extra comments.php change.

@leftjustified
18 years ago

Updated: because backwards compat. is a Good Thing :)

#5 @leftjustified
18 years ago

  • Keywords bg|needs-testing added
  • Status changed from new to assigned

Patch modified to address Ryan's concerns.

#6 @rob1n
17 years ago

  • Keywords has-patch dev-feedback 2nd-opinion added; bg|has-patch bg|needs-testing removed
  • Milestone set to 2.3
  • Owner changed from leftjustified to rob1n
  • Status changed from assigned to new

I think it's fine the way we do it, IMO. I think we include it in <code />, which is good enough. Devs?

#7 @rob1n
17 years ago

  • Status changed from new to assigned

#8 @rob1n
17 years ago

  • Milestone 2.3 deleted
  • Resolution set to wontfix
  • Status changed from assigned to closed

Not worth it, really. If you really wanted to, you could write your own function. Or loop through $allowedtags yourself.

Note: See TracTickets for help on using tickets.