WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#10024 closed defect (bug) (invalid)

Duplicate CSS includes for wp_register_style() dependencies that are loaded by wp_admin_css_color()

Reported by: archon810 Owned by: azaozz
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)

comment:1 @archon8106 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()

comment:2 @Denis-de-Bernardy6 years ago

  • Milestone set to 2.8
  • Severity changed from normal to major

comment:3 @Denis-de-Bernardy6 years ago

  • Owner set to azaozz
  • Status changed from new to assigned

comment:4 @azaozz6 years ago

  • Milestone 2.8 deleted
  • Resolution set to invalid
  • Status changed from assigned to closed

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.

comment:5 @archon8106 years ago

OK, thank you, that worked.

Is this functionality documented anywhere? It's quite easy to confuse 'colors' with 'colors-classic' because the former is also a valid handle. Perhaps a warning somewhere in the documentation would suffice.

Note: See TracTickets for help on using tickets.