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

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

- Page: https://pluginprobe.com/plugins/double-opt-in/3.0.60/code/ui/UIOptinView.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/3.0.60/raw/ui/UIOptinView.class.php
- Modified: 2024-08-13T13:52:36+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.0.60/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 {
		/**
		 * Class constructor.
		 *
		 * @param TemplateHandler $templateHandler The template handler object.
		 * @param string          $domain          The domain of the class.
		 *
		 * @return void
		 */
		public function __construct( TemplateHandler $templateHandler, string $domain ) {
			parent::__construct( $templateHandler, $domain, 'optin_view', __( 'OptIn View', 'double-opt-in' ) );

			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
			$this->TemplateHandler->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( 'Opt-In:', 'double-opt-in' ); ?>
                </h2>

                <div class="option">
                    <div class="label">
                        <label for="category"><?php _e( 'Link:', 'double-opt-in' ); ?></label>
                    </div>
                    <div class="input copy-to-clipboard">
						<?php
						echo $Optin->get_link_optin();
						?>
                    </div>
                </div>

            </div>


			<?php

			/**
			 * Sidebar
			 *
			 * This Hook allows us to extend the sidebar for the pro version.
			 *
			 * @param OptIn $Optin
			 *
			 * @since 3.0.0
			 */
			do_action( 'f12_cf7_doubleoptin_ui_view_optin_sidebar', $Optin );
		}

		public function getSettings( $settings ) {
			return $settings;
		}
	}
}
```
