我有一个bootstrap 4开关,它是从4.3版本引入的自定义复选框输入类型。我想将其集成到自定义选项页中,并在呈现选项页时为其指定默认值。我怎样才能做到这一点,是可能的吗?
这是我的实际代码,我省略了add_action
函数,但插件代码上存在。
function registerSettings()
{
$menu_slug = \'my-plugin-options\';
register_setting( $menu_slug, \'my-option\' );
// I want to use these two functions but I\'m not able to output the form so I\'ve commented them
//add_settings_section( \'\', \'Slider settings\', \'\', $menu_slug );
//add_settings_field( \'\', \'Auto init\', [$this, \'initSettings\'], $menu_slug, \'\' );
}
function renderOptionsMenu()
{
?>
<div class="container-fluid">
<div class="row">
<h1>Bootstrap Shortcodes - Swiper settings</h1>
<form action="options.php" method="POST">
<?php
settings_fields(\'my-plugin-options\');
do_settings_sections(\'my-plugin-options\');
?>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" name="my-option" id="customSwitch1" value="<?php echo esc_attr( get_option(\'my-option\') ); ?>">
<label class="custom-control-label" for="customSwitch1">Auto init</label>
</div>
<?php
submit_button();
?>
</form>
</div>
</div>
<?php
}