#20836 closed defect (bug) (fixed)
wp_add_inline_style does not work with concatenated stylesheets
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.6 | Priority: | normal |
Severity: | normal | Version: | 3.3.2 |
Component: | General | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
When using wp_add_inline_style
with concatenated stylesheets (those loaded through load-styles.php
- such as 'wp-admin'), additional styles added with wp_add_inline_style
are not printed to the document - but instead the word 'array' is printed.
For non-concatenated scripts wp_add_inline_style
works as expected. Also when SCRIPT_DEBUG is set to true it works as expected (scripts are no-longer concatenated).
Attachments (1)
Change History (11)
#6
@
10 years ago
- Keywords reporter-feedback added; has-patch removed
Given:
- load-styles.php doesn't require() any plugins or themes; it only loads wp-includes/script-loader.php
- The script-loader.php file doesn't have any wp_add_inline_style() calls
From 1. we can deduce:
- Plugins and themes can't use concatenated stylesheets.
Conclusion:
Unless you modify the script-loader.php file and add a wp_add_inline_style() call to it - hacking a core file is bad, mkay - this is a non-issue.
Did I miss something?
#7
@
10 years ago
Plug-ins / Themes can use wp_add_inline_style()
to add in-line styles to core (or any other) styles. It should be 'attached' to (albeit not compressed, but printed after) the style-sheet you're adding it to.
Currently what is printed is not the attached styles, but instead the word "Array" is printed.
As a contrived example
wp_add_inline_style('admin-bar','#wpadminbar {background: blue;}');
Works when SCRIPT_DEBUG
is true, but not if its false.
#8
@
10 years ago
- Keywords has-patch commit added; reporter-feedback removed
- Milestone changed from Awaiting Review to 3.6
It should be 'attached' to (albeit not compressed, but printed after) the style-sheet you're adding it to.
Oh, so it wouldn't be concatenated along with the standalone files by load-styles.php, as I had assumed. Thanks, this makes sense now.
Similar discussion for JS concatenation: http://core.trac.wordpress.org/ticket/16494#comment:29 onwards
The additional scripts are stored in an array in
$styles->registered[$handle]->extra
. Usually this is imploded before printing to the document however, in the case of concatenated scripts there are not.See
do_item
method of theWP_Styles
method. In particular line 48-57: https://github.com/WordPress/WordPress/blob/3.3.2/wp-includes/class.wp-styles.php#L48$this->get_data( $handle, 'after' );
is appended to the code to be printed. However$this->get_data( $handle, 'after' );
either returns an array (if there is additional code) or false otherwise. This needs to be imploded before being appended to the code.