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/Notifications/Fields/Signature.php
<?php

namespace WPFormsPDF\Notifications\Fields;

/**
 * Class Signature field.
 *
 * @since 1.1.0
 */
class Signature {

	/**
	 * Class constructor.
	 *
	 * @since 1.1.0
	 *
	 * @return void
	 */
	public function __construct() {

		$this->hooks();
	}

	/**
	 * Register hooks.
	 *
	 * @since 1.1.0
	 *
	 * @return void
	 */
	public function hooks(): void {

		add_filter(
			'wpforms_process_smart_tags',
			[ $this, 'filter_process_smart_tags' ],
			-100,
			5
		);
	}

	/**
	 * Filter processing smart tags.
	 *
	 * @since 1.1.0
	 *
	 * @param string|mixed $content   Content.
	 * @param array        $form_data Form data.
	 * @param array        $fields    List of fields.
	 * @param string       $entry_id  Entry ID.
	 * @param string       $context   Context.
	 *
	 * @return string
	 * @noinspection PhpUnusedParameterInspection
	 */
	public function filter_process_smart_tags( $content, array $form_data, array $fields = [], string $entry_id = '', string $context = '' ): string { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks

		$content = (string) $content;

		if ( ! in_array( $context, [ 'wpforms-pdf-preview-process-texts', 'wpforms-pdf-process-texts' ], true ) ) {
			return $content;
		}

		static $filter_added = false;

		if ( ! $filter_added ) {
			add_filter( 'wpforms_smart_tags_formatted_field_value', [ $this, 'filter_smart_tags_formatted_field_value' ], 100, 5 );

			$filter_added = true;
		}

		return $content;
	}

	/**
	 * Filter the formatted field value.
	 *
	 * @since 1.1.0
	 *
	 * @param string|mixed $value    Field value.
	 * @param int          $field_id Field ID.
	 * @param array        $fields   List of fields.
	 *
	 * @return string
	 * @noinspection HtmlUnknownTarget
	 */
	public function filter_smart_tags_formatted_field_value( $value, int $field_id, array $fields ): string {

		$value = (string) $value;

		if (
			! isset( $fields[ $field_id ]['type'] ) ||
			$fields[ $field_id ]['type'] !== 'signature'
		) {
			return $value;
		}

		return sprintf(
			'<img src="%1$s" style="max-width:100%%;display:block;margin:0;" alt="">',
			esc_url( $value )
		);
	}
}