| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Declare frontend actions/filters/shortcodes |
| 5 |
*/ |
| 6 |
|
| 7 |
// if ('dev' == $app->getEnv()) { |
| 8 |
// add_filter('init', function () use ($app) { |
| 9 |
// if ($header = $app->request->header('X-HOOK')) { |
| 10 |
// error_log($header); |
| 11 |
// } |
| 12 |
// }); |
| 13 |
// } |
| 14 |
|
| 15 |
/* |
| 16 |
* Exclude For WP Rocket Settings |
| 17 |
*/ |
| 18 |
if (defined('WP_ROCKET_VERSION')) { |
| 19 |
add_filter('rocket_excluded_inline_js_content', function ($lines) { |
| 20 |
$lines[] = 'fluent_form_ff_form_instance'; |
| 21 |
$lines[] = 'fluentFormVars'; |
| 22 |
$lines[] = 'fluentform_payment'; |
| 23 |
return $lines; |
| 24 |
}); |
| 25 |
} |
| 26 |
/* |
| 27 |
* Push captcha in all forms when enabled from global settings |
| 28 |
*/ |
| 29 |
add_filter('fluentform_rendering_form', function ($form) { |
| 30 |
$option = get_option('_fluentform_global_form_settings'); |
| 31 |
$enabled = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.autoload_captcha'); |
| 32 |
if (!$enabled) { |
| 33 |
return $form; |
| 34 |
} |
| 35 |
$type = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.captcha_type'); |
| 36 |
$reCaptcha = [ |
| 37 |
'element' => 'recaptcha', |
| 38 |
'attributes' => [ |
| 39 |
'name' => 'recaptcha', |
| 40 |
], |
| 41 |
]; |
| 42 |
$hCaptcha = [ |
| 43 |
'element' => 'hcaptcha', |
| 44 |
'attributes' => [ |
| 45 |
'name' => 'hcaptcha', |
| 46 |
], |
| 47 |
]; |
| 48 |
$turnstile = [ |
| 49 |
'element' => 'turnstile', |
| 50 |
'attributes' => [ |
| 51 |
'name' => 'turnstile', |
| 52 |
], |
| 53 |
]; |
| 54 |
|
| 55 |
if ('recaptcha' == $type) { |
| 56 |
$captcha = $reCaptcha; |
| 57 |
} elseif ('hcaptcha' == $type) { |
| 58 |
$captcha = $hCaptcha; |
| 59 |
} elseif ('turnstile' == $type) { |
| 60 |
$captcha = $turnstile; |
| 61 |
} |
| 62 |
|
| 63 |
// place recaptcha below custom submit button |
| 64 |
$hasCustomSubmit = false; |
| 65 |
foreach ($form->fields['fields'] as $index => $field) { |
| 66 |
if ('custom_submit_button' == $field['element']) { |
| 67 |
$hasCustomSubmit = true; |
| 68 |
array_splice($form->fields['fields'], $index, 0, [$captcha]); |
| 69 |
break; |
| 70 |
} |
| 71 |
} |
| 72 |
if (!$hasCustomSubmit) { |
| 73 |
$form->fields['fields'][] = $captcha; |
| 74 |
} |
| 75 |
|
| 76 |
return $form; |
| 77 |
}, 10, 1); |
| 78 |
|