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