<?php 

add_action( 'admin_menu', 'plumber_works_menu' );
add_action( 'admin_init', 'plumber_works_register_settings' );

function plumber_works_menu() {
    add_menu_page(
        'Theme Options',
        'Theme Option',
        'manage_options',
        'plumber_works_theme_option',
        'plumber_works_preloader_page_callback',
        'dashicons-screenoptions',
        30
    );
}

function plumber_works_register_settings() {
    register_setting( 'plumber_works_preloader_settings', 'plumber_works_preloader_toggle' );
}

function plumber_works_preloader_page_callback() {
    ?>
    <div class="menu-box">
        <h2><?php echo esc_html('Preloader Setting','plumber-works'); ?></h2>
        <form method="post" action="options.php">
            <?php settings_fields( 'plumber_works_preloader_settings' ); ?>
            <?php $toggle = get_option( 'plumber_works_preloader_toggle', 'off' ); ?>
            <label for="plumber_works_preloader_toggle">
                <input type="checkbox" id="plumber_works_preloader_toggle" name="plumber_works_preloader_toggle" <?php checked( $toggle, 'on' ); ?> />
                <?php echo esc_html('Enable Preloader','plumber-works'); ?>
            </label>
            <?php submit_button(); ?>
        </form>
    </div>
    


    <?php
}
