diff --git a/CHANGELOG.md b/CHANGELOG.md index 236ff77..3b9dc3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ * Navbar: Disable show on goingup on WooCommerce Checkout and when page content has a form (Gravity Forms or not) +* Gravity Forms: refactoring, and disable JS in footer since it is now default to true in the plugin ### 0.8.5: October 28th, 2021 * Images: align center even with webp images (picture, figure tags) diff --git a/inc/plugins/gravityforms.php b/inc/plugins/gravityforms.php index 238e24c..95f30b5 100644 --- a/inc/plugins/gravityforms.php +++ b/inc/plugins/gravityforms.php @@ -1,30 +1,22 @@ '; - $message .= '×'; - $message .= '' . $oldmessage . ''; - $message .= ''; - return $message; -} -add_filter('gform_validation_message', 'stormbringer_gform_validation_message', 10, 2); - -*/ -// This filter is used to enable the inclusion of the hidden choice in the Field Label Visibility and Sub-Label Placement settings on the field Appearance tab in the form editor. +// Gravity Forms: enable the inclusion of the hidden choice in the Field Label Visibility and Sub-Label Placement settings on the field Appearance tab in the form editor. add_filter( 'gform_enable_field_label_visibility_settings', '__return_true' ); - -// This filter can be used to dynamically add/remove CSS classes to a field -function stormbringer_gform_field_css_class($classes, $field, $form) +/** + * Gravity Forms: field css classes + * + * @param string $classes + * @param $field + * @param $form + * + * @return array|string|string[] + */ +function stormbringer_gform_field_css_class(string $classes, $field, $form) { $form_css = $form['cssClass'] ?? ''; @@ -35,7 +27,7 @@ function stormbringer_gform_field_css_class($classes, $field, $form) $classes = str_replace('icon-', 'dummy-', $classes); //$classes = str_replace('gfield', 'form-group gfield', $classes); - if ($field["type"] == 'textarea' || $field["type"] == 'text' || $field["type"] == 'email' || $field["type"] == 'name') { + if ($field['type'] == 'textarea' || $field['type'] == 'text' || $field['type'] == 'email' || $field['type'] == 'name') { if (strpos($form_css, 'form-placeholder') !== false) $classes .= " hide-label"; @@ -52,7 +44,7 @@ function stormbringer_gform_field_css_class($classes, $field, $form) add_action('gform_field_css_class', 'stormbringer_gform_field_css_class', 10, 3); /** - * Gravity Forms Submit Button + * Gravity Forms: submit Button * * @param $button * @param $form @@ -69,23 +61,40 @@ function stormbringer_gform_submit_button($button, $form) } add_filter('gform_submit_button', 'stormbringer_gform_submit_button', 10, 2); -function stormbringer_gform_next_button($button, $form) -{ +/** + * Gravity Forms: next button + * + * @param $button + * @param $form + * + * @return string + */ +function stormbringer_gform_next_button($button, $form): string { return '
'.str_replace('gform_next_button button','gform_next_button button btn btn-primary',$button).'
'; } add_filter('gform_next_button', 'stormbringer_gform_next_button', 10, 2); -function stormbringer_gform_previous_button($button, $form) -{ +/** + * Gravity Forms: previous button + * + * @param $button + * @param $form + * + * @return string + */ +function stormbringer_gform_previous_button($button, $form): string { return '
'.str_replace('gform_previous_button button','btn btn-link',$button).'
'; } add_filter('gform_previous_button', 'stormbringer_gform_previous_button', 10, 2); - - -//This filter is executed when the form is displayed and can be used to completely change -//the form tag (i.e.
). - +/** + * Gravity Forms: is executed when the form is displayed and can be used to completely change the form tag (i.e. ). + * + * @param $form_tag + * @param $form + * + * @return array|string|string[] + */ function stormbringer_gform_form_tag( $form_tag, $form ) { $form_css = $form['cssClass'] ?? ''; $class = "form "; @@ -104,13 +113,19 @@ function stormbringer_gform_form_tag( $form_tag, $form ) { return $form_tag; } -add_filter("gform_form_tag", "stormbringer_gform_form_tag", 10, 2); - - -//This filter is executed before creating the field's content, allowing users to completely -//modify the way the field is rendered. It can also be used to create custom field types. -//It is similar to gform_field_input, but provides more flexibility. +add_filter('gform_form_tag', 'stormbringer_gform_form_tag', 10, 2); +/** + * Gravity Forms: is executed before creating the field's content, allowing users to completely modify the way the field is rendered. It can also be used to create custom field types. It is similar to gform_field_input, but provides more flexibility. + * + * @param $content + * @param $field + * @param $value + * @param $lead_id + * @param $form_id + * + * @return array|string|string[]|null + */ function stormbringer_gform_field_content($content, $field, $value, $lead_id, $form_id) { global $form_css; @@ -136,138 +151,39 @@ function stormbringer_gform_field_content($content, $field, $value, $lead_id, $f $content = str_replace('type=\'password\'', 'type=\'password\' class="form-control"', $content); - // validation message - // if ($field["failed_validation"] == 1) { - // $content = str_replace('help-block help-inline', 'help-inline', $content); - //$content = preg_replace('/<\/div>(
.*?<\/div>)/', '
', $content); - //} else - //$content = preg_replace('/<\/div>(
.*?<\/div>)/', '\\1
', $content); - /* - $content = preg_replace('/<\/div>(
.*?<\/div>)/', '\\1
', $content); //1st time for description - $content = preg_replace('/<\/div>(
.*?<\/div>)/', '\\1
', $content); //2nd time for error - - // append button - $button = false; - if (strpos($field["cssClass"], 'buttontext-') !== false) { - $button_value = substr($field["cssClass"], strpos($field["cssClass"], 'buttontext-') + 11); - $button = true; - } - */ - // field-inline + // Different cases for each field types + $inline=''; - if (strpos($field["cssClass"], 'field-inline') !== false){ + if (strpos($field['cssClass'], 'field-inline') !== false){ $inline='-inline'; } - /* - // append/prepend icon - if ($field["type"] == 'text' || $field["type"] == 'email' || $field["type"] == 'name') { - - // placeholder - //if (GRAVITYFORMS_PLACEHOLDER == true) - //if ($form_css == 'placeholder') - if (strpos($form_css, 'form-placeholder') !== false){ - if($field["type"] == 'name'){ - foreach($field["inputs"] as $key=>$value){ - - $content = str_replace('name=\'input_'.$value['id'].'\'', 'name=\'input_'.$value['id'].'\' placeholder=\'' . $value['label'] . '\'', $content); - $content = str_replace('', ' placeholder=\'' . $field['label'] . '\'/>', $content); - } - } - // input-small for name - if($field["type"] == 'name'){ - foreach($field["inputs"] as $key=>$value){ - $content = str_replace('name=\'input_'.$value['id'].'\'', 'name="input_'.$value['id'].'" input class=\'input-mini input-name-'.($key+1).'\'', $content); - } - } - if (strpos($field["cssClass"], 'field-disabled') !== false) - $content = str_replace('/>', ' disabled=\'disabled\'/>', $content); - if (strpos($field["cssClass"], 'field-force') !== false) - $content = str_replace('/>', ' data-force=\'1\'/>', $content); - if (strpos($field["cssClass"], 'input-append') !== false) { - //$content = str_replace('controls','controls input-append',$content); - $field["cssClass"] = trim(str_replace('input-append', '', $field["cssClass"])); - $field["cssClass"] = trim(str_replace('input-mini', '', $field["cssClass"])); - $field["cssClass"] = trim(str_replace('input-max', '', $field["cssClass"])); - $field["cssClass"] = trim(str_replace('button-', 'btn-', $field["cssClass"])); - - if ($button == true) - $content = str_replace('/>', '/>', $content); - else - $content = str_replace('/>', '/>', $content); - $content = str_replace('', '/>', $content); - } - } - // field size : mini, max - if (strpos($field["cssClass"], 'input-mini') !== false) { - $content = str_replace('input-small', 'input-mini', $content); - $content = str_replace('input-medium', 'input-mini', $content); - $content = str_replace('input-large', 'input-mini', $content); - } - if (strpos($field["cssClass"], 'input-max') !== false) { - $content = str_replace('input-small', 'input-max', $content); - $content = str_replace('input-medium', 'input-max', $content); - $content = str_replace('input-large', 'input-max', $content); - } - - if ($field["type"] == 'textarea') { - // placeholder - if (strpos($form_css, 'form-placeholder') !== false) - $content = str_replace('(
.*?<\/div>)/', '\\1
', $content); - $content = preg_replace('/(.*?)<\/label>/', (!$inline ? '
' : '') . '' . (!$inline ? '
' : ''), $content); // insert input into label tag + $content = preg_replace('/(.*?)<\/label>/', (!$inline ? '
' : '') . '' . (!$inline ? '
' : ''), $content); // insert input into label tag //$content = preg_replace('/(.*?)<\/label>/', '\\2', $content); //removes only the label - if (strpos($field["cssClass"], 'field-disabled') !== false) + if (strpos($field['cssClass'], 'field-disabled') !== false) $content = str_replace('