# double-opt-in/2.12/ui/UIDatabase.class.php

Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification, version 2.12. 129 lines.

- Page: https://pluginprobe.com/plugins/double-opt-in/2.12/code/ui/UIDatabase.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/2.12/raw/ui/UIDatabase.class.php
- Modified: 2023-01-21T14:56:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/double-opt-in/2.12/code/ui/UIDatabase.class.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {
    if (!defined('ABSPATH')) {
        exit;
    }

    /**
     * Class UIDatabase
     * @package forge12\contactform7\CF7DoubleOptIn
     */
    class UIDatabase extends UIPageForm
    {
        public function __construct($domain)
        {
            parent::__construct($domain, 'database', 'Database', 50);
            $this->hideSubmitButton(true);
        }

        /**
         * Save on form submit
         */
        private function maybeCleanDatabase()
        {
            // Check if the form is posted and the nonce is valid
            if ((isset($_POST['doi-clean-submit']) || isset($_POST['doi-clean-confirmed-submit']) || isset($_POST['doi-clean-unconfirmed-submit']))) {
                $CleanUp = new CleanUp();
                if (isset($_POST['doi-clean-submit']) || isset($_POST['doi-clean-confirmed-submit'])) {
                    $CleanUp->removeConfirmedOptins();
                }
                if (isset($_POST['doi-clean-submit']) || isset($_POST['doi-clean-unconfirmed-submit'])) {
                    $CleanUp->removeUnconfirmedOptins();
                }

                Messages::getInstance()->add(__('Database cleaned.', 'double-opt-in'), 'success');
            }
        }

        /**
         * Reset the database deleting all entries.
         */
        private function maybeResetDatabase()
        {
            // Check if the form is posted and the nonce is valid
            if (isset($_POST['doi-reset-submit'])) {
                $CleanUp = new CleanUp();
                $CleanUp->reset();

                Messages::getInstance()->add(__('Database reset finished.', 'double-opt-in'), 'success');
            }
        }

        /**
         * Render the license subpage content
         */
        protected function theContent($slug, $page, $settings)
        {
            ?>
            <h2>
                <?php _e('Database', 'double-opt-in'); ?>
            </h2>
            <?php
            wp_nonce_field('doi_settings_action', 'doi_settings_nonce');
            ?>

            <div class="option">
                <div class="label">
                    <label for="delete"><?php _e('Clean Database', 'double-opt-in'); ?></label>
                </div>
                <div class="input">
                    <input type="submit" name="doi-clean-submit" class="button"
                           value="<?php _e('Clean All', 'double-opt-in'); ?>"/>
                    <input type="submit" name="doi-clean-confirmed-submit" class="button"
                           value="<?php _e('Clean Confirmed', 'double-opt-in'); ?>"/>
                    <input type="submit" name="doi-clean-unconfirmed-submit" class="button"
                           value="<?php _e('Clean Unconfirmed', 'double-opt-in'); ?>"/>
                    <p>
                        <?php _e('Make sure you backup your database before clicking one of these buttons.', 'double-opt-in'); ?>
                    </p>
                </div>
            </div>
            <div class="option">
                <div class="label">
                    <label for="delete"><?php _e('Reset Database', 'double-opt-in'); ?></label>
                </div>
                <div class="input">
                    <input type="submit" name="doi-reset-submit" class="button button-delete"
                           value="<?php _e('Reset', 'double-opt-in'); ?>"/>
                    <p>
                        <?php _e('Make sure you backup your database before clicking one of these buttons. If you click this button, all Opt-Ins will be deleted.', 'double-opt-in'); ?>
                    </p>
                </div>
            </div>
            <?php
        }

        protected function theSidebar($slug, $page)
        {
            if ($page != 'settings') {
                return;
            }
            ?>
            <div class="box">
                <h2>
                    <?php _e('Hint:', 'double-opt-in'); ?>
                </h2>
                <p>
                    <?php _e("In the table on the left side, you'll find an list containing all Opt-Ins and the required information from your customers. Click on the hash to open aditional informations about the form and the user data. All unconfirmed opt-ins will be deleted after 7 days.", 'double-opt-in'); ?>
                </p>
            </div>
            <?php
        }

        public function getSettings($settings)
        {
            return $settings;
        }

        protected function onSave($settings)
        {
            // Check if the user wants to clean the database manually
            $this->maybeCleanDatabase();
            // Check if the user wants to reset the database manually
            $this->maybeResetDatabase();

            return $settings;
        }
    }
}
```
