#18753 closed enhancement (fixed)
Add data to stylesheets
Reported by: | kobenland | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Template | Keywords: | has-patch commit 2nd-opinion needs-codex |
Focuses: | Cc: |
Description
In my humble opinion it would be awesome to provide theme developers an easy function to add extra data to registered stylesheets.
This way they could use the 'wp_head' action to cleanly make stylesheets conditional for IE, make them alternate or add RTL support.
Like wp_add_inline_style()
, this function could really contribute to decluttering template files.
Attachments (7)
Change History (24)
#1
@
13 years ago
This exists currently, but you have to dig into $wp_styles and use add_data(), such as add_data( 'ie', 'conditional', 'lte IE 7' ) and add_data( $handle, 'rtl', true );.
It's complex (I didn't provide a code sample as I'd have to look it up beyond what I provided) and I wouldn't mind some wrappers here.
#6
follow-up:
↓ 7
@
12 years ago
@kobenland I like the goal of this idea. I also feel that the script/style system is more complex that it needs to be and it needs to be simplified. I think it would be better to implement a more general data method that could be used for many purposes rather than adding a function that only gets used a few times. A function like the example below would be capable of storing data related to scripts/styles and practically anything else. Also (loosely related) see #22249
// Get or set data via key/value pair. function wp_data ($k = null, $v = null) { static $hash; // php.net/manual/en/language.variables.scope.php isset($hash) or $hash = array(); // only initiates once if ( func_num_args() > 1 ) return $hash[$k] = $v; // set if ( is_scalar($k) ) return $hash[$k]; // get if ( is_null($k) ) return $hash; // get all return $hash = array_merge($hash, (array) $k); // set multi }
#7
in reply to:
↑ 6
@
12 years ago
Replying to ryanve:
@kobenland I like the goal of this idea. I also feel that the script/style system is more complex that it needs to be and it needs to be simplified. I think it would be better to implement a more general data method that could be used for many purposes rather than adding a function that only gets used a few times.
I appreciate your feedback! I merely proposed an abstraction of existing functionality though. Maybe it would be a good idea to open a new ticket with what you came up with?
#10
@
11 years ago
- Keywords 2nd-opinion removed
Going by the function names in that file, and the add_data() method, the function name here should probably be wp_style_add_data
.
Suffice to say, I'm rather surprised that we don't already have the helper function, even more surprised that we used the exact same global access method in Twenty Twelve.
#13
@
11 years ago
- Milestone changed from Awaiting Review to 3.6
Nacin said yesterday it may not be to late for this - I'll move it in 3.6 for commit or punt decision.
I'm available for any alterations or additional patches that are need.
#14
@
11 years ago
- Keywords commit 2nd-opinion added
18753.2.diff is good to go. Per IRC, leaving Twenty Twelve out of this. It's just more code, not really needed. If it were legitimately easier, I'd argue sure. but it's a function wrapping a method, not even a function rename or something.
#15
@
11 years ago
Pointing out that it avoids the did_action() and new WP_Styles stuff because this is a new function. The original functions simply set up WP_Styles on demand, at any time — we needed to dress it up when we wanted to add_doing_it_wrong()
and such. But if this new function gets called too early, it'll simply trigger a fatal error.
Patch