Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/wpforms-.../src/Frontend
File: Modern.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Frontend;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Modern render engine class.
[5] Fix | Delete
*
[6] Fix | Delete
* @since 1.8.1
[7] Fix | Delete
*/
[8] Fix | Delete
class Modern extends Classic {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Hooks.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 1.8.1
[14] Fix | Delete
*/
[15] Fix | Delete
public function hooks() {
[16] Fix | Delete
[17] Fix | Delete
add_filter( 'wpforms_field_properties', [ $this, 'field_properties' ], 10, 3 );
[18] Fix | Delete
add_filter( 'wpforms_get_field_required_label', [ $this, 'get_field_required_label' ], 10 );
[19] Fix | Delete
add_filter( 'wpforms_frontend_strings', [ $this, 'frontend_strings' ], 10 );
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Open form container.
[24] Fix | Delete
*
[25] Fix | Delete
* @since 1.8.1
[26] Fix | Delete
*
[27] Fix | Delete
* @param string $classes Form container classes.
[28] Fix | Delete
* @param array $form_data Form data.
[29] Fix | Delete
*/
[30] Fix | Delete
public function form_container_open( $classes, $form_data ) {
[31] Fix | Delete
[32] Fix | Delete
$classes[] = 'wpforms-render-modern';
[33] Fix | Delete
[34] Fix | Delete
parent::form_container_open( $classes, $form_data );
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Noscript message.
[39] Fix | Delete
*
[40] Fix | Delete
* @since 1.8.1
[41] Fix | Delete
*
[42] Fix | Delete
* @param string $msg Noscript message.
[43] Fix | Delete
*/
[44] Fix | Delete
public function noscript( $msg ) {
[45] Fix | Delete
[46] Fix | Delete
printf(
[47] Fix | Delete
'<noscript class="wpforms-error-noscript">%1$s</noscript><div id="wpforms-error-noscript" style="display: none;">%1$s</div>',
[48] Fix | Delete
esc_html( $msg )
[49] Fix | Delete
);
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Display form error.
[54] Fix | Delete
*
[55] Fix | Delete
* @since 1.8.1
[56] Fix | Delete
*
[57] Fix | Delete
* @param string $type Error type.
[58] Fix | Delete
* @param string $error Error text.
[59] Fix | Delete
*/
[60] Fix | Delete
public function form_error( $type, $error ) {
[61] Fix | Delete
[62] Fix | Delete
switch ( $type ) {
[63] Fix | Delete
case 'header':
[64] Fix | Delete
case 'footer':
[65] Fix | Delete
printf(
[66] Fix | Delete
'<div id="wpforms-%1$s-%2$s-error" class="wpforms-error-container" role="alert">
[67] Fix | Delete
<span class="wpforms-hidden" aria-hidden="false">%3$s</span>%4$s
[68] Fix | Delete
</div>',
[69] Fix | Delete
esc_attr( $this->form_data['id'] ?? 0 ),
[70] Fix | Delete
esc_attr( $type ),
[71] Fix | Delete
esc_html__( 'Form error message', 'wpforms-lite' ),
[72] Fix | Delete
wpautop( wpforms_sanitize_error( $error ) ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[73] Fix | Delete
);
[74] Fix | Delete
break;
[75] Fix | Delete
[76] Fix | Delete
case 'header_styled':
[77] Fix | Delete
case 'footer_styled':
[78] Fix | Delete
printf(
[79] Fix | Delete
'<div id="wpforms-%1$s-%2$s-error" class="wpforms-error-container wpforms-error-styled-container" role="alert">
[80] Fix | Delete
<div class="wpforms-error"><span class="wpforms-hidden" aria-hidden="false">%3$s</span>%4$s</div>
[81] Fix | Delete
</div>',
[82] Fix | Delete
esc_attr( $this->form_data['id'] ),
[83] Fix | Delete
esc_attr( $type ),
[84] Fix | Delete
esc_html__( 'Form error message', 'wpforms-lite' ),
[85] Fix | Delete
wpautop( wpforms_sanitize_error( $error ) ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[86] Fix | Delete
);
[87] Fix | Delete
break;
[88] Fix | Delete
[89] Fix | Delete
case 'header_styled':
[90] Fix | Delete
case 'footer_styled':
[91] Fix | Delete
printf(
[92] Fix | Delete
'<div id="wpforms-%1$s-%2$s-error" class="wpforms-error-container wpforms-error-styled-container" role="alert">
[93] Fix | Delete
<div class="wpforms-error"><span class="wpforms-hidden" aria-hidden="false">%3$s</span>%4$s</div>
[94] Fix | Delete
</div>',
[95] Fix | Delete
esc_attr( $this->form_data['id'] ),
[96] Fix | Delete
esc_attr( $type ),
[97] Fix | Delete
esc_html__( 'Form error message', 'wpforms-lite' ),
[98] Fix | Delete
wpautop( wpforms_sanitize_error( $error ) ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[99] Fix | Delete
);
[100] Fix | Delete
break;
[101] Fix | Delete
[102] Fix | Delete
case 'header_styled':
[103] Fix | Delete
case 'footer_styled':
[104] Fix | Delete
printf(
[105] Fix | Delete
'<div id="wpforms-%1$s-%2$s-error" class="wpforms-error-container wpforms-error-styled-container" role="alert">
[106] Fix | Delete
<div class="wpforms-error"><span class="wpforms-hidden" aria-hidden="false">%3$s</span>%4$s</div>
[107] Fix | Delete
</div>',
[108] Fix | Delete
esc_attr( $this->form_data['id'] ),
[109] Fix | Delete
esc_attr( $type ),
[110] Fix | Delete
esc_html__( 'Form error message', 'wpforms-lite' ),
[111] Fix | Delete
wpautop( wpforms_sanitize_error( $error ) ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[112] Fix | Delete
);
[113] Fix | Delete
break;
[114] Fix | Delete
[115] Fix | Delete
case 'recaptcha':
[116] Fix | Delete
printf(
[117] Fix | Delete
'<em id="wpforms-field_recaptcha-error" class="wpforms-error" role="alert">
[118] Fix | Delete
<span class="wpforms-hidden" aria-hidden="false">%1$s</span>%2$s
[119] Fix | Delete
</em>',
[120] Fix | Delete
esc_attr__( 'Recaptcha error message', 'wpforms-lite' ),
[121] Fix | Delete
wpforms_sanitize_error( $error ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[122] Fix | Delete
);
[123] Fix | Delete
break;
[124] Fix | Delete
}
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Field label markup.
[129] Fix | Delete
*
[130] Fix | Delete
* @since 1.8.1
[131] Fix | Delete
*
[132] Fix | Delete
* @param array $field Field data and settings.
[133] Fix | Delete
* @param array $form_data Form data and settings.
[134] Fix | Delete
*/
[135] Fix | Delete
public function field_label( $field, $form_data ) {
[136] Fix | Delete
[137] Fix | Delete
// Do not need to output label if the field requires fieldset.
[138] Fix | Delete
if ( $this->is_field_requires_fieldset( $field ) ) {
[139] Fix | Delete
return;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
if ( ! empty( $field['label_hide'] ) ) {
[143] Fix | Delete
$field['properties']['label']['attr']['aria-hidden'] = 'false';
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
parent::field_label( $field, $form_data );
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Open fieldset markup.
[151] Fix | Delete
*
[152] Fix | Delete
* @since 1.8.1
[153] Fix | Delete
*
[154] Fix | Delete
* @param array $field Field data and settings.
[155] Fix | Delete
* @param array $form_data Form data and settings.
[156] Fix | Delete
*/
[157] Fix | Delete
public function field_fieldset_open( $field, $form_data ) {
[158] Fix | Delete
[159] Fix | Delete
if ( ! $this->is_field_requires_fieldset( $field ) ) {
[160] Fix | Delete
return;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
if ( ! empty( $field['label_hide'] ) ) {
[164] Fix | Delete
$field['properties']['label']['attr']['aria-hidden'] = 'false';
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
$label = $field['properties']['label'];
[168] Fix | Delete
$required = $label['required'] ? wpforms_get_field_required_label() : '';
[169] Fix | Delete
[170] Fix | Delete
unset( $label['attr']['for'] );
[171] Fix | Delete
[172] Fix | Delete
printf(
[173] Fix | Delete
'<fieldset><legend %s>%s%s</legend>',
[174] Fix | Delete
wpforms_html_attributes( $label['id'], $label['class'], $label['data'], $label['attr'] ),
[175] Fix | Delete
esc_html( $label['value'] ),
[176] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[177] Fix | Delete
$required
[178] Fix | Delete
);
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
/**
[182] Fix | Delete
* Close fieldset markup.
[183] Fix | Delete
*
[184] Fix | Delete
* @since 1.8.1
[185] Fix | Delete
*
[186] Fix | Delete
* @param array $field Field data and settings.
[187] Fix | Delete
* @param array $form_data Form data and settings.
[188] Fix | Delete
*/
[189] Fix | Delete
public function field_fieldset_close( $field, $form_data ) {
[190] Fix | Delete
[191] Fix | Delete
if ( ! $this->is_field_requires_fieldset( $field ) ) {
[192] Fix | Delete
return;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
echo '</fieldset>';
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Whether the field requires fieldset markup.
[200] Fix | Delete
*
[201] Fix | Delete
* @since 1.8.1
[202] Fix | Delete
*
[203] Fix | Delete
* @param array $field Field data and settings.
[204] Fix | Delete
*/
[205] Fix | Delete
private function is_field_requires_fieldset( $field ) {
[206] Fix | Delete
[207] Fix | Delete
if ( empty( $field['type'] ) ) {
[208] Fix | Delete
return false;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Determine whether the field is requires fieldset+legend markup on the frontend.
[213] Fix | Delete
*
[214] Fix | Delete
* @since 1.8.1
[215] Fix | Delete
*
[216] Fix | Delete
* @param bool $requires_fieldset True if requires. Defaults to false.
[217] Fix | Delete
* @param array $field Field data.
[218] Fix | Delete
*/
[219] Fix | Delete
return (bool) apply_filters( "wpforms_frontend_modern_is_field_requires_fieldset_{$field['type']}", false, $field );
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
/**
[223] Fix | Delete
* Field error.
[224] Fix | Delete
*
[225] Fix | Delete
* @since 1.8.1
[226] Fix | Delete
*
[227] Fix | Delete
* @param array $field Field data and settings.
[228] Fix | Delete
* @param array $form_data Form data and settings.
[229] Fix | Delete
*
[230] Fix | Delete
* @noinspection HtmlUnknownAttribute
[231] Fix | Delete
*/
[232] Fix | Delete
public function field_error( $field, $form_data ) {
[233] Fix | Delete
[234] Fix | Delete
if ( empty( $field['properties']['error'] ) ) {
[235] Fix | Delete
return;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
$error = $field['properties']['error'];
[239] Fix | Delete
[240] Fix | Delete
printf(
[241] Fix | Delete
'<em %1$s>%2$s</em>',
[242] Fix | Delete
wpforms_html_attributes( $error['id'], $error['class'], $error['data'], $error['attr'] ),
[243] Fix | Delete
esc_html( $error['value'] )
[244] Fix | Delete
);
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
/**
[248] Fix | Delete
* Define additional field properties.
[249] Fix | Delete
*
[250] Fix | Delete
* @since 1.8.1
[251] Fix | Delete
*
[252] Fix | Delete
* @param array $properties Field properties.
[253] Fix | Delete
* @param array $field Field settings.
[254] Fix | Delete
* @param array $form_data Form data and settings.
[255] Fix | Delete
*
[256] Fix | Delete
* @return array
[257] Fix | Delete
*/
[258] Fix | Delete
public function field_properties( $properties, $field, $form_data ) {
[259] Fix | Delete
[260] Fix | Delete
$field_id = "wpforms-{$form_data['id']}-field_{$field['id']}";
[261] Fix | Delete
$desc_id = "{$field_id}-description";
[262] Fix | Delete
[263] Fix | Delete
// Add `id` to field description.
[264] Fix | Delete
$properties['description']['id'] = $desc_id;
[265] Fix | Delete
[266] Fix | Delete
// Add attributes to error message.
[267] Fix | Delete
$properties['error']['attr']['role'] = 'alert';
[268] Fix | Delete
$properties['error']['attr']['aria-label'] = esc_html__( 'Error message', 'wpforms-lite' );
[269] Fix | Delete
$properties['error']['attr']['id'] = $properties['error']['attr']['for'] . '-error';
[270] Fix | Delete
$properties['error']['attr']['for'] = '';
[271] Fix | Delete
[272] Fix | Delete
foreach ( $properties['inputs'] as $input => $input_data ) {
[273] Fix | Delete
[274] Fix | Delete
// Add `aria-errormessage` to inputs (except hidden according to W3C requirements).
[275] Fix | Delete
if ( ! empty( $input_data['id'] ) && $field['type'] !== 'hidden' ) {
[276] Fix | Delete
$properties['inputs'][ $input ]['attr']['aria-errormessage'] = "{$input_data['id']}-error";
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
// Add `aria-describedby` to inputs.
[280] Fix | Delete
if ( ! empty( $field['description'] ) ) {
[281] Fix | Delete
$properties['inputs'][ $input ]['attr']['aria-describedby'] = $desc_id;
[282] Fix | Delete
}
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
return $properties;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
/**
[289] Fix | Delete
* Required label (asterisk) markup.
[290] Fix | Delete
*
[291] Fix | Delete
* @since 1.8.1
[292] Fix | Delete
*
[293] Fix | Delete
* @param string $label_html Required label markup.
[294] Fix | Delete
*
[295] Fix | Delete
* @return string
[296] Fix | Delete
*/
[297] Fix | Delete
public function get_field_required_label( $label_html ) {
[298] Fix | Delete
[299] Fix | Delete
return ' <span class="wpforms-required-label" aria-hidden="true">*</span>';
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
/**
[303] Fix | Delete
* Modify javascript `wpforms_settings` properties on the front end.
[304] Fix | Delete
*
[305] Fix | Delete
* @since 1.8.1
[306] Fix | Delete
*
[307] Fix | Delete
* @param array $strings Array `wpforms_settings` properties.
[308] Fix | Delete
*
[309] Fix | Delete
* @return array
[310] Fix | Delete
*/
[311] Fix | Delete
public function frontend_strings( $strings ) {
[312] Fix | Delete
[313] Fix | Delete
$strings['isModernMarkupEnabled'] = wpforms_get_render_engine() === 'modern';
[314] Fix | Delete
$strings['formErrorMessagePrefix'] = esc_html__( 'Form error message', 'wpforms-lite' );
[315] Fix | Delete
$strings['errorMessagePrefix'] = esc_html__( 'Error message', 'wpforms-lite' );
[316] Fix | Delete
$strings['submitBtnDisabled'] = esc_html__( 'Submit button is disabled during form submission.', 'wpforms-lite' );
[317] Fix | Delete
[318] Fix | Delete
return $strings;
[319] Fix | Delete
}
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function