Opened 12 years ago
Closed 11 years ago
#23236 closed feature request (wontfix)
Add functions to format attributes
Reported by: | ryanve | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Formatting | Keywords: | needs-patch |
Focuses: | Cc: |
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)
#4
@
12 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
@
12 years ago
I'll work up a wp_attrs()
function similar in effect to phat\attrs() but specific to WordPress.
#6
@
11 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.
#7
@
11 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to 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.
Related: #23237