PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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/helpers/FrmFormsHelper.php +109 -95 6.3.1 → 6.8 View file →
@@ -63,9 +63,9 @@
63 63
64 64 /**
65 65 * @param string $class
66 66 * @param string $param
67 - * @param array $add_html
67 + * @param array $add_html
68 68 *
69 69 * @since 2.0.6
70 70 */
71 71 public static function add_html_attr( $class, $param, &$add_html ) {
@@ -97,9 +97,10 @@
97 97 $args['form'] = 0;
98 98 } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) {
99 99 $args['frm_action'] = 'edit';
100 100 } elseif ( FrmAppHelper::is_style_editor_page() ) {
101 - unset( $args['id'] ); // Avoid passing style into form switcher on style page.
101 + // Avoid passing style into form switcher on style page.
102 + unset( $args['id'] );
102 103 $query_args = array(
103 104 'page' => 'formidable-styles',
104 105 );
105 106 if ( $frm_action ) {
@@ -190,9 +191,9 @@
190 191 </a>
191 192 </li>
192 193 <?php
193 194 unset( $form );
194 - }
195 + }//end foreach
195 196 ?>
196 197 </ul>
197 198 </div>
198 199 <?php
@@ -201,9 +202,9 @@
201 202 /**
202 203 * @since 3.05
203 204 * @deprecated 4.0
204 205 *
205 - * @param array $values - The form array
206 + * @param array $values The form array.
206 207 */
207 208 public static function builder_submit_button( $values ) {
208 209 FrmDeprecated::builder_submit_button( $values );
209 210 }
@@ -209,9 +210,9 @@
209 210 }
210 211
211 212 public static function get_sortable_classes( $col, $sort_col, $sort_dir ) {
212 213 echo ( $sort_col == $col ) ? 'sorted' : 'sortable';
213 - echo ( $sort_col == $col && $sort_dir == 'desc' ) ? ' asc' : ' desc';
214 + echo ( $sort_col == $col && $sort_dir === 'desc' ) ? ' asc' : ' desc';
214 215 }
215 216
216 217 /**
217 218 * @since 3.0
@@ -260,8 +261,10 @@
260 261 }
261 262
262 263 /**
263 264 * @param array $atts {
265 + * The success message details.
266 + *
264 267 * @type string $message
265 268 * @type stdClass $form
266 269 * @type int $entry_id
267 270 * @type string $class
@@ -284,9 +287,9 @@
284 287 if ( ! empty( $values ) ) {
285 288 $post_values = $values;
286 289 } else {
287 290 $values = array();
288 - $post_values = isset( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
291 + $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
289 292 }
290 293
291 294 $defaults = array(
292 295 'name' => '',
@@ -367,9 +370,9 @@
367 370 $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
368 371 }
369 372
370 373 unset( $var, $default );
371 - }
374 + }//end foreach
372 375
373 376 return $values;
374 377 }
375 378
@@ -418,20 +421,20 @@
418 421 /**
419 422 * @param string $loc
420 423 */
421 424 public static function get_default_html( $loc ) {
422 - if ( $loc == 'submit' ) {
425 + if ( $loc === 'submit' ) {
423 426 $draft_link = self::get_draft_link();
424 427 $start_over = self::get_start_over_shortcode();
425 428 $default_html = <<<SUBMIT_HTML
426 -<div class="frm_submit">
429 +<div class="frm_submit frm_flex">
430 +<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button>
427 431 [if back_button]<button type="submit" name="frm_prev_page" formnovalidate="formnovalidate" class="frm_prev_page" [back_hook]>[back_label]</button>[/if back_button]
428 -<button class="frm_button_submit" type="submit" [button_action]>[button_label]</button>
429 432 $draft_link
430 433 $start_over
431 434 </div>
432 435 SUBMIT_HTML;
433 - } elseif ( $loc == 'before' ) {
436 + } elseif ( $loc === 'before' ) {
434 437 $default_html = <<<BEFORE_HTML
435 438 <legend class="frm_screen_reader">[form_name]</legend>
436 439 [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name]
437 440 [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
@@ -669,8 +672,10 @@
669 672 * Automatically add end section fields if they don't exist (2.0 migration)
670 673 *
671 674 * @since 2.0
672 675 *
676 + * @param object $form
677 + * @param array $fields
673 678 * @param boolean $reset_fields
674 679 */
675 680 public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
676 681 if ( empty( $fields ) ) {
@@ -712,14 +717,14 @@
712 717 }
713 718
714 719 // There is already an end section here, so there is no need to create one.
715 720 $open = false;
716 - }
721 + }//end switch
717 722 $prev_order = $field->field_order;
718 723
719 724 $last_field = $field;
720 725 unset( $field );
721 - }
726 + }//end foreach
722 727
723 728 self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field );
724 729 }
725 730
@@ -756,9 +761,9 @@
756 761 if ( $code === 'form_name' ) {
757 762 $replace_with = $form->name;
758 763 } elseif ( $code === 'form_description' ) {
759 764 $replace_with = FrmAppHelper::use_wpautop( $form->description );
760 - } elseif ( $code === 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) {
765 + } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) {
761 766 $replace_with = FrmAppHelper::simple_get( 'entry' );
762 767 } else {
763 768 $replace_with = '';
764 769 }
@@ -765,12 +770,12 @@
765 770
766 771 FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
767 772 }
768 773
769 - //replace [form_key]
774 + // Replace [form_key].
770 775 $html = str_replace( '[form_key]', $form->form_key, $html );
771 776
772 - //replace [frmurl]
777 + // Replace [frmurl].
773 778 $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html );
774 779
775 780 if ( strpos( $html, '[button_label]' ) ) {
776 781 add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
@@ -879,9 +884,9 @@
879 884
880 885 /**
881 886 * Returns appropriate class if form has top labels
882 887 *
883 - * @param $form
888 + * @param array $form
884 889 *
885 890 * @return string
886 891 */
887 892 private static function maybe_align_fields_top( $form ) {
@@ -890,9 +895,9 @@
890 895
891 896 /**
892 897 * Determine if a form has fields with top labels so submit button can be aligned properly
893 898 *
894 - * @param $form
899 + * @param array $form
895 900 *
896 901 * @return bool
897 902 */
898 903 private static function form_has_top_labels( $form ) {
@@ -904,9 +909,10 @@
904 909 if ( count( $fields ) <= 0 ) {
905 910 return false;
906 911 }
907 912
908 - $fields = array_reverse( $fields ); // start from the fields closest to the submit button
913 + // Start from the fields closest to the submit button.
914 + $fields = array_reverse( $fields );
909 915 foreach ( $fields as $field ) {
910 916 $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
911 917 $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
912 918 if ( $has_input ) {
@@ -919,10 +925,10 @@
919 925
920 926 /**
921 927 * Check if a field's label position is set to "top"
922 928 *
923 - * @param $field
924 - * @param $form
929 + * @param array $field
930 + * @param object|string|bool $form
925 931 *
926 932 * @return bool
927 933 */
928 934 private static function field_has_top_label( $field, $form ) {
@@ -931,10 +937,9 @@
931 937 return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
932 938 }
933 939
934 940 /**
935 - * @param object|string|boolean $form
936 - *
941 + * @param object|array|string|boolean $form
937 942 * @return string
938 943 */
939 944 public static function get_form_style( $form ) {
940 945 $style = 1;
@@ -942,9 +947,9 @@
942 947 return $style;
943 948 } elseif ( is_object( $form ) && $form->parent_form_id ) {
944 949 // get the parent form if this is a child
945 950 $form = $form->parent_form_id;
946 - } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) {
951 + } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) {
947 952 $form = $form['parent_form_id'];
948 953 } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) {
949 954 $style = $form['custom_style'];
950 955 }
@@ -960,9 +965,9 @@
960 965
961 966 /**
962 967 * Display the validation error messages when an entry is submitted
963 968 *
964 - * @param array $args - includes img, errors
969 + * @param array $args Includes img, errors.
965 970 *
966 971 * @since 2.0.6
967 972 */
968 973 public static function show_errors( $args ) {
@@ -988,9 +993,9 @@
988 993 * Display the error message in the front-end along with the image if set
989 994 * The image was removed from the styling settings, but it may still be set with a hook
990 995 * If the message in the global settings is empty, show every validation message in the error box
991 996 *
992 - * @param array $args - includes img, errors, and show_img
997 + * @param array $args Includes img, errors, and show_img.
993 998 *
994 999 * @since 2.0.6
995 1000 */
996 1001 public static function show_error( $args ) {
@@ -1074,9 +1079,9 @@
1074 1079 );
1075 1080 }
1076 1081
1077 1082 $actions['trash'] = self::delete_trash_info( $form_id, $form->status );
1078 - }
1083 + }//end if
1079 1084
1080 1085 return $actions;
1081 1086 }
1082 1087
@@ -1100,9 +1105,9 @@
1100 1105 return FrmAppHelper::truncate( $name, 40 );
1101 1106 }
1102 1107
1103 1108 /**
1104 - * @param mixed data
1109 + * @param mixed $data
1105 1110 * @return int
1106 1111 */
1107 1112 private static function get_form_id_from_data( $data ) {
1108 1113 if ( is_object( $data ) ) {
@@ -1183,9 +1188,9 @@
1183 1188
1184 1189 /**
1185 1190 * @since 3.0
1186 1191 */
1187 - private static function delete_trash_links( $id ) {
1192 + public static function delete_trash_links( $id ) {
1188 1193 $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
1189 1194 $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
1190 1195
1191 1196 return array(
@@ -1301,26 +1306,31 @@
1301 1306 return $name;
1302 1307 }
1303 1308
1304 1309 /**
1305 - * @param array $categories
1310 + * Renders a template icon based on the given categories.
1311 + *
1312 + * @param array $categories The categories to render the icon for.
1306 1313 * @param array $atts {
1307 - * @type string $html 'span' or 'div'.
1308 - * @type boolean $bg Whether to add a bg color or not.
1314 + * Optional. An array of attributes for rendering.
1315 + * @type string $html 'span' or 'div'. Default 'span'.
1316 + * @type boolean $bg Whether to add a background color or not. Default false.
1309 1317 * }
1310 1318 *
1311 1319 * @return void
1312 1320 */
1313 1321 public static function template_icon( $categories, $atts = array() ) {
1322 + // Define defaults.
1314 1323 $defaults = array(
1315 - 'html' => 'span',
1316 - 'bg' => false,
1324 + 'bg' => true,
1317 1325 );
1318 1326 $atts = array_merge( $defaults, $atts );
1319 1327
1328 + // Filter out ignored categories.
1320 1329 $ignore = self::ignore_template_categories();
1321 1330 $categories = array_diff( $categories, $ignore );
1322 1331
1332 + // Define icons mapping.
1323 1333 $icons = array(
1324 1334 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1325 1335 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1326 1336 'User Registration' => array( 'register', 'var(--pink)' ),
@@ -1350,45 +1360,38 @@
1350 1360 'Signature' => array( 'signature' ),
1351 1361 '' => array( 'align_right' ),
1352 1362 );
1353 1363
1354 - $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' );
1355 -
1364 + // Determine the icon to be used.
1356 1365 $icon = $icons[''];
1357 -
1358 1366 if ( count( $categories ) === 1 ) {
1359 1367 $category = reset( $categories );
1360 1368 $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon;
1361 1369 } elseif ( ! empty( $categories ) ) {
1362 - foreach ( $icons as $cat => $icon ) {
1363 - if ( ! in_array( $cat, $categories ) ) {
1364 - unset( $icons[ $cat ] );
1365 - }
1366 - }
1370 + $icons = array_intersect_key( $icons, array_flip( $categories ) );
1367 1371 $icon = reset( $icons );
1368 1372 }
1369 1373
1370 - $bg = isset( $icon[1] ) ? $icon[1] : '';
1374 + // Prepare variables for output.
1375 + $icon_name = $icon[0];
1376 + $bg_color = isset( $icon[1] ) ? $icon[1] : '';
1371 1377
1372 - if ( $atts['html'] === 'div' ) {
1373 - echo '<div class="frm-category-icon frm-icon-wrapper" role="button"';
1374 - } else {
1375 - echo '<span class="frm-inner-circle"';
1378 + // Render the icon.
1379 + echo '<span class="frm-category-icon frm-icon-wrapper"';
1380 + if ( $bg_color && $atts['bg'] ) {
1381 + echo ' style="background-color:' . esc_attr( $bg_color ) . '"';
1376 1382 }
1377 - echo empty( $bg ) || empty( $atts['bg'] ) ? '' : ' style="background-color:' . esc_attr( $bg ) . '"';
1378 1383 echo '>';
1379 -
1380 - FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon[0] . '_icon' );
1381 - echo '<span class="frm_hidden">';
1382 - FrmAppHelper::icon_by_class( 'frmfont frm_lock_icon' );
1384 + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon_name . '_icon' );
1383 1385 echo '</span>';
1384 - echo '</' . esc_attr( $atts['html'] ) . '>';
1385 1386 }
1386 1387
1387 1388 /**
1389 + * Retrieves the list of template categories to ignore.
1390 + *
1388 1391 * @since 4.03.01
1389 1392 *
1390 - * @return array<string>
1393 + * @return string[] Array of categories to ignore.
1391 1394 */
1392 1395 public static function ignore_template_categories() {
1393 1396 return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' );
1394 1397 }
@@ -1393,9 +1396,15 @@
1393 1396 return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' );
1394 1397 }
1395 1398
1396 1399 /**
1400 + * Get template install link.
1401 + *
1397 1402 * @since 4.02
1403 + *
1404 + * @param array $template Template details.
1405 + * @param array $args Additional arguments.
1406 + * @return array The link attributes.
1398 1407 */
1399 1408 public static function get_template_install_link( $template, $args ) {
1400 1409 $defaults = array(
1401 1410 'class' => 'install-now',
@@ -1431,9 +1440,8 @@
1431 1440 *
1432 1441 * @since 4.02.02
1433 1442 *
1434 1443 * @param array $args
1435 - *
1436 1444 * @return bool
1437 1445 */
1438 1446 public static function plan_is_allowed( $args ) {
1439 1447 if ( empty( $args['license_type'] ) ) {
@@ -1439,20 +1447,22 @@
1439 1447 if ( empty( $args['license_type'] ) ) {
1440 1448 return false;
1441 1449 }
1442 1450
1443 - $included = $args['license_type'] === strtolower( $args['plan_required'] );
1451 + $plans = array( 'free', 'personal', 'business', 'elite' );
1452 + $license_type = strtolower( $args['license_type'] );
1453 + $plan_required = strtolower( $args['plan_required'] );
1454 + $included = $license_type === $plan_required;
1444 1455
1445 - $plans = array( 'free', 'personal', 'business', 'elite' );
1446 - if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) {
1456 + if ( $included || ! in_array( $plan_required, $plans, true ) ) {
1447 1457 return $included;
1448 1458 }
1449 1459
1450 1460 foreach ( $plans as $plan ) {
1451 - if ( $included || $plan === $args['license_type'] ) {
1461 + if ( $included || $plan === $license_type ) {
1452 1462 break;
1453 1463 }
1454 - $included = $plan === strtolower( $args['plan_required'] );
1464 + $included = $plan === $plan_required;
1455 1465 }
1456 1466
1457 1467 return $included;
1458 1468 }
@@ -1457,16 +1467,8 @@
1457 1467 return $included;
1458 1468 }
1459 1469
1460 1470 /**
1461 - * @since 4.02
1462 - */
1463 - public static function template_install_html( $link, $class = '' ) {
1464 - $link['class'] .= ' ' . $class;
1465 - echo '<a ' . esc_attr( $link['href'] ) . '="' . esc_url( $link['url'] ) . '" class="' . esc_attr( $link['class'] ) . ' " aria-label="' . esc_attr( $link['label'] ) . '"' . ( $link['atts'] ? ' target="_blank" rel="noopener"' : '' ) . '>';
1466 - }
1467 -
1468 - /**
1469 1471 * If a template or add-on cannot be installed, show a message
1470 1472 * about which plan is required.
1471 1473 *
1472 1474 * @since 4.0
@@ -1671,34 +1673,8 @@
1671 1673 );
1672 1674 }
1673 1675
1674 1676 /**
1675 - * Check an array of templates, determine how many the logged in user can use
1676 - *
1677 - * @param array $templates
1678 - * @param array $args
1679 - * @return int
1680 - */
1681 - public static function available_count( $templates, $args ) {
1682 - return array_reduce(
1683 - $templates,
1684 - function( $total, $template ) use ( $args ) {
1685 - if ( ! empty( $template['url'] ) ) {
1686 - return $total + 1;
1687 - }
1688 -
1689 - $args['plan_required'] = self::get_plan_required( $template );
1690 - if ( self::plan_is_allowed( $args ) ) {
1691 - return $total + 1;
1692 - }
1693 -
1694 - return $total;
1695 - },
1696 - 0
1697 - );
1698 - }
1699 -
1700 - /**
1701 1677 * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined.
1702 1678 * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL.
1703 1679 *
1704 1680 * @since 5.0.16
@@ -1747,9 +1723,9 @@
1747 1723 }
1748 1724 $new_shortcode .= ' sanitize_url=1]';
1749 1725
1750 1726 $query = str_replace( $shortcode, $new_shortcode, $query );
1751 - }
1727 + }//end foreach
1752 1728
1753 1729 if ( $query === $original_query ) {
1754 1730 return $url;
1755 1731 }
@@ -1766,6 +1742,44 @@
1766 1742 * @return bool
1767 1743 */
1768 1744 public static function should_use_pro_for_ajax_submit() {
1769 1745 return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' );
1746 + }
1747 +
1748 + /**
1749 + * Outputs the appropriate button text in the publish box.
1750 + *
1751 + * @return void
1752 + */
1753 + public static function publish_box_button_text() {
1754 + $is_new_template = FrmAppHelper::simple_get( 'new_template' );
1755 + $action = FrmAppHelper::simple_get( 'frm_action' );
1756 +
1757 + if ( ( 'edit' === $action || 'settings' === $action ) && $is_new_template ) {
1758 + esc_html_e( 'Save', 'formidable' );
1759 + } else {
1760 + esc_html_e( 'Update', 'formidable' );
1761 + }
1762 + }
1763 +
1764 + /**
1765 + * @since 4.02
1766 + * @deprecated 6.7
1767 + */
1768 + public static function template_install_html( $link, $class = '' ) {
1769 + _deprecated_function( __METHOD__, '6.7' );
1770 + }
1771 +
1772 + /**
1773 + * Check an array of templates, determine how many the logged in user can use
1774 + *
1775 + * @deprecated 6.7
1776 + *
1777 + * @param array $templates
1778 + * @param array $args
1779 + * @return int
1780 + */
1781 + public static function available_count( $templates, $args ) {
1782 + _deprecated_function( __METHOD__, '6.7' );
1783 + return 0;
1770 1784 }
1771 1785 }