1

I'm using WordPress 4.6.1, is it possible for us to hook into function register_admin_color_schemes() located in wp-includes/general-template.php? This way we can send or concatenate or bind the following code to that function:

wp_admin_css_color( 'ffa', _x( 'My Custom Color Combo', 'admin color scheme' ),
        admin_url( "/my-plugin=directory/css/colors/my-custom-color-combo/colors$suffix.css" ),
        array( '#ffffff', '#ffcd00', '#c7a589', '#9ea476' ),
        array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
    );

If possible, how can we do this dynamically?

FYI, I see that I can manually modify the general-template.php file, but I would have to do that every time I update WordPress.

1

No, you can't hook into that function since there is no do_action or apply_filters in it, the function itself hooks to admin_init. So if your goal is to add new color schemes you have to hook your code the same way, so using your example, the required code would be something like this:

// Define the function that registers the color schemes.
function wpse244982_register_admin_color_schemes() {
    wp_admin_css_color( 'ffa', _x( 'My Custom Color Combo', 'admin color scheme' ),
        admin_url( "/my-plugin=directory/css/colors/my-custom-color-combo/colors$suffix.css" ),
        array( '#ffffff', '#ffcd00', '#c7a589', '#9ea476' ),
        array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
    );

    // Maybe more colors schemes here
    // wp_admin_css_color(...);
    // wp_admin_css_color(...);
}

// Hook it to admin_init as WordPress does
add_action( 'admin_init', 'wpse244982_register_admin_color_schemes');
1
  • 1
    I like this approach because I can easily see how we can (bonus) register multiple wp_admin_css_color() schemes into a class structure. Thanks – klewis Nov 3 '16 at 19:06
1

As far I understood your question you need a way where you can pass parameter and add multiple color schemes, right ? Well in that case you can call the function multiple times or you can write your own function like below-

function the_dramatist_admin_css_color( $args ) {
    wp_admin_css_color( $args['key'], $args['name'], admin_url( $args['url'] ), $args['color'], $args['last_el'] );
}

And call it passing your parameter like below-

$args = array(
    'key'       => 'ffa',
    'name'      => _x( 'My Custom Color Combo', 'admin color scheme' ),
    'url'       => '/my-plugin=directory/css/colors/my-custom-color-combo/colors.css',
    'color'     => array( '#ffffff', '#ffcd00', '#c7a589', '#9ea476' ),
    'last_el'   => array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )

);

// Then call the function
the_dramatist_admin_css_color($args);

Hope that helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.