Home > Blockchain >  Remove color scheme options from user's profile page in WordPress 6.0
Remove color scheme options from user's profile page in WordPress 6.0

Time:06-04

I've always used this code in a must-use plugin to remove the whole color schemes section:

remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );

Unfortunately, with WordPress 6.0 this does not work anymore. I've found that Core's add_action( 'admin_color_... was recently moved from default-filters.php file to the admin-filters.php file, but I am unsure why and how I'd have to update the above snippet to make it work again.

CodePudding user response:

You can use the other part of the if statement in user-edit.php to remove the ability to change the color scheme.

From user-edit.php

<?php if ( count( $_wp_admin_css_colors ) > 1 && has_action('admin_color_scheme_picker' ) ) : ?>

Although not a direct solution to using the remove action function, you can set the $_wp_admin_css_colors global to an empty array...

add_action( 'admin_init', function () {
    global $_wp_admin_css_colors;
    $_wp_admin_css_colors = [];
} );

CodePudding user response:

For a remove_action() call to be effective, it needs to be called after the action you want to remove has been added, and before the action runs.

WordPress adds the admin_color_scheme_picker action in admin-filters.php and then runs the action in the user-edit.php admin page template.

To remove the admin_color_scheme_picker action right before it is called on the user profile page, you can run the remove_action() call using the admin_head-profile.php hook:

add_action( 'admin_head-profile.php', 'wpse_72463738_remove_admin_color_scheme_picker' );

/**
 * Remove the color picker from the user profile admin page.
 */
wpse_72463738_remove_admin_color_scheme_picker() {
    remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
}

Note that the admin_head-{$hook_suffix} hook fires in the head section for a specific admin page. In the example above replacing $hook_suffix with profile.php in the hook name makes it run on the user admin profile page.

  • Related