HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/www/wp-content/plugins/wpforms-pdf/src/Access/File.php
<?php

namespace WPFormsPDF\Access;

/**
 * File access handler for PDF access templates.
 *
 * @since 1.0.0
 */
class File {
	/**
	 * File constructor.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {

		$this->hooks();
	}

	/**
	 * Register hooks.
	 *
	 * @since 1.0.0
	 */
	private function hooks(): void {

		if ( ! $this->is_access_page() ) {
			return;
		}

		add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ] );
		add_filter( 'body_class', [ $this, 'body_class' ] );

		add_filter( 'qm/dispatch/html', '__return_false' );
		add_filter( 'show_admin_bar', '__return_false' );
	}

	/**
	 * Enqueue styles for access templates if on an access page.
	 *
	 * @since 1.0.0
	 */
	public function enqueue_styles(): void {

		$min = wpforms_get_min_suffix();

		wp_enqueue_style(
			'wpforms-pdf-access',
			WPFORMS_PDF_URL . "assets/css/access-protection-page{$min}.css",
			[],
			WPFORMS_PDF_VERSION
		);
	}

	/**
	 * Add custom body class.
	 *
	 * @since 1.0.0
	 *
	 * @param array $classes Body classes.
	 *
	 * @return array
	 */
	public function body_class( array $classes ): array {

		$classes[] = 'wpforms-file-download';

		return $classes;
	}

	/**
	 * Determine if the current request is for a PDF access page.
	 *
	 * @since 1.0.0
	 *
	 * @return bool
	 */
	private function is_access_page(): bool {
		// Check if we're rendering one of the access templates.
		// This can be detected by checking if the global $template or a custom query var was set.
		// For simplicity, check for the query param used for PDF download.
		if ( ! empty( $_GET['wpforms_pdf_download'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
			return true;
		}

		return false;
	}
}