| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* @since 6.8.4 |
| 8 |
*/ |
| 9 |
class FrmCaptchaFactory { |
| 10 |
|
| 11 |
/** |
| 12 |
* Get the proper FrmFieldCaptchaSettings child class based on a type setting. |
| 13 |
* |
| 14 |
* @since 6.8.4 |
| 15 |
* |
| 16 |
* @param string $captcha_type Either 'active', 'recaptcha', 'hcaptcha' or 'turnstile'. If active, the global setting will be used. |
| 17 |
* |
| 18 |
* @return FrmFieldCaptchaSettings |
| 19 |
*/ |
| 20 |
public static function get_settings_object( $captcha_type = 'active' ) { |
| 21 |
$frm_settings = FrmAppHelper::get_settings(); |
| 22 |
|
| 23 |
if ( 'active' === $captcha_type ) { |
| 24 |
$class = self::get_settings_class( $frm_settings->active_captcha ); |
| 25 |
} else { |
| 26 |
$class = self::get_settings_class( $captcha_type ); |
| 27 |
} |
| 28 |
|
| 29 |
return new $class( $frm_settings ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @since 6.8.4 |
| 34 |
* |
| 35 |
* @param string $active_captcha |
| 36 |
* |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
private static function get_settings_class( $active_captcha ) { |
| 40 |
$settings_classes = array( |
| 41 |
'recaptcha' => 'FrmRecaptchaSettings', |
| 42 |
'hcaptcha' => 'FrmHcaptchaSettings', |
| 43 |
'turnstile' => 'FrmTurnstileSettings', |
| 44 |
); |
| 45 |
|
| 46 |
if ( ! isset( $settings_classes[ $active_captcha ] ) ) { |
| 47 |
$active_captcha = 'recaptcha'; |
| 48 |
} |
| 49 |
|
| 50 |
return $settings_classes[ $active_captcha ]; |
| 51 |
} |
| 52 |
} |
| 53 |
|