| @@ -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 | } |
| @@ -226,9 +226,10 @@ | ||
| 226 | 226 | */ |
| 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 | - FrmShortcodeHelper::remove_inline_conditions( ( $description && $description != '' ), 'description', $description, $this->html ); | |
| 230 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 231 | + FrmShortcodeHelper::remove_inline_conditions( $description && $description != '', 'description', $description, $this->html ); | |
| 231 | 232 | } |
| 232 | 233 | |
| 233 | 234 | /** |
| 234 | 235 | * Add an ID to the description for aria-describedby. |
| @@ -240,8 +241,9 @@ | ||
| 240 | 241 | */ |
| 241 | 242 | private function maybe_add_description_id() { |
| 242 | 243 | $description = $this->field_obj->get_field_column( 'description' ); |
| 243 | 244 | |
| 245 | + // phpcs:ignore Universal.Operators.StrictComparisons | |
| 244 | 246 | if ( $description != '' ) { |
| 245 | 247 | $this->add_element_id( 'description', 'desc' ); |
| 246 | 248 | } |
| 247 | 249 | } |
| @@ -266,16 +268,20 @@ | ||
| 266 | 268 | if ( ! is_string( $inner_html[2] ) && count( $inner_html[2] ) === 1 ) { |
| 267 | 269 | $inner_html[2] = $inner_html[2][0]; |
| 268 | 270 | } |
| 269 | 271 | |
| 270 | - if ( is_string( $inner_html[2] ) ) { | |
| 271 | - $has_id = strpos( $inner_html[2], ' id=' ); | |
| 272 | + if ( ! is_string( $inner_html[2] ) ) { | |
| 273 | + return; | |
| 274 | + } | |
| 272 | 275 | |
| 273 | - if ( ! $has_id ) { | |
| 274 | - $id = 'frm_' . $id . '_' . $this->html_id; | |
| 275 | - $this->html = str_replace( 'class="frm_' . $param, 'id="' . esc_attr( $id ) . '" class="frm_' . esc_attr( $param ), $this->html ); | |
| 276 | - } | |
| 276 | + $has_id = str_contains( $inner_html[2], ' id=' ); | |
| 277 | + | |
| 278 | + if ( $has_id ) { | |
| 279 | + return; | |
| 277 | 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 ); | |
| 278 | 284 | } |
| 279 | 285 | |
| 280 | 286 | /** |
| 281 | 287 | * @since 3.0 |
| @@ -285,18 +291,28 @@ | ||
| 285 | 291 | private function replace_error_shortcode() { |
| 286 | 292 | $this->maybe_add_error_id(); |
| 287 | 293 | $error = $this->pass_args['errors'][ 'field' . $this->field_id ] ?? false; |
| 288 | 294 | |
| 289 | - if ( ! empty( $error ) && false === strpos( $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 ) { | |
| 290 | 304 | $error_body = self::get_error_body( $this->html ); |
| 291 | 305 | |
| 292 | - if ( is_string( $error_body ) && false === strpos( $error_body, 'role=' ) ) { | |
| 306 | + if ( is_string( $error_body ) && ! str_contains( $error_body, 'role=' ) ) { | |
| 293 | 307 | $new_error_body = preg_replace( '/class="frm_error/', 'role="alert" class="frm_error', $error_body, 1 ); |
| 294 | 308 | $this->html = str_replace( '[if error]' . $error_body . '[/if error]', '[if error]' . $new_error_body . '[/if error]', $this->html ); |
| 295 | 309 | } |
| 310 | + } elseif ( ! $include_alert_role_on_field_errors && $has_alert_role ) { | |
| 311 | + $this->html = str_replace( 'role="alert"', '', $this->html ); | |
| 296 | 312 | } |
| 297 | 313 | |
| 298 | - FrmShortcodeHelper::remove_inline_conditions( ! empty( $error ), 'error', $error, $this->html ); | |
| 314 | + FrmShortcodeHelper::remove_inline_conditions( true, 'error', $error, $this->html ); | |
| 299 | 315 | } |
| 300 | 316 | |
| 301 | 317 | /** |
| 302 | 318 | * Pull the HTML between [if error] and [/if error] shortcodes. |
| @@ -317,10 +333,9 @@ | ||
| 317 | 333 | if ( false === $end ) { |
| 318 | 334 | return false; |
| 319 | 335 | } |
| 320 | 336 | |
| 321 | - $error_body = substr( $html, $start + 10, $end - $start - 10 ); | |
| 322 | - return $error_body; | |
| 337 | + return substr( $html, $start + 10, $end - $start - 10 ); | |
| 323 | 338 | } |
| 324 | 339 | |
| 325 | 340 | /** |
| 326 | 341 | * Add an ID to the error message for aria-describedby. |
| @@ -355,17 +370,19 @@ | ||
| 355 | 370 | * |
| 356 | 371 | * @return void |
| 357 | 372 | */ |
| 358 | 373 | private function replace_form_shortcodes() { |
| 359 | - if ( ! empty( $this->form ) ) { | |
| 360 | - $form = (array) $this->form; | |
| 374 | + if ( ! $this->form ) { | |
| 375 | + return; | |
| 376 | + } | |
| 361 | 377 | |
| 362 | - // Replace [form_key]. | |
| 363 | - $this->html = str_replace( '[form_key]', $form['form_key'], $this->html ); | |
| 378 | + $form = (array) $this->form; | |
| 364 | 379 | |
| 365 | - // Replace [form_name]. | |
| 366 | - $this->html = str_replace( '[form_name]', $form['name'], $this->html ); | |
| 367 | - } | |
| 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 ); | |
| 368 | 385 | } |
| 369 | 386 | |
| 370 | 387 | /** |
| 371 | 388 | * @since 3.0 |
| @@ -375,9 +392,9 @@ | ||
| 375 | 392 | public function replace_shortcodes_after_input() { |
| 376 | 393 | $this->html .= "\n"; |
| 377 | 394 | |
| 378 | 395 | // Stop html filtering on confirmation field to prevent loop |
| 379 | - if ( $this->field_obj->get_field_column( 'conf_field' ) != 'stop' ) { | |
| 396 | + if ( $this->field_obj->get_field_column( 'conf_field' ) !== 'stop' ) { | |
| 380 | 397 | $this->filter_for_more_shortcodes(); |
| 381 | 398 | } |
| 382 | 399 | } |
| 383 | 400 | |
| @@ -408,9 +425,9 @@ | ||
| 408 | 425 | * |
| 409 | 426 | * @return void |
| 410 | 427 | */ |
| 411 | 428 | public function remove_collapse_shortcode( &$html ) { |
| 412 | - if ( strpos( $html, '[collapse_this]' ) ) { | |
| 429 | + if ( str_contains( $html, '[collapse_this]' ) ) { | |
| 413 | 430 | $html = str_replace( '[collapse_this]', '', $html ); |
| 414 | 431 | } |
| 415 | 432 | } |
| 416 | 433 | |
| @@ -424,11 +441,10 @@ | ||
| 424 | 441 | |
| 425 | 442 | foreach ( $shortcodes[0] as $short_key => $tag ) { |
| 426 | 443 | $shortcode_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] ); |
| 427 | 444 | $tag = FrmShortcodeHelper::get_shortcode_tag( $shortcodes, $short_key ); |
| 445 | + $replace_with = ''; | |
| 428 | 446 | |
| 429 | - $replace_with = ''; | |
| 430 | - | |
| 431 | 447 | if ( $tag === 'deletelink' && FrmAppHelper::pro_is_installed() ) { |
| 432 | 448 | $replace_with = FrmProEntriesController::entry_delete_link( $shortcode_atts ); |
| 433 | 449 | } elseif ( $tag === 'input' ) { |
| 434 | 450 | $replace_with = $this->replace_input_shortcode( $shortcode_atts ); |
| @@ -444,9 +460,8 @@ | ||
| 444 | 460 | * @return string |
| 445 | 461 | */ |
| 446 | 462 | private function replace_input_shortcode( $shortcode_atts ) { |
| 447 | 463 | $shortcode_atts = $this->prepare_input_shortcode_atts( $shortcode_atts ); |
| 448 | - | |
| 449 | 464 | return $this->field_obj->include_front_field_input( $this->pass_args, $shortcode_atts ); |
| 450 | 465 | } |
| 451 | 466 | |
| 452 | 467 | /** |
| @@ -507,10 +522,10 @@ | ||
| 507 | 522 | */ |
| 508 | 523 | private function add_field_div_classes() { |
| 509 | 524 | $classes = $this->get_field_div_classes(); |
| 510 | 525 | |
| 511 | - if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && strpos( $this->html, '[error_class]' ) === false ) { | |
| 512 | - // there is no error_class shortcode for HTML fields | |
| 526 | + if ( in_array( $this->field_obj->get_field_column( 'type' ), array( 'html', 'summary' ), true ) && ! str_contains( $this->html, '[error_class]' ) ) { | |
| 527 | + // There is no error_class shortcode for HTML fields | |
| 513 | 528 | $this->html = str_replace( 'class="frm_form_field', 'class="frm_form_field ' . esc_attr( $classes ), $this->html ); |
| 514 | 529 | return; |
| 515 | 530 | } |
| 516 | 531 | |
| @@ -521,9 +536,9 @@ | ||
| 521 | 536 | * Get the classes for a field div |
| 522 | 537 | * |
| 523 | 538 | * @since 3.0 |
| 524 | 539 | * |
| 525 | - * @return string $classes | |
| 540 | + * @return string Classes. | |
| 526 | 541 | */ |
| 527 | 542 | private function get_field_div_classes() { |
| 528 | 543 | // Add error class |
| 529 | 544 | $classes = isset( $this->pass_args['errors'][ 'field' . $this->field_id ] ) ? ' frm_blank_field' : ''; |
| @@ -530,9 +545,9 @@ | ||
| 530 | 545 | |
| 531 | 546 | // Add label position class |
| 532 | 547 | $settings = $this->field_obj->display_field_settings(); |
| 533 | 548 | |
| 534 | - if ( isset( $settings['label_position'] ) && $settings['label_position'] ) { | |
| 549 | + if ( ! empty( $settings['label_position'] ) ) { | |
| 535 | 550 | $label_position = $this->field_obj->get_field_column( 'label' ); |
| 536 | 551 | $classes .= ' frm_' . $label_position . '_container'; |
| 537 | 552 | |
| 538 | 553 | // Add class if field has value, to be used for floating label styling. |
| @@ -543,10 +558,10 @@ | ||
| 543 | 558 | |
| 544 | 559 | // Add CSS layout classes |
| 545 | 560 | $extra_classes = $this->field_obj->get_field_column( 'classes' ); |
| 546 | 561 | |
| 547 | - if ( ! empty( $extra_classes ) ) { | |
| 548 | - if ( ! strpos( $this->html, 'frm_form_field ' ) ) { | |
| 562 | + if ( $extra_classes ) { | |
| 563 | + if ( ! str_contains( $this->html, 'frm_form_field ' ) ) { | |
| 549 | 564 | $classes .= ' frm_form_field'; |
| 550 | 565 | } |
| 551 | 566 | |
| 552 | 567 | $classes .= ' ' . $extra_classes; |
| @@ -557,11 +572,9 @@ | ||
| 557 | 572 | // Get additional classes |
| 558 | 573 | $classes = apply_filters( 'frm_field_div_classes', $classes, $this->field_obj->get_field(), array( 'field_id' => $this->field_id ) ); |
| 559 | 574 | |
| 560 | 575 | // Remove unexpected characters from class. |
| 561 | - $classes = implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $classes ) ) ); | |
| 562 | - | |
| 563 | - return $classes; | |
| 576 | + return implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $classes ) ) ); | |
| 564 | 577 | } |
| 565 | 578 | |
| 566 | 579 | /** |
| 567 | 580 | * This filters shortcodes in the field HTML |