#10024 closed defect (bug) (invalid)
Duplicate CSS includes for wp_register_style() dependencies that are loaded by wp_admin_css_color()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | major | Version: | 2.7.1 |
Component: | General | Keywords: | wp_register_style, wp_enqueue_style, wp_admin_css_color, css |
Focuses: | Cc: |
Description
I think there is a bug in the logic that handles dependencies for styles. Allow me to demonstrate.
I am registering a new style for my admin plugin and I want it to load after certain css files, using the dependency method that wp_register_style() offers. I want my css to load after wp-admin.css and colors-classic.css.
wp_register_style('test_css', "http://test.com/wp-content/my-plugin/css/my-plugin-admin.css", array('wp-admin', 'colors-classic')); wp_enqueue_style('test_css');
This works just fine and my css indeed loads AFTER the 2 dependencies, except there it is followed by a duplicate
<link rel='stylesheet' href='http://test.com/wp-admin/css/colors-classic.css?ver=20081210' type='text/css' media='all' />
I traced it down to line 41 in wp-admin/admin.php:
wp_admin_css_color('classic', __('Blue'), admin_url("css/colors-classic.css"), array('#073447', '#21759B', '#EAF3FA', '#BBD8E7'));
Apparently wp_admin_css_color() doesn't play well with dependency handling and inserts an extra colors-classic.css anyway, even though it's already been inserted, thus creating a duplicate as well as overriding my styles all over again.
This is what the final output looks like right now:
<link rel='stylesheet' href='http://test.com/wp-admin/wp-admin.css?ver=20081210' type='text/css' media='all' /> <link rel='stylesheet' href='http://test.com/wp-admin/css/colors-classic.css?ver=20081210' type='text/css' media='all' /> <link rel='stylesheet' href='http://test.com/wp-content/my-plugin/css/my-plugin-admin.css?ver=2.7.1' type='text/css' media='all' /> <link rel='stylesheet' href='http://test.com/wp-admin/css/global.css?ver=20081210' type='text/css' media='all' /> <link rel='stylesheet' href='http://test.com/wp-admin/css/colors-classic.css?ver=20081210' type='text/css' media='all' />
Change History (5)
#1
@
16 years ago
- Summary changed from Duplicate css file includes for some wp_register_style() dependencies to Duplicate CSS includes for wp_register_style() dependencies that are loaded by wp_admin_css_color()
This is because you're using directly
colors-classic.css
as dependency. Color sylesheets are selectable by the user and are queued with handle 'colors'. There's a function to output the right one depending on the user settings. Try using 'colors' as a dependency.