# double-opt-in/3.0.51/core/TemplateHandler.class.php

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

- Page: https://pluginprobe.com/plugins/double-opt-in/3.0.51/code/core/TemplateHandler.class.php
- Raw: https://pluginprobe.com/plugins/double-opt-in/3.0.51/raw/core/TemplateHandler.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.51/code/core/TemplateHandler.class.php#L10-L20`.

```php
<?php
namespace forge12\contactform7\CF7DoubleOptIn;

if(!defined('ABSPATH')){
	exit;
}

class TemplateHandler{
	private static ?TemplateHandler $_instance = null;

	public static function getInstance() {
		if ( self::$_instance == null ) {
			self::$_instance = new self();
		}

		return self::$_instance;
	}

	/**
	 * Get the content of the specified template with the given attributes.
	 *
	 * @param string $template_name The name of the template file.
	 * @param array  $atts          The parameters sent to the template.
	 *
	 * @return string The content of the template.
	 */
	public function getTemplate( $template_name, $atts = array() ) {
		$template_path = plugin_dir_path( dirname(__FILE__) ) . '/templates/' . $template_name . '.php';

		if ( ! is_readable( $template_path ) ) {
			return '';
		}

		extract( $atts );

		ob_start();
		require( $template_path );

		return ob_get_clean();
	}

	/**
	 * Renders the specified template with the given attributes.
	 *
	 * @param string $template_name The name of the template file.
	 * @param array  $atts          The parameters sent to the template.
	 */
	public function renderTemplate( $template_name, $atts = array() ) {
		$template = $this->getTemplate( $template_name, $atts );

		if ( empty( $template ) ) {
			return;
		}

		echo $template;
	}

}
```
