Opened 10 years ago
Closed 10 years ago
#30488 closed defect (bug) (fixed)
Switching between Admin Color Schemes does not immediately update the body class.
Reported by: | valendesigns | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | normal | Version: | 3.8 |
Component: | Administration | Keywords: | has-patch dev-feedback |
Focuses: | ui, javascript, administration | Cc: |
Description
Recently I was working on a plugin that required different menu icons based on the color scheme currently activated. However, I found that when you switch between schemes in your profile the body
class is not updated until you manually refresh the page. Which means any styles you've added via admin_head
to change your icon globally are not immediately reflected in the UI.
I'm submitting this ticket with a simple patch. The changes I've made are to pass the value of $color_scheme
to the wp_send_json_success()
function via its $data
parameter, and a bit of JavaScript that removes the old color scheme and adds the newly selected one to the body
class.
Attachments (3)
Change History (16)
#2
@
10 years ago
#3
@
10 years ago
- Keywords dev-feedback added
Thank you for testing the patch @florianziegler. Hopefully this can make it into 4.1.0, which seems like a reasonable request IMO.
#4
follow-up:
↓ 5
@
10 years ago
- Milestone changed from Awaiting Review to Future Release
I'd be interested in knowing what changes you make to your icon based on the colour scheme.
#5
in reply to:
↑ 4
@
10 years ago
Replying to johnbillion:
I'd be interested in knowing what changes you make to your icon based on the colour scheme.
Originally I was going to simply replace the darker version with a lighter version for certain schemes by hiding the image and adding the alternative to the background of the container. However, due to the body class limitation I went a different route. In the end I created an svg
and turned it into a font. Which was the best solution, and much more seamless for UX. Still, having the class properly switch makes sense; even if I don't need it anymore. Not everyone has the option to turn their icon into a font.
This ticket was mentioned in Slack in #core by drew. View the logs.
10 years ago
#10
follow-up:
↓ 11
@
10 years ago
To get rid of the RegExp, what about returning the old and the new CSS class in wp_send_json_success() to make a simple .replace() call?
#11
in reply to:
↑ 10
@
10 years ago
Replying to ocean90:
To get rid of the RegExp, what about returning the old and the new CSS class in wp_send_json_success() to make a simple .replace() call?
Sounds good. I'll update the patch.
#12
@
10 years ago
Patch 30488.2.diff lets wp_ajax_save_user_color_scheme
take care of the logic, and the JavaScript simply removes and adds the classes that get passed in from the wp_send_json_success
array. Thank you @ocean90 for the suggestion, it's much better this way.
Tested. Works.
Would be nice to get this committed asap, as we also need this for #28599.