# double-opt-in/3.0.3/ui/UICategoriesView.class.php

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

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

```php
<?php

namespace forge12\contactform7\CF7DoubleOptIn {
	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	/**
	 * Class UICategories
	 * Show the Category and Assigned DOIs
	 *
	 * @package forge12\contactform7\CF7DoubleOptIn
	 */
	class UICategoriesView extends UIPage {
		/**
		 * Class constructor.
		 *
		 * @param TemplateHandler $templateHandler The template handler object.
		 * @param string          $domain          The domain string.
		 */
		public function __construct( TemplateHandler $templateHandler, string $domain ) {
			parent::__construct( $templateHandler, $domain, 'categories_view', __('Category View', 'double-opt-in') );

			add_action( 'admin_init', array( $this, 'maybeUpdateCategory' ) );
		}

		public function maybeUpdateCategory() {
			if ( isset( $_POST['doi_settings_nonce'] ) && ! wp_verify_nonce( $_POST['doi_settings_nonce'], 'doi_settings_action' ) ) {
				return;
			}

			if ( ! isset( $_POST['doubleoptin-settings-edit-submit'] ) ) {
				return;
			}

			if ( ! isset( $_POST['category_id'] ) ) {
				return;
			}

			$category_id = (int) $_POST['category_id'];

			$Category = Category::get_by_id( $category_id );

			if ( null === $Category ) {
				return;
			}

			$name = sanitize_text_field( $_POST['categorie_name'] );

			if ( empty( $name ) ) {
				return false;
			}

			$Category->set_name( $name );

			if ( $Category->save() ) {
				Messages::getInstance()->add( __( 'Category updated', 'double-opt-in' ), 'success' );
			} else {
				Messages::getInstance()->add( __( 'Category update failed', 'double-opt-in' ), 'error' );
			}
		}

		/**
		 * 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 ID for the Categorie is set
			 */
			if ( ! isset( $_GET['id'] ) ) {
				wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' );
			}

			$id = (int) $_GET['id'];

			/*
			 * Load the assigned Category
			 */
			$Category = Category::get_by_id( $id );

			if ( null === $Category ) {
				wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' );
			}

			$atts = array(
				'perPage' => 10,
				'page'    => 1,
				'order'   => 'DESC',
			);

			if ( isset( $_GET['pageNum'] ) ) {
				$atts['page'] = (int) $_GET['pageNum'];
			}

			if ( isset( $_GET['perPage'] ) ) {
				$atts['perPage'] = (int) $_GET['perPage'];
			}

			if ( isset( $_GET['keyword'] ) ) {
				$atts['keyword'] = sanitize_text_field( $_GET['keyword'] );
			}

			$numberOfPages = 0;
			$listOfOptIns  = OptIn::get_list_by_category_id( $Category->get_id(), $atts, $numberOfPages );

			/*
			 * Render the Template
			 */
			?>
            <h1><?php _e( 'Category: ', 'double-opt-in' ) . esc_attr_e( $Category->get_name() ); ?></h1>
			<?php

			$this->TemplateHandler->renderTemplate( 'list-optins', array(
				'domain'        => $this->domain,
				'listOfOptIns'  => $listOfOptIns,
				'numberOfPages' => $numberOfPages,
				'currentPage'   => $atts['page'],
				'slug'          => $slug
			) );
		}

		protected function theSidebar( $slug, $page ) {
			/*
			 * Ensure that the ID for the Categorie is set
			 */
			if ( ! isset( $_GET['id'] ) ) {
				wp_redirect( admin_url( 'admin.php' ) . '?page=f12-cf7-doubleoptin' );
			}

			$id = (int) $_GET['id'];

			/*
			 * Load the assigned Category
			 */
			$Category = Category::get_by_id( $id );

			?>
            <div class="box">
                <h2>
					<?php _e( 'Edit Category:', 'double-opt-in' ); ?>
                </h2>

                <form action="" method="post">
                    <div class="option">
                        <input type="hidden" value="<?php esc_attr_e( $_GET['id'] ); ?>" name="category_id"/>
                        <div class="input">
                            <input type="text" name="categorie_name"
                                   value="<?php esc_attr_e( $Category->get_name() ); ?>"
                                   placeholder="<?php _e( 'Please enter the Name of the Categorie', 'double-opt-in' ); ?>"/>
                            <p>
								<?php _e( 'Enter the name of the Categorie and submit.', '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>
			<?php
		}

		public function getSettings( $settings ) {
			return $settings;
		}
	}
}
```
