PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFieldFormHtml.php +36 -20 6.27 → trunk View file →
@@ -179,9 +179,9 @@
179 179 private function replace_field_values() {
180 180 // Replace [id].
181 181 $this->html = str_replace( '[id]', $this->field_id, $this->html );
182 182
183 - // set the label for
183 + // Set the label for
184 184 $this->html = str_replace( 'field_[key]', $this->html_id, $this->html );
185 185
186 186 // Replace [key].
187 187 $this->html = str_replace( '[key]', $this->field_obj->get_field_column( 'field_key' ), $this->html );
@@ -211,9 +211,9 @@
211 211 * @return void
212 212 */
213 213 private function maybe_replace_description_shortcode( $wp_processed = false ) {
214 214 $is_html = 'html' === $this->field_obj->get_field_column( 'type' );
215 - $should_replace = ( $is_html && $wp_processed ) || ( ! $is_html && ! $wp_processed );
215 + $should_replace = $is_html ? $wp_processed : ! $wp_processed;
216 216
217 217 if ( $should_replace ) {
218 218 $this->replace_description_shortcode();
219 219 }
@@ -227,9 +227,9 @@
227 227 private function replace_description_shortcode() {
228 228 $this->maybe_add_description_id();
229 229 $description = FrmAppHelper::maybe_kses( $this->field_obj->get_field_column( 'description' ) );
230 230 // phpcs:ignore Universal.Operators.StrictComparisons
231 - FrmShortcodeHelper::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $this->html );
231 + FrmShortcodeHelper::remove_inline_conditions( $description && $description != '', 'description', $description, $this->html );
232 232 }
233 233
234 234 /**
235 235 * Add an ID to the description for aria-describedby.
@@ -268,16 +268,20 @@
268 268 if ( ! is_string( $inner_html[2] ) && count( $inner_html[2] ) === 1 ) {
269 269 $inner_html[2] = $inner_html[2][0];
270 270 }
271 271
272 - if ( is_string( $inner_html[2] ) ) {
273 - $has_id = str_contains( $inner_html[2], ' id=' );
272 + if ( ! is_string( $inner_html[2] ) ) {
273 + return;
274 + }
274 275
275 - if ( ! $has_id ) {
276 - $id = 'frm_' . $id . '_' . $this->html_id;
277 - $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html );
278 - }
276 + $has_id = str_contains( $inner_html[2], ' id=' );
277 +
278 + if ( $has_id ) {
279 + return;
279 280 }
281 +
282 + $id = 'frm_' . $id . '_' . $this->html_id;
283 + $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html );
280 284 }
281 285
282 286 /**
283 287 * @since 3.0
@@ -287,9 +291,17 @@
287 291 private function replace_error_shortcode() {
288 292 $this->maybe_add_error_id();
289 293 $error = $this->pass_args['errors'][ 'field' . $this->field_id ] ?? false;
290 294
291 - if ( $error && ! str_contains( $this->html, 'role="alert"' ) && FrmAppHelper::should_include_alert_role_on_field_errors() ) {
295 + if ( ! $error ) {
296 + FrmShortcodeHelper::remove_inline_conditions( false, 'error', $error, $this->html );
297 + return;
298 + }
299 +
300 + $include_alert_role_on_field_errors = FrmAppHelper::should_include_alert_role_on_field_errors();
301 + $has_alert_role = str_contains( $this->html, 'role="alert"' );
302 +
303 + if ( ! $has_alert_role && $include_alert_role_on_field_errors ) {
292 304 $error_body = self::get_error_body( $this->html );
293 305
294 306 if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) {
295 307 $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 );
@@ -294,11 +306,13 @@
294 306 if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) {
295 307 $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 );
296 308 $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html );
297 309 }
310 + } elseif ( ! $include_alert_role_on_field_errors && $has_alert_role ) {
311 + $this->html = str_replace( 'role="alert"', '', $this->html );
298 312 }
299 313
300 - FrmShortcodeHelper::remove_inline_conditions( ! empty( $error ), 'error', $error, $this->html );
314 + FrmShortcodeHelper::remove_inline_conditions( true, 'error', $error, $this->html );
301 315 }
302 316
303 317 /**
304 318 * Pull the HTML between [if error] and [/if error] shortcodes.
@@ -356,17 +370,19 @@
356 370 *
357 371 * @return void
358 372 */
359 373 private function replace_form_shortcodes() {
360 - if ( ! empty( $this->form ) ) {
361 - $form = (array) $this->form;
374 + if ( ! $this->form ) {
375 + return;
376 + }
362 377
363 - // Replace [form_key].
364 - $this->html = str_replace( '[form_key]', $form['form_key'], $this->html );
378 + $form = (array) $this->form;
365 379
366 - // Replace [form_name].
367 - $this->html = str_replace( '[form_name]', $form['name'], $this->html );
368 - }
380 + // Replace [form_key].
381 + $this->html = str_replace( '[form_key]', $form['form_key'], $this->html );
382 +
383 + // Replace [form_name].
384 + $this->html = str_replace( '[form_name]', $form['name'], $this->html );
369 385 }
370 386
371 387 /**
372 388 * @since 3.0
@@ -507,9 +523,9 @@
507 523 private function add_field_div_classes() {
508 524 $classes = $this->get_field_div_classes();
509 525
510 526 if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && ! str_contains( $this->html, '[error_class]' ) ) {
511 - // there is no error_class shortcode for HTML fields
527 + // There is no error_class shortcode for HTML fields
512 528 $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . esc_attr( $classes ), $this->html );
513 529 return;
514 530 }
515 531
@@ -520,9 +536,9 @@
520 536 * Get the classes for a field div
521 537 *
522 538 * @since 3.0
523 539 *
524 - * @return string $classes
540 + * @return string Classes.
525 541 */
526 542 private function get_field_div_classes() {
527 543 // Add error class
528 544 $classes = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? ' frm_blank_field' : '';