helgatheviking / kia-customizer-toggle-control

WordPress 自定义控制器的切换控制。

1.0.1 2022-06-02 20:53 UTC

This package is auto-updated.

Last update: 2024-09-30 01:41:05 UTC


README

WordPress 自定义控制器的切换控制

Animation. Three toggle inputs that are switched on and off.

安装

将以下内容添加到您的 composer.json 文件中,并运行 composer update

"repositories": [
{
    "type": "git",
    "url": "https://github.com/helgatheviking/kia-customizer-toggle-control.git"
}
],
"require": {
"helgatheviking/kia-customizer-toggle-control": "dev-main"
},
"extra": {
"installer-paths": {
    "includes/{$name}": [
        "helgatheviking/kia-customizer-toggle-control"
    ]
}

添加控制

/**
 * Add range slider to Customizer.
 *
 * @param  obj     $wp_customize
 */
function kia_customizer( $wp_customize ) {
    // Include the class
    require_once dirname( __FILE__ ) . '/includes/kia-customizer-toggle-control/class-kia-customizer-toggle-control.php';

    // Register the control types that we're using as JavaScript controls.
	$wp_customize->register_control_type( 'KIA_Customizer_Toggle_Control' );

    $wp_customize->add_setting(
        'my_setting',
        array(
            'default'              => false,
            'type'                 => 'option',
            'capability'           => 'edit_themes',
            'transport'            => 'postMessage',
            'sanitize_callback'    => array( 'KIA_Customizer_Radio_Image_Control', 'sanitize' ),
            'sanitize_js_callback' => array( 'KIA_Customizer_Radio_Image_Control', 'sanitize' ),
        )
    );

    $wp_customize->add_control(
        new KIA_Customizer_Range_Control(
            $wp_customize,
            'my_control',
            array(
                'type'        => 'kia-range',
                'label'       => __( 'Turn on setting', 'your-textomain' ),
                'description' => __( 'An example toggle', 'your-textdomain' ),
                'section'  => 'my_section',
	            'settings' => 'my_setting',
            )
        )
    );

}
add_action( 'customize_register', 'kia_customizer' );

致谢

非常感谢 Rich Tabor 的 登录设计师 和 Per Soderlind 的 自定义切换控制