# double-opt-in/2.15/ui/UIOptinView.class.php

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

- Page: https://pluginprobe.com/plugins/double-opt-in/2.15/code/ui/UIOptinView.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/2.15/raw/ui/UIOptinView.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.15/code/ui/UIOptinView.class.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {
    if (!defined('ABSPATH')) {
        exit;
    }

    /**
     * Class UIOptinView
     * Show a specific OptIn
     *
     * @package forge12\contactform7\CF7DoubleOptIn
     */
    class UIOptinView extends UIPage
    {
        public function __construct($domain)
        {
            parent::__construct($domain, 'optin_view', 'OptIn View');

            if (isset($_GET['status'])) {
                $status = sanitize_text_field($_GET['status']);

                switch ($status) {
                    case 'deleted':
                        Messages::getInstance()->add(__('Opt-In deleted', 'double-opt-in'), 'success');
                        break;
                    case 'not-deleted':
                        Messages::getInstance()->add(__('Opt-In not-deleted', 'double-opt-in'), 'error');
                        break;
                    default:
                        break;
                }
            }
        }

        /**
         * Hide this page in the menu.
         *
         * @return bool
         */
        public function hideInMenu()
        {
            return true;
        }

        /**
         * Render the license subpage content
         */
        protected function theContent($slug, $page, $settings)
        {
            /*
             * Ensure that the hash is given
             */
            if (!isset($_GET['hash'])) {
                wp_redirect(admin_url('admin.php') . '?page=f12-cf7-doubleoptin');
            }

            $this->maybeSave();


            $hash = sanitize_text_field($_GET['hash']);

            /*
             * Load the assigned Category
             */
            $Optin = Optin::get_by_hash($hash);

            if (null === $Optin) {
                wp_redirect(admin_url('admin.php') . '?page=f12-cf7-doubleoptin');
            }

            /*
             * Render the Template
             */
            ?>
            <h2><?php _e('Opt-In: ', 'double-opt-in') . esc_attr_e($Optin->get_hash()); ?></h2>
            <?php
            CF7DoubleOptIn::getInstance()->renderTemplate('view-optin', array(
                'domain' => $this->domain,
                'optin' => $Optin
            ));
        }

        /**
         * Update the Optin if the category has been submitted.
         * @return void
         */
        private function maybeSave(){
            if(!isset($_POST['hash']) || !wp_verify_nonce($_POST['doi_settings_nonce'], 'doi_settings_action')){
                return;
            }

            $category = (int)$_POST['category'];
            $hash = sanitize_text_field($_POST['hash']);


            if(!$category){
                return;
            }

            $Optin = OptIn::get_by_hash($hash);
            $Optin->set_category($category);
            $Optin->save();
        }

        protected function theSidebar($slug, $page)
        {
            /*
             * Ensure that the ID for the Categorie is set
             */
            if (!isset($_GET['hash'])) {
                wp_redirect(admin_url('admin.php') . '?page=f12-cf7-doubleoptin');
            }

            $hash = sanitize_text_field($_GET['hash']);

            /*
             * Load the OptIn
             */
            $Optin = OptIn::get_by_hash($hash);

            if (!$Optin) {
                wp_redirect(admin_url('admin.php') . '?page=f12-cf7-doubleoptin');
            }
            ?>
            <div class="box">
                <h2>
                    <?php _e('Edit Opt-In:', 'double-opt-in'); ?>
                </h2>

                <form action="" method="post">
                    <div class="option">
                        <div class="label">
                            <label for="category"><?php _e('Category:', 'double-opt-in'); ?></label>
                        </div>
                        <input type="hidden" value="<?php esc_attr_e($Optin->get_hash()); ?>" name="hash"/>
                        <div class="input">
                            <?php
                            echo wp_kses(CategoryOptions::getInstance()->select_category($Optin->get_category()), array('select' => array('name' => array()), 'option' => array('value' => array(), 'selected' => array())));
                            ?>
                            <p>
                                <?php _e('Select the category to assign the Opt-In.', 'double-opt-in'); ?>
                            </p>
                        </div>
                    </div>
                    <?php
                    wp_nonce_field('doi_settings_action', 'doi_settings_nonce');
                    ?>

                    <input type="submit" name="doubleoptin-settings-edit-submit" class="button"
                           value=" <?php _e('Update', 'double-opt-in'); ?>"/>
                </form>
            </div>

            <div class="box">
                <h2>
                    <?php _e('Links:', 'double-opt-in'); ?>
                </h2>

                <div class="option">
                    <div class="label">
                        <label for="category"><?php _e('Opt-In:', 'double-opt-in'); ?></label>
                    </div>
                    <div class="input copy-to-clipboard">
                        <?php
                        echo esc_url_raw($Optin->get_link_optin());
                        ?>
                    </div>
                </div>
            </div>
            <?php
        }

        public function getSettings($settings)
        {
            return $settings;
        }
    }
}
```
