Search code examples
phpwordpresscolor-schemewordpress-admin

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


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.


Solution

  • 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.
     */
    function 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.