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/public_html/wp-content/plugins/wpforms-pdf/src/Builder/Ajax/Template.php
<?php

namespace WPFormsPDF\Builder\Ajax;

/**
 * Class Preview.
 *
 * Handles AJAX requests for updating template data.
 *
 * @since 1.0.0
 */
class Template extends Base {

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

		add_action( 'wp_ajax_wpforms_pdf_update_template_data', [ $this, 'update_template_data' ] );
	}

	/**
	 * Update theme data.
	 *
	 * @since 1.0.0
	 */
	public function update_template_data(): void {

		// Verify the AJAX request.
		$this->verify_ajax_request();

		// Get and sanitize POST data.
		$template_data = $this->get_post_data( 'data', 'array' );

		// Validate IDs.
		if ( empty( $template_data ) ) {
			wp_send_json_error( esc_html__( 'Empty template data.', 'wpforms-pdf' ) );
		}

		$is_delete = ! empty( $template_data['delete'] );

		if ( $is_delete ) {
			// Delete custom template.
			$result = wpforms_pdf()->templates->delete_custom_template( $template_data );
		} else {
			// Update custom template data.
			$result = wpforms_pdf()->templates->update_custom_template( $template_data );
		}

		// Check for errors.
		if ( ! $result ) {
			// Log the error.
			wpforms_pdf()->helpers->log(
				[
					'message'       => 'Can\'t update custom template data.',
					'template_data' => $template_data,
					'operation'     => $is_delete ? 'delete' : 'update',
				],
				'error'
			);

			wp_send_json_error();
		}

		// Send the response.
		wp_send_json_success();
	}
}