php - Wordpress - 使用 functions.php 添加新的管理员配色方案
问题描述
在 Wordpress UI 的“个人资料”页面 (../wp-admin/profile.php) 上,您可以选择八种默认的管理员配色方案作为选项:
我找到了创建这些方案的 CSS 的位置 (../wp-admin/css/colors/) 并使用 CSS 制作了我自己的文件夹以匹配。
首先,我什至无法在个人资料页面上显示我的配色方案,因此我可以对其进行测试。在 ../wp-admin/profile.php 中是这样的:
define('IS_PROFILE_PAGE', true);
/** Load User Editing Page */
require_once( dirname( __FILE__ ) . '/user-edit.php' );
在 ../wp-admin/user-edit.php 中,这是吐出配色方案的部分:
<?php if ( count($_wp_admin_css_colors) > 1 && has_action('admin_color_scheme_picker') ) : ?>
<tr class="user-admin-color-wrap">
<th scope="row"><?php _e('Admin Color Scheme')?></th>
<td><?php
/**
* Fires in the 'Admin Color Scheme' section of the user editing screen.
*
* The section is only enabled if a callback is hooked to the action,
* and if there is more than one defined color scheme for the admin.
*
* @since 3.0.0
* @since 3.8.1 Added `$user_id` parameter.
*
* @param int $user_id The user ID.
*/
do_action( 'admin_color_scheme_picker', $user_id );
?></td>
</tr>
<?php
endif; // $_wp_admin_css_colors
所以我的问题是:
- 如何让它在个人资料页面上显示我的配色方案,以便我可以对其进行测试和编辑?
- Once I'm satisfied with how it looks, how do I put the color scheme in my custom theme's functions.php file so I can import it with every theme install and not have to worry about WordPress erasing it with updates?
- How do I set this color scheme as the default one for users?
Let me know if I need to add further details, thanks for the help guys!
解决方案
Take a look at this article, it may help you: https://www.orionorigin.com/tutorials-and-snippets/define-wordpress-color-scheme-set-default-users/
add_filter( 'get_user_option_admin_color', function( $color_scheme ) {
$color_scheme = 'your_color_sheme_name';
return $color_scheme;
}, 5 );
推荐阅读
- java - Dialog里面的RecyclerView被截断底部
- ios - 在 iOS swift 中将 localizable.string 文件转换为 JSON
- c# - 创建数据服务以在 c# api 和前端(角度)之间进行通信
- java - 无法在 NLGElement 上应用方法 addComplement
- java - Java Streams,跳过元素列表流中每个列表中的第一项
- android - Android 如何用空格替换 TextView 和通知的换行符?
- laravel - 如果选中某个单选按钮,则 laravel-5.8 验证必填字段
- javascript - Rails - 包含带有动态(每个请求)文件名的javascript标记?
- php - 返回最后一个 id laravel
- angular - 传递给指令的值有时未定义