File: /home/globfdxw/www/wp-content/plugins/wpforms-pdf/src/Plugin.php
<?php
namespace WPFormsPDF;
use WPFormsPDF\Builder\FormBuilder;
use WPFormsPDF\Builder\Ajax;
use WPFormsPDF\Notifications\Process;
use WPFormsPDF\SmartTags\SmartTags;
use WPFormsPDF\Templates\Templates;
use WPFormsPDF\Templates\Themes;
use WPFormsPDF\Access\PDF as AccessPDF;
use WPFormsPDF\Access\File as AccessFile;
use WPFormsPDF\Admin\Entry;
/**
* Main class.
*
* @since 1.0.0
*/
final class Plugin {
/**
* Provider name.
*
* @since 1.0.0
*/
public const NAME = 'PDF';
/**
* Provider slug.
*
* @since 1.0.0
*/
public const SLUG = 'pdf';
/**
* Notifications Process instance.
*
* @since 1.0.0
*
* @var Process
*/
private $process;
/**
* Helpers instance.
*
* @since 1.0.0
*
* @var Helpers
*/
public $helpers;
/**
* Templates instance.
*
* @since 1.0.0
*
* @var Templates
*/
public $templates;
/**
* Themes instance.
*
* @since 1.0.0
*
* @var Themes
*/
public $themes;
/**
* FormBuilder instance.
*
* @since 1.0.0
*
* @var FormBuilder
*/
public $form_builder;
/**
* Access instance.
*
* @since 1.0.0
*
* @var AccessPDF
*/
public $access;
/**
* Access File instance.
*
* @since 1.0.0
*
* @var AccessFile
*/
public $access_file;
/**
* Entry instance.
*
* @since 1.0.0
*
* @var Entry
*/
public $entry;
/**
* Plugin constructor.
*
* @since 1.0.0
*/
private function __construct() {}
/**
* Get a single instance of the class.
*
* @since 1.0.0
*
* @return Plugin
*/
public static function get_instance(): Plugin {
static $instance = null;
if ( ! $instance ) {
$instance = new Plugin();
$instance->init();
}
return $instance;
}
/**
* Initialize plugin.
*
* @since 1.0.0
*/
public function init(): void {
$this->load_dependencies();
$this->hooks();
}
/**
* Plugin hooks.
*
* @since 1.0.0
*/
private function hooks(): void {
add_filter( 'wpforms_helpers_templates_include_html_located', [ $this, 'register_templates' ], 10, 2 );
}
/**
* Get property.
*
* @since 1.0.0
*
* @param string $property_name Property name.
*
* @return mixed
*/
public function get( string $property_name ) {
return property_exists( $this, $property_name ) ? $this->{$property_name} : null;
}
/**
* Register addon templates location.
*
* @since 1.0.0
*
* @param string|mixed $located Template location.
* @param string $template Template.
*
* @return string
*/
public function register_templates( $located, string $template ): string {
// Checking if `$template` is an absolute path and passed from this plugin.
if (
strpos( $template, WPFORMS_PDF_PATH ) === 0 &&
is_readable( $template )
) {
return $template;
}
return (string) $located;
}
/**
* All the actual plugin loading is done here.
*
* @since 1.0.0
*/
private function load_dependencies(): void {
$this->helpers = new Helpers();
$this->process = new Process();
$this->templates = new Templates();
$this->themes = new Themes();
$this->form_builder = new FormBuilder();
$this->access = new AccessPDF();
$this->access_file = new AccessFile();
$this->entry = new Entry();
( new Cleanup() )->init();
( new SmartTags() )->init();
if ( ! wpforms_is_admin_ajax() ) {
return;
}
// AJAX handlers.
new Ajax\TemplateFields();
new Ajax\SaveForm();
new Ajax\Preview();
new Ajax\Template();
new Ajax\Theme();
}
}