Using WordPress ‘admin_color_scheme_picker()’ PHP function

The admin_color_scheme_picker() WordPress PHP function displays the default admin color scheme picker. This function is primarily used in user-edit.php.

Usage

Here’s a generic way to use the function. The function takes the user ID as input.

admin_color_scheme_picker( $user_id );

Parameters

  • $user_id (int) – The required user ID.

More Information

See WordPress Developer Resources: admin_color_scheme_picker()

This function is part of the WordPress core and is used to allow admin users to change their dashboard color scheme. It was implemented in WordPress 3.0 and is not currently deprecated. The source code can be found in wp-admin/includes/general-template.php.

Examples

Using admin_color_scheme_picker() to display color scheme picker for a specific user

// Assume we have a user with ID 1
$user_id = 1;

// Use the function to display the color scheme picker for this user
admin_color_scheme_picker($user_id);

In the above example, we’re using the function to display the color scheme picker for the user with an ID of 1.

Using admin_color_scheme_picker() within a custom admin page

// Assume we're inside a custom admin page function
function my_custom_admin_page() {
  // Get the current user ID
  $current_user_id = get_current_user_id();

  // Display the color scheme picker for the current user
  admin_color_scheme_picker($current_user_id);
}

// Hook into the 'admin_menu' action to add our custom page
add_action('admin_menu', 'my_custom_admin_page');

In this example, we’re adding a custom admin page that displays the color scheme picker for the currently logged in user.

Using admin_color_scheme_picker() within a custom profile field

// Add the color scheme picker to the user profile edit screen
function add_custom_profile_field($user) {
  // Display the color scheme picker for the current user
  admin_color_scheme_picker($user->ID);
}

// Hook into the 'show_user_profile' and 'edit_user_profile' actions
add_action('show_user_profile', 'add_custom_profile_field');
add_action('edit_user_profile', 'add_custom_profile_field');

Here, we are adding the color scheme picker to the user profile edit screen.

Using admin_color_scheme_picker() to customize the WordPress login page

// Custom login page function
function my_custom_login() {
  // Get the current user ID
  $current_user_id = get_current_user_id();

  // Display the color scheme picker for the current user
  admin_color_scheme_picker($current_user_id);
}

// Hook into the 'login_form' action to customize the login page
add_action('login_form', 'my_custom_login');

In this example, we’re customizing the WordPress login page to include the color scheme picker for the