File: /home/globfdxw/public_html/wp-content/plugins/wpforms-pdf/src/Notifications/Fields.php
<?php
namespace WPFormsPDF\Notifications;
use WPForms\Emails\Notifications;
/**
* Class Fields.
*
* @since 1.0.0
*/
class Fields {
/**
* Form data.
*
* @since 1.0.0
*
* @var array
*/
private $form_data;
/**
* Template data.
*
* @since 1.0.0
*
* @var array
*/
private $template;
/**
* Is field processing enabled.
*
* @since 1.0.0
*
* @var bool
*/
private $is_enabled;
/**
* Class constructor.
*
* @since 1.0.0
*
* @return void
*/
public function __construct() {
new Fields\Address();
new Fields\Divider();
new Fields\Pagebreak();
new Fields\Signature();
new Fields\Textarea();
new Fields\Richtext();
}
/**
* Initialize fields.
*
* @since 1.0.0
*
* @param array $entry_fields Entry fields.
* @param array $form_data Form data.
* @param array $template Template data.
*
* @return void
*/
public function init( array $entry_fields, array $form_data, array $template ): void {
$this->form_data = $form_data;
$this->template = $template;
$this->is_enabled = true;
$this->hooks();
}
/**
* Register hooks.
*
* @since 1.0.0
*
* @return void
*/
public function hooks(): void {
add_filter( 'wpforms_html_field_value', [ $this, 'field_html_value' ], 100, 4 );
add_filter(
'wpforms_emails_notifications_field_message_html',
[ $this, 'field_message_html' ],
100,
7
);
}
/**
* Disable field processing.
*
* @since 1.0.0
*
* @return void
*/
public function disable_field_processing(): void {
$this->is_enabled = false;
}
/**
* Get field HTML value.
*
* @since 1.0.0
*
* @param string|mixed $value Field value.
* @param array $field Field data.
* @param array $form_data Form data.
* @param string $context Context.
*
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function field_html_value( $value, array $field, array $form_data, string $context ): string {
$value = (string) $value;
if ( $context !== 'email-html' || ! $this->is_enabled ) {
return $value;
}
/**
* Filter the specific field type HTML value.
*
* @since 1.0.0
*
* @param string $value Field value.
* @param array $field Field data.
* @param array $form_data Form data.
* @param array $template Context of the field name.
*/
$value = (string) apply_filters(
"wpforms_pdf_notifications_fields_field_html_value_{$field['type']}",
$value,
$field,
$this->form_data,
$this->template
);
/**
* Filter the field HTML value.
*
* @since 1.0.0
*
* @param string $value Field value.
* @param array $field Field data.
* @param array $form_data Form data.
* @param array $template Context of the field name.
*/
return (string) apply_filters(
'wpforms_pdf_notifications_fields_field_html_value',
$value,
$field,
$this->form_data,
$this->template
);
}
/**
* Get field message HTML markup.
*
* It includes the field label and value.
*
* @since 1.0.0
*
* @param string|mixed $field_markup Field message.
* @param array $field Field data.
* @param bool $show_empty_fields Whether to display empty fields in the email.
* @param array $other_fields List of field types.
* @param array $form_data Form data.
* @param array $fields List of submitted fields.
* @param Notifications $notifications Notifications instance.
*
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function field_message_html( $field_markup, array $field, bool $show_empty_fields, array $other_fields, array $form_data, array $fields, Notifications $notifications ): string { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$field_markup = (string) $field_markup;
if ( ! $this->is_enabled ) {
return $field_markup;
}
/**
* Filter the specific field type HTML value.
*
* @since 1.0.0
*
* @param string $field_markup Field value.
* @param array $field Field data.
* @param array $form_data Form data.
* @param array $template Context of the field name.
*/
$html = (string) apply_filters(
"wpforms_pdf_notifications_fields_field_message_html_{$field['type']}",
$field_markup,
$field,
$this->form_data,
$this->template
);
/**
* Filter the field HTML value.
*
* @since 1.0.0
*
* @param string $field_markup Field value.
* @param array $field Field data.
* @param array $form_data Form data.
* @param array $template Context of the field name.
*/
return (string) apply_filters(
'wpforms_pdf_notifications_fields_field_message_html',
$html,
$field,
$this->form_data,
$this->template
);
}
}