Current File : /home/n742ef5/royalanteam.com/wp-content/themes/myhome/src/version-selector.php
<?php

add_action('after_switch_theme', static function () {
    $theme = wp_get_theme();

    if ($theme->get('Name') === 'MyHome' && is_admin()) {
        if (!isset($_GET['page']) || $_GET['page'] !== 'myhome-setup') {
            wp_safe_redirect(admin_url('admin.php?page=myhome-setup'));
            exit;
        }
    }
});

add_action('admin_menu', static function () {
    add_menu_page('MyHome', 'MyHome Setup', 'manage_options', 'myhome-setup', static function () {
        ?>
        <div class="wrap" style="max-width:600px;">
            <h1><?php esc_html_e('MyHome Setup', 'myhome'); ?></h1>
            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php?action=myhome_setup')); ?>">
                <h2><?php esc_html_e('Choose Your Page Builder', 'myhome'); ?></h2>
                <p><?php esc_html_e('Please select which page builder you would like to use with MyHome theme.', 'myhome'); ?></p>

                <h3><?php esc_html_e('Elementor', 'myhome'); ?> (Recommended)</h3>
                <p><?php esc_html_e('Elementor is a powerful, user-friendly page builder with a drag-and-drop interface. It offers extensive customization and is regularly updated with new features.', 'myhome'); ?></p>
                <label>
                    <input
                            type="radio"
                            name="page_builder"
                            value="elementor"
                            checked
                    >
                    <?php esc_html_e('Use Elementor', 'myhome'); ?>
                </label>

                <h3><?php esc_html_e('WPBakery Page Builder', 'myhome'); ?></h3>
                <p><?php esc_html_e('WPBakery Page Builder is reliable and compatible with many themes. While it’s a solid choice, Elementor receives more frequent updates and new features.', 'myhome'); ?></p>
                <label>
                    <input
                            type="radio"
                            name="page_builder"
                            value="wpbakery"
                    >
                    <?php esc_html_e('Use WPBakery Page Builder', 'myhome'); ?>
                </label>

                <h3></h3>

                <p>
                    <strong><?php esc_html_e('Please note that Elementor and WPBakery demos are not interchangeable. Elements from an Elementor demo cannot be used in a WPBakery demo, and vice versa. Choose the builder that best suits your needs.', 'myhome'); ?></strong>
                </p>

                <?php submit_button(__('Save Changes', 'myhome')); ?>
            </form>
        </div>
        <?php
    }, '', 2);
}, 999);

add_action('admin_post_myhome_setup', static function () {
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.', 'myhome'));
    }

    if (!isset($_POST['page_builder'])) {
        wp_die(__('Invalid request.', 'myhome'));
    }

    update_option('myhome_page_builder', sanitize_text_field($_POST['page_builder']));

    wp_redirect(admin_url('index.php'));
    exit;
});