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

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

- Page: https://pluginprobe.com/plugins/double-opt-in/2.12/code/ui/UIDashboard.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/2.12/raw/ui/UIDashboard.class.php
- Modified: 2022-12-16T11:04:54+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/UIDashboard.class.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {
    if (!defined('ABSPATH')) {
        exit;
    }

    /**
     * Class UIDashboard
     *
     * @package forge12\contactform7\CF7DoubleOptIn
     */
    class UIDashboard extends UIPage
    {
        public function __construct($domain)
        {
            parent::__construct($domain, 'f12-cf7-doubleoptin', 'Dashboard', 0);

        }

        public function getSettings($settings)
        {
            return $settings;
        }

        protected function onSave($settings)
        {
            return $settings;
        }

        /**
         * Maybe delete an given entry.
         */
        private function maybeDelete()
        {
            if (isset($_GET['option']) && $_GET['option'] == 'delete' && isset($_GET['hash']) && !empty($_GET['hash']) && current_user_can('manage_options')) {
                $hash = esc_attr($_GET['hash']);

                $CleanUp = new CleanUp();

                if ($CleanUp->deleteByHash($hash)) {
                    wp_redirect('admin.php?page=f12-cf7-doubleoptin&status=deleted');
                    wp_die();
                } else {
                    wp_redirect('admin.php?page=f12-cf7-doubleoptin&status=error');
                    wp_die();
                }

            } else if (isset($_GET['status'])) {

                $status = $_GET['status'];
                if ($status == 'deleted') {
                    Messages::getInstance()->add(__('The given DOI has been removed.', 'double-opt-in'), 'success');
                }
                if ($status == 'error') {
                    Messages::getInstance()->add(__('Couldn\'t delete the DOI, please try again later.', 'double-opt-in'), 'error');
                }
            }
        }

        public function theContent($slug, $page, $settings)
        {
            // Check if there is a call to delete an specific entry
            $this->maybeDelete();

            // Render the optins
            $this->renderLatestOptIns($slug, $page);
        }

        private function renderLatestOptins($slug, $page)
        {
            $atts = array(
                'perPage' => 10,
                'page' => 1,
                'order' => 'DESC',
                'keyword' => ''
            );

            if(isset($_GET['perPage'])){
                $atts['perPage'] = (int)$_GET['perPage'];
            }

            if (isset($_GET['pageNum'])) {
                $atts['page'] = (int)$_GET['pageNum'];
            }

            if(isset($_GET['keyword'])){
                $atts['keyword'] = sanitize_text_field($_GET['keyword']);
            }

            if(isset($_GET['cf_form_id'])){
                $atts['cf_form_id'] = (int)$_GET['cf_form_id'];
            }

            $numberOfPages = 0;
            $listOfOptIns = OptIn::get_list($atts, $numberOfPages);

            /*
             * Render the Template
             */
            ?>
            <h1><?php _e('Latest Opt-ins', 'double-opt-in'); ?></h1>
            <?php

            CF7DoubleOptIn::getInstance()->renderTemplate('list-optins', array(
                'domain' => $this->domain,
                'listOfOptIns' => $listOfOptIns,
                'numberOfPages' => $numberOfPages,
                'currentPage' => $atts['page'],
                'slug' => $slug
            ));
        }

        public function theSidebar($slug, $page)
        {
            ?>
            <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>
            <div class="box">
                <h2>
                    <?php _e('Hooks:', 'double-opt-in'); ?>
                </h2>
                <p>
                    <?php _e("You can use the following hooks to adjust the Opt-In to your requirements.", 'double-opt-in'); ?>
                </p>
                <p>
                    <strong><?php _e("An Opt-in link has been called which is already confirmed or has been deleted.", 'double-opt-in'); ?></strong>
                </p>
                <div class="option">
                    <div class="input">
                        <p>
                            add_action('f12_cf7_doubleoptin_already_confirmed', $hash, $OptIn)
                            <br>
                        </p>
                    </div>
                </div>

                <p>
                    <strong><?php _e("An Opt-in link has been called but not yet updated the database.", 'double-opt-in'); ?></strong>
                </p>
                <div class="option">
                    <div class="input">
                        <p>
                            add_action('f12_cf7_doubleoptin_before_confirm', $hash, $OptIn)
                            <br>
                        </p>
                    </div>
                </div>

                <p>
                    <strong><?php _e("An Opt-in link has been called and the database has been updated already.", 'double-opt-in'); ?></strong>
                </p>
                <div class="option">
                    <div class="input">
                        <p>
                            add_action('f12_cf7_doubleoptin_after_confirm', $hash, $OptIn)
                        </p>
                    </div>
                </div>

            </div>
            <?php
        }
    }
}
```
