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

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

- Page: https://pluginprobe.com/plugins/double-opt-in/3.1.0/code/ui/UIDashboard.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/3.1.0/raw/ui/UIDashboard.class.php
- Modified: 2025-09-23T13:34:24+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/3.1.0/code/ui/UIDashboard.class.php#L10-L20`.

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {

	use Forge12\Shared\LoggerInterface;

	if (!defined('ABSPATH')) {
        exit;
    }

    /**
     * Class UIDashboard
     *
     * @package forge12\contactform7\CF7DoubleOptIn
     */
    class UIDashboard extends UIPage
    {
	    /**
	     * Constructor for the class.
	     *
	     * @param TemplateHandler $templateHandler The template handler object.
	     * @param string          $domain          The text domain for translations.
	     *
	     * @return void
	     */
	    public function __construct(LoggerInterface $logger, TemplateHandler $templateHandler, string $domain)
	    {
		    parent::__construct(
			    $logger,
			    $templateHandler,
			    $domain,
			    'f12-cf7-doubleoptin',
			    __('Dashboard','double-opt-in'),
			    0
		    );

		    $this->get_logger()->notice( 'UIDashboard parent constructor called with a position of 0.', [
			    'plugin' => $domain,
		    ] );
	    }

	    public function getSettings($settings)
	    {
		    $this->get_logger()->info( 'getSettings method called. Returning the provided settings array without modification.', [
			    'plugin' => $this->domain,
			    'page_slug' => $this->slug,
			    'settings_keys' => is_array($settings) ? array_keys($settings) : 'not an array',
		    ] );

		    return $settings;
	    }

	    protected function onSave($settings)
	    {
		    $this->get_logger()->info( 'onSave method for the dashboard UI page called. No modifications to settings are performed.', [
			    'plugin' => $this->domain,
		    ] );

		    // This method is a placeholder and intentionally does not modify the settings.
		    // The dashboard UI page is typically for viewing information, not for saving settings.
		    return $settings;
	    }

        /**
         * Maybe delete an given entry.
         */
	    private function maybeDelete()
	    {
		    $this->get_logger()->info('Attempting to handle a delete or status-based message display.', [
			    'plugin' => $this->domain,
		    ]);

		    // Handle delete request
		    if (isset($_GET['option']) && $_GET['option'] == 'delete' && isset($_GET['hash']) && !empty($_GET['hash']) && current_user_can('manage_options')) {
			    $hash = esc_attr($_GET['hash']);
			    $this->get_logger()->debug('Delete request received for hash: ' . $hash, [
				    'plugin' => $this->domain,
				    'hash' => $hash,
			    ]);

			    $CleanUp = new CleanUp($this->get_logger());

			    if ($CleanUp->deleteByHash($hash)) {
				    $this->get_logger()->notice('Successfully deleted DOI with hash: ' . $hash . '. Redirecting.', [
					    'plugin' => $this->domain,
				    ]);
				    wp_redirect('admin.php?page=f12-cf7-doubleoptin&status=deleted');
				    wp_die();
			    } else {
				    $this->get_logger()->error('Failed to delete DOI with hash: ' . $hash . '. Redirecting.', [
					    'plugin' => $this->domain,
				    ]);
				    wp_redirect('admin.php?page=f12-cf7-doubleoptin&status=error');
				    wp_die();
			    }

			    // Handle status message display after a redirect
		    } else if (isset($_GET['status'])) {
			    $status = sanitize_text_field($_GET['status']);
			    $this->get_logger()->info('Processing status message from URL: ' . $status, [
				    'plugin' => $this->domain,
			    ]);

			    if ($status == 'deleted') {
				    Messages::getInstance()->add(__('The given DOI has been removed.', 'double-opt-in'), 'success');
				    $this->get_logger()->notice('Added "DOI deleted" success message.', [
					    'plugin' => $this->domain,
				    ]);
			    }
			    if ($status == 'error') {
				    Messages::getInstance()->add(__('Couldn\'t delete the DOI, please try again later.', 'double-opt-in'), 'error');
				    $this->get_logger()->error('Added "DOI deletion failed" error message.', [
					    'plugin' => $this->domain,
				    ]);
			    }
		    }
	    }

	    public function theContent($slug, $page, $settings)
	    {
		    $this->get_logger()->info('Rendering the main content for the Dashboard UI page.', [
			    'plugin'    => $this->domain,
			    'page_slug' => $page,
		    ]);

		    // Check for and handle a deletion request.
		    // The maybeDelete() method will handle logging, nonce checks, and redirection on its own.
		    $this->maybeDelete();

		    // Render the latest Opt-Ins table.
		    // The renderLatestOptIns() method is responsible for fetching data and rendering the HTML table.
		    $this->get_logger()->info('Calling renderLatestOptIns() to display the latest entries.', [
			    'plugin' => $this->domain,
		    ]);
		    $this->renderLatestOptIns($slug, $page);

		    $this->get_logger()->notice('Dashboard content rendering completed successfully.', [
			    'plugin' => $this->domain,
		    ]);
	    }

	    private function renderLatestOptins($slug, $page)
	    {
		    $this->get_logger()->info('Rendering the latest Opt-Ins table for the Dashboard UI page.', [
			    'plugin'    => $this->domain,
			    'page_slug' => $page,
		    ]);

		    $atts = array(
			    'perPage' => 10,
			    'page' => 1,
			    'order' => 'DESC',
			    'keyword' => ''
		    );

		    // Set pagination and search attributes from URL parameters.
		    if(isset($_GET['perPage'])){
			    $atts['perPage'] = (int)$_GET['perPage'];
			    $this->get_logger()->debug('perPage attribute set from URL: ' . $atts['perPage'], [
				    'plugin' => $this->domain,
			    ]);
		    }

		    if (isset($_GET['pageNum'])) {
			    $atts['page'] = (int)$_GET['pageNum'];
			    $this->get_logger()->debug('pageNum attribute set from URL: ' . $atts['page'], [
				    'plugin' => $this->domain,
			    ]);
		    }

		    if(isset($_GET['keyword'])){
			    $atts['keyword'] = sanitize_text_field($_GET['keyword']);
			    $this->get_logger()->debug('keyword attribute set from URL: ' . $atts['keyword'], [
				    'plugin' => $this->domain,
			    ]);
		    }

		    if(isset($_GET['cf_form_id'])){
			    $atts['cf_form_id'] = (int)$_GET['cf_form_id'];
			    $this->get_logger()->debug('cf_form_id attribute set from URL: ' . $atts['cf_form_id'], [
				    'plugin' => $this->domain,
			    ]);
		    }

		    $numberOfPages = 0;
		    $this->get_logger()->info('Fetching a list of Opt-Ins from the database.', [
			    'plugin'     => $this->domain,
			    'query_atts' => $atts,
		    ]);

		    // Fetch the list of opt-ins based on the attributes.
		    $listOfOptIns = OptIn::get_list($atts, $numberOfPages);

		    $this->get_logger()->notice('Found ' . count($listOfOptIns) . ' Opt-Ins across ' . $numberOfPages . ' pages.', [
			    'plugin' => $this->domain,
		    ]);

		    /*
			 * Render the Template
			 */
		    ?>
            <h1><?php _e('Latest Opt-ins', 'double-opt-in'); ?></h1>
		    <?php
		    $this->get_logger()->info('Rendering the "list-optins" template.', [
			    'plugin' => $this->domain,
		    ]);

		    // Render the list-optins template with the fetched data.
		    $this->TemplateHandler->renderTemplate('list-optins', array(
			    'domain' => $this->domain,
			    'listOfOptIns' => $listOfOptIns,
			    'numberOfPages' => $numberOfPages,
			    'currentPage' => $atts['page'],
			    'slug' => $slug
		    ));

		    $this->get_logger()->notice('Finished rendering the latest Opt-Ins content.', [
			    'plugin' => $this->domain,
		    ]);
	    }

	    public function theSidebar($slug, $page)
	    {
		    $this->get_logger()->info('Rendering the sidebar content for the Dashboard UI page.', [
			    'plugin'    => $this->domain,
			    'page_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
		    $this->get_logger()->notice('Dashboard sidebar content rendered successfully.', [
			    'plugin' => $this->domain,
		    ]);
	    }
    }
}
```
