Make WordPress Core

Opened 14 years ago

Closed 13 years ago

#23236 closed feature request (wontfix)

Add functions to format attributes

Reported by: ryanve Owned by:
Priority: normal Milestone:
Component: Formatting Version:
Severity: normal Keywords: needs-patch
Cc: Focuses:

Description

I'd like to see WP add functions for attributes. These would be extremely useful and resuable for theme devs and internally. I've developed very solid generic functions for this in ​phat and would be happy to make WP versions to the effect of:

wp_attrs( $array ) // converts array to attributes string
wp_attrs( $name, $value ) // formats attribute string
wp_attrs( $string ) // reformats attribute string
wp_parse_attrs( $string ) parses attributes into assoc array

Change History (7)

#1 @alexvorn2
14 years ago

  • Component General → Formatting

#2 @alexvorn2
14 years ago

  • Keywords needs-patch added

#4 @ryanve
14 years ago

Here's how I think ​wp_parse_attrs() should be. It uses a primitive loop and is very fail-safe. I don't think regexp is viable due to complications from quotes (single, double, unquoted, JSON). ​DOMDocument is viable but too brittle.

#5 @ryanve
14 years ago

I'll work up a wp_attrs() function similar in effect to ​phat\attrs() but specific to WordPress.

#6 @ryanve
13 years ago

I added ​wphat.php in the ​phat repo called where I'm working on this. I think it'll be better to name the functions wp_attr and wp_attr_parse b/c both can handle 1+ attributes.

How do we want to encode complex (array|object) attributes? ​Currently it checks for the ~10 attributes that take tokens ([class], [media], ​etc.) and implode them with the correct glue. Otherwise it uses json_encode. Should we skip the check and go with the simple approach of using json_encode for any complex value? In either case I'll include a 'complex_attr_value' filter.

I avoided esc_attr b/c it breaks JSON and b/c it double-encodes entities.

Version 0, edited 13 years ago by ryanve (next)

#7 @nacin
13 years ago

  • Milestone Awaiting Review
  • Resolution → wontfix
  • Status new → closed

Closing to due lack of interest. It's possible for these concepts to come back up as the ​metadata API is discussed, of course.

Note: See TracTickets for help on using tickets.