admin管理员组文章数量:1312782
I am surprised with the new colour scheme for 3.8 and although the classic 3.7 theme has gone, I would like to set the new "Light" colour scheme as the default for all users, but at the same time, still allow them to change the theme if they wish, in their user profile.
Has anyone managed to come up with a function to set the default for all users? I've searched but can find nothing as this is so new, 3.8 codex not fully written.
I am surprised with the new colour scheme for 3.8 and although the classic 3.7 theme has gone, I would like to set the new "Light" colour scheme as the default for all users, but at the same time, still allow them to change the theme if they wish, in their user profile.
Has anyone managed to come up with a function to set the default for all users? I've searched but can find nothing as this is so new, 3.8 codex not fully written.
Share Improve this question edited Dec 23, 2020 at 18:56 T.Todua 5,8609 gold badges52 silver badges79 bronze badges asked Dec 16, 2013 at 21:12 SolaceBeforeDawnSolaceBeforeDawn 4855 silver badges21 bronze badges2 Answers
Reset to default 18You can set (in terms of force) a default color within functions.php
like this:
add_filter( 'get_user_option_admin_color', 'update_user_option_admin_color', 5 );
function update_user_option_admin_color( $color_scheme ) {
$color_scheme = 'light';
return $color_scheme;
}
Update: The following color schemes are available per default at WP 3.8
- fresh
- light
- blue
- coffee
- ectoplasm
- midnight
- ocean
- sunrise
Bonus (found on wpmudev): Disable the Admin Color Scheme Options to make sure that users can not switch back to another color:
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
Update 2: As Rarst pointed out the filter above will force a specific color scheme instead of setting a changeable default. The solution to this is to run an action only once (e.g. on user setup/registration) so after that the user can decide and change the color on his own:
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
update_user_meta($user_id, 'admin_color', 'light');
}
Update 3: Okay, so one more try :)
The idea is to add extra user meta data (see custom_admin_color_scheme
) as soon as the user updates the profile; as long as the field is not set to true
we'll change the default admin color scheme to a color scheme of our choice:
// add custom user meta data
add_action('personal_options_update', 'save_custom_admin_color_optios');
function save_custom_admin_color_optios( $user_id ) {
update_user_meta($user_id, 'custom_admin_color_scheme', true);
}
// change default color scheme if not customized
$customized_color_scheme = get_user_option( 'custom_admin_color_scheme', get_current_user_id() );
if ( empty($customized_color_scheme) ) {
update_user_meta(get_current_user_id(), 'admin_color', 'light');
}
Update 4: Finally there is also a very nice plugin on wordpress to handle default admin color schemes easily: Default Admin Color Scheme
the add_filter( 'get_user_option_admin_color', ...)
sets the color, but it doesn't remove the option from my-profile page. So, if you want to enforce (and block) any modification by user:
remove_action("admin_color_scheme_picker", "admin_color_scheme_picker");
If you also need to set that when user registers, then :
add_action('user_register', 'my_func');
function my_func($user_id) {
$args = array(
'ID' => $user_id,
'admin_color' => 'ectoplasm'
);
wp_update_user( $args );
}
本文标签: Set Default Admin Colour For All Users
版权声明:本文标题:Set Default Admin Colour For All Users 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741893992a2403468.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论