Make WordPress Core

Opened 10 years ago

Last modified 5 years ago

#28324 new feature request

Add primary and secondary color definitions to admin color schemes and add function to retrieve color scheme info

Reported by: bamadesigner's profile bamadesigner Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8
Component: Administration Keywords: reporter-feedback
Focuses: ui, administration Cc:

Description

I'd like to be able to implement a user's selected admin color scheme into my plugin admin UI design but, at this point in time, using wp_admin_css_color() to register a color scheme only asks for an array of colors and then depends on a stylesheet to use said colors so there's no way for me to, at the very least, detect a primary and secondary color to use in my design.

From what I can tell, most color schemes have what they consider to be the primary and secondary color, and they use those colors for primary buttons and admin menu links and such, but there's no way for someone else to detect those color values.

It would also be nice if there was a function to retrieve the color scheme info. Perhaps something like this:

function get_user_admin_color() {
   global $_wp_admin_css_colors;

   if ( ( $user_admin_color = get_user_option( 'admin_color' ) )
      && isset( $_wp_admin_css_colors[ $user_admin_color ] ) ) {

      return $_wp_admin_css_colors[ $user_admin_color ];

   }

   return false;

}

But the big request is changes to the wp_admin_css_color() function so, at the very least, a primary and secondary color can be defined and stored in $_wp_admin_css_colors. Perhaps something like this?

function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array(), $primary_color = NULL, $secondary_color = NULL ) {
   global $_wp_admin_css_colors;

   // If a primary color is not defined, use first color from $colors array
   if ( ! isset( $primary_color ) && count( $colors ) >= 1 )
      $primary_color = $colors[0];

   // If a secondary color is not defined, use second color from $colors array
   if ( ! isset( $secondary_color ) && count( $colors ) >= 2 )
      $secondary_color = $colors[1];

   if ( ! isset( $_wp_admin_css_colors ) )
      $_wp_admin_css_colors = array();

   $_wp_admin_css_colors[$key] = (object) array(
      'name' => $name,
      'url' => $url,
      'primary_color' => $primary_color,
      'secondary_color => $secondary_color,
      'colors' => $colors,
      'icon_colors' => $icons,
      );
}

Change History (6)

#1 @johnbillion
10 years ago

Closely related: #26691

#2 @SergeyBiryukov
10 years ago

There are helper classes for plugins to leverage the active color scheme:
tags/3.9.1/src/wp-admin/css/common.css#L662.

#4 @nacin
10 years ago

#28953 was marked as a duplicate.

#5 @nacin
10 years ago

  • Version changed from trunk to 3.8

Indeed, there are helper CSS classes. See also my reply on #28953 (which I'm closing as a duplicate):

What would the use case be for this? These registered colors are only useful for showing a palette and for the icon colors. They shouldn't be indicative of specific primary/secondary colors, so I'm not sure having a function for them would be a great idea.

#6 @chriscct7
9 years ago

  • Keywords reporter-feedback added
Note: See TracTickets for help on using tickets.