kirki-framework / control-color-palette
Kirki自定义框架的色彩调色板控件
该软件包的官方仓库似乎已删除,因此该软件包已被冻结。
v1.0.3
2022-01-18 07:50 UTC
Requires
- php: >=7.0
- kirki-framework/control-base: *
README
为Kirki自定义框架提供的control-color-palette
软件包。
目录
安装
首先,使用Composer安装软件包
composer require kirki-framework/control-color-palette
然后确保您已包含自动加载器
require_once "your/path/to/vendor/autoload.php";
使用
可以使用Kirki API或WordPress自定义API来使用此控件。
使用Kirki API
new \Kirki\Field\Color_Palette( [ 'settings' => 'your_control_setting_id', 'label' => esc_html__( 'Your Control Label', 'your-text-domain' ), 'description' => esc_html__( 'Your control description.', 'your-text-domain' ), 'section' => 'your_section_id', 'default' => 5, 'choices' => [ 'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ], 'shape' => 'round', // Optional, default is 'square'. 'size' => 20, // Optional, default is 28. ], ] );
使用WordPress自定义API
/** * Register customizer settings and controls. * * @param \WP_Customize_Manager $wp_customize The Customizer object. */ function your_customize_register_function( $wp_customize ) { // Add setting. $wp_customize->add_setting( 'your_control_setting_id', [ 'type' => 'theme_mod', // Or 'option'. 'capability' => 'edit_theme_options', 'default' => 5, 'transport' => 'postMessage', // Or 'refresh'. 'sanitize' => 'intval', // Or 'absint' or other int sanitization. ] ); // Add control. $wp_customize->add_control( new \Kirki\Control\Color_Palette( $wp_customize, 'your_control_setting_id', [ 'label' => esc_html__( 'Your Control Label', 'your-text-domain' ), 'description' => esc_html__( 'Your control description.', 'your-text-domain' ), 'section' => 'your_section_id', 'choices' => [ 'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ], 'shape' => 'round', // Optional, default is 'square'. 'size' => 20, // Optional, default is 28. ], ] ) ); // Add more settings... // Add more controls... } add_action( 'customize_register', 'your_customize_register_function' );