wp_admin_css_color()
云策文档标注
概述
wp_admin_css_color() 函数用于在 WordPress 后台注册一个新的管理员颜色方案,允许插件自定义界面配色。它通过指定键、名称、CSS 文件 URL 和颜色数组来定义方案。
关键要点
- 函数 wp_admin_css_color() 注册管理员颜色方案,需提供唯一键、名称、CSS 文件 URL 和可选颜色数组。
- 参数包括:$key(唯一键)、$name(方案名称)、$url(CSS 文件 URL)、$colors(CSS 颜色定义数组,默认空数组)、$icons(SVG 图标颜色数组,默认空数组)。
- 函数内部将方案存储在全局变量 $_wp_admin_css_colors 中,用于后台颜色选择器。
- 相关函数 register_admin_color_schemes() 用于注册默认颜色方案。
- 自 WordPress 2.5.0 版本引入。
代码示例
wp_admin_css_color(
'classic',
__( 'Classic', 'textdomain' ),
admin_url( "css/colors/blue/colors.css" ),
array('#07273E', '#14568A', '#D54E21', '#2683AE'),
array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
);
原文内容
Registers an admin color scheme css file.
Description
Allows a plugin to register a new admin color scheme. For example:
wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
'#07273E', '#14568A', '#D54E21', '#2683AE'
) );
Parameters
$keystringrequired-
The unique key for this theme.
$namestringrequired-
The name of the theme.
$urlstringrequired-
The URL of the CSS file containing the color scheme.
$colorsarrayoptional-
An array of CSS color definition strings which are used to give the user a feel for the theme.
Default:
array() $iconsarrayoptional-
CSS color definitions used to color any SVG icons.
basestringSVG icon base color.focusstringSVG icon color on focus.currentstringSVG icon color of current admin menu link.
Default:
array()
Source
function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
global $_wp_admin_css_colors;
if ( ! isset( $_wp_admin_css_colors ) ) {
$_wp_admin_css_colors = array();
}
$_wp_admin_css_colors[ $key ] = (object) array(
'name' => $name,
'url' => $url,
'colors' => $colors,
'icon_colors' => $icons,
);
}
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
Skip to note 2 content
Codex
Example
To register the Classic admin theme using default blue scheme use:
wp_admin_css_color( 'classic', __( 'Classic', 'textdomain' ), admin_url( "css/colors/blue/colors.css" ), array('#07273E', '#14568A', '#D54E21', '#2683AE'), array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' ) );